changeset 1:3b5f5d1c5041

Initial revision
author arpi_esp
date Sat, 24 Feb 2001 20:28:24 +0000
parents c1bb2c071d63
children 9373c2abe9c3
files DOCS/AUTHORS DOCS/ChangeLog DOCS/ChangeLog.mpeg DOCS/INSTALL DOCS/LIRC DOCS/MPlayer-FAQ DOCS/MTRR DOCS/OpenDivX DOCS/README DOCS/SOUNDCARDS DOCS/SPEED DOCS/TODO DOCS/inttypes.h DOCS/mplayer.1 Makefile TOOLS/GL-test/compile.sh TOOLS/GL-test/gltest.c TOOLS/asfinfo.c TOOLS/c TOOLS/movinfo.c TVout/Mon-640x400 TVout/Mon-640x480 TVout/TV-640x512 TVout/TV-640x528 TVout/TV-704x528 TVout/TV-704x576 TVout/TV-720x576 TVout/clean.sh TVout/cloning TVout/compile.sh TVout/con2fb/con2fb.c TVout/fbset.db TVout/fbset/INSTALL TVout/fbset/Makefile TVout/fbset/fb.h TVout/fbset/fb.modes.5 TVout/fbset/fbset.8 TVout/fbset/fbset.c TVout/fbset/fbset.h TVout/fbset/modeline2fb TVout/fbset/modes.l TVout/fbset/modes.y TVout/independ TVout/matroxset/Makefile TVout/matroxset/fb.h TVout/matroxset/matroxfb.h TVout/matroxset/matroxset.c TVout/matroxset/normal TVout/matroxset/swapit TVout/matroxset/swapped TVout/modules alaw.c asfheader.c aviheader.c aviparse.c aviprint.c aviwrite.c codecctrl.c codecs.c config.h config.mak configure demux_asf.c demux_avi.c demux_mpg.c demuxer.c dll_init.c drivers/3dfx.h drivers/Makefile drivers/README drivers/mga_vid.c drivers/mga_vid.h drivers/mga_vid_test.c drivers/sis_vid.c drivers/sis_vid.h help_avp.h help_mp.h liba52/srfftp.h libmpeg2/Makefile libmpeg2/attributes.h libmpeg2/decode.c libmpeg2/header.c libmpeg2/idct.c libmpeg2/idct_mlib.c libmpeg2/idct_mmx.c libmpeg2/mm_accel.h libmpeg2/mmx.h libmpeg2/motion_comp.c libmpeg2/motion_comp_mlib.c libmpeg2/motion_comp_mmx.c libmpeg2/mpeg2.h libmpeg2/mpeg2_internal.h libmpeg2/slice.c libmpeg2/sse.h libmpeg2/stats.c libmpeg2/vlc.h libvo/Attic/SHIT/video_out_gl.c.V3-sux libvo/Attic/SHIT/video_out_gl.c.diff libvo/Attic/SHIT/video_out_odivx.c.OLD libvo/Attic/SHIT/video_out_sdl.c-1.1.4 libvo/Attic/SHIT/video_out_x11.c.OLD libvo/Attic/SHIT/video_out_x11.c.thread libvo/Makefile libvo/config.mak libvo/mga_common.c libvo/mmx.h libvo/rgb15to16mmx.c libvo/video_out.c libvo/video_out.h libvo/video_out_internal.h libvo/vo_3dfx.c libvo/vo_gl.c libvo/vo_md5.c libvo/vo_mga.c libvo/vo_null.c libvo/vo_odivx.c libvo/vo_pgm.c libvo/vo_sdl.c libvo/vo_syncfb.c libvo/vo_syncfb.c.OLD libvo/vo_x11.c libvo/vo_xmga.c libvo/vo_xv.c libvo/wskeys.h libvo/yuv2rgb.c libvo/yuv2rgb.h libvo/yuv2rgb_mlib.c libvo/yuv2rgb_mmx.c linux/getch2.c linux/getch2.h linux/keycodes.h linux/shmem.c linux/shmem.h linux/timer-lx.c linux/timer.h lirc_mp.c lirc_mp.h loader/Makefile loader/afl.c loader/com.h loader/config.h loader/driver.c loader/elfdll.c loader/ext.c loader/loader.h loader/module.c loader/pe_image.c loader/pe_resource.c loader/registry.c loader/registry.h loader/resource.c loader/stubs.s loader/vfl.c loader/win32.c loader/win32.h loader/wine/avifmt.h loader/wine/basetsd.h loader/wine/config.h loader/wine/debugtools.h loader/wine/driver.h loader/wine/elfdll.h loader/wine/heap.h loader/wine/ldt.h loader/wine/mmreg.h loader/wine/module.h loader/wine/msacm.h loader/wine/msacmdrv.h loader/wine/ntdef.h loader/wine/pe_image.h loader/wine/poppack.h loader/wine/pshpack1.h loader/wine/pshpack2.h loader/wine/pshpack4.h loader/wine/pshpack8.h loader/wine/vfw.h loader/wine/winbase.h loader/wine/windef.h loader/wine/windows.h loader/wine/winerror.h loader/wine/winestring.h loader/wine/winnt.h loader/wine/winreg.h loader/wine/winuser.h loader/wineacm.h mp3lib/Makefile mp3lib/config.mak mp3lib/d_cpu.h mp3lib/d_cpu.s mp3lib/dct12.c mp3lib/dct36.c mp3lib/dct36_3dnow.s mp3lib/dct64.c mp3lib/dct64_3dnow.s mp3lib/dct64_i386.c mp3lib/decod386.c mp3lib/decode_3dnow.s mp3lib/decode_i586.s mp3lib/equalizer.c mp3lib/huffman.h mp3lib/l2tables.h mp3lib/layer2.c mp3lib/layer3.c mp3lib/mp3.h mp3lib/mpg123.h mp3lib/sr1.c mp3lib/tabinit.c mplayer.c parse_es.c stream.c tvision.c vcd_read.h version.h videodev.h xa/xa_gsm.c xa/xa_gsm.h xa/xa_gsm_int.h
diffstat 216 files changed, 58871 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DOCS/AUTHORS	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,78 @@
+                            AUTHORS:
+                            ~~~~~~~~
+
+====================== The MPlayer project: ===========================
+
+Arpád Gereöffy (A'rpi/ESP-team):  <arpi@thot.banki.hu>
+- player code (mpeg stream demultiplexer and avi/asf parser, A-V sync, seek...)
+- mp3lib, based on mpg123 sources  [MP3 audio decoder]
+- getch2  [keyboard handler]
+- some changes in libmpeg2 code (progressive frames, bitrate & fps support)
+- libvo improvements: adding OpenGL support, bugfix in mga driver...
+- YUY2 support into mga_vid driver (for DivX/MPEG4)
+- YUY2, RGB/BGR 15/16/24/32 support into libvo drivers (for AVI codecs)
+- scripts in the TVout directory (allows using TVout on Matrox G400 DH on fb)
+- hacking DivX/Mpeg4 VfW codecs to get YUV output
+- opendivx decoder speed optimizations (see opendivx/ChangeLog)
+
+Zoltán Ponekker (Pontscho/Fresh!):  <pontscho@makacs.poliod.hu> 
+- configure script and Makefiles for easy compile
+- GUI system (coming soon!)
+- 3DNow! support into mp3lib
+- various X11 driver changes (keyboard handling, fullscreen, bpp detect, etc)
+- libvo: adding xmga driver (similar to Xv but works under X3.3.x)
+
+Gábor Lénárt (LGB): <lgb@supervisor.hu>
+- testing and some improvements in mpeg player's user interface (options)
+- ./configure script improvements
+
+Gabucino:  <gabucino@k2.jozsef.kando.hu>
+- web design, docs improvements/updating
+- testing, (Open)DivX encoding, picture quality comparsions
+
+Dariusz Pietrzak: <dariush@ajax.umcs.lublin.pl>
+- mailing lists hosting (see README for details)
+
+Main testers:
+  Gabucino
+  Balazs Tibor (Tibcu)
+  Sasi Peter (SaPe)
+  Christoph H. Lampert
+
+========================== The Codecs: ===================================
+
+Aaron Holtzman:  <aholtzma@engr.uvic.ca>
+- ac3dec (and libac3) author  [AC3 audio decoder]
+- mga_vid driver  [Matrox G200/G400 YUV Back-end Scaler]
+- mpeg2dec        [Fast MPEG1/MPEG2 video decoder, currently used in player]
+
+Michel Lespinasse:  <walken@zoy.org>
+- did large libmpeg2 changes for better speed and mpeg conformance
+
+Eugene Kuznetsov:  <divx@euro.ru>
+- avifile author  [AVI player library for linux, using Win32 VfW/ACM codecs]
+- technical help about AVI and ASF formats, and how to get YUV using VfW...
+
+Project Mayo:  [http://www.projectmayo.com]
+- the OpenDivX codec authors
+
+Michael Hipp:
+- mpg123 author   [free mpeg audio player, isn't used directly but in mp3lib]
+
+Mark Podlipec:
+- xanim author    [i'm using its aLaw audio decoder]
+
+Jutta Degener and Carsten Bormann:
+- xa_gsm.c authors  [MS-GSM audio codec]
+
+Their code is not used in current player version, but I've got some ideas or
+other technical help from:
+
+John F. McGowan   http://www.jmcgowan.com/
+- AVI FAQ author/collector. [site with many useful docs on codecs and avi fmt]
+
+Dirk Farin:      <farin@ti.uni-mannheim.de>
+- dvdview author  [MPEG1/MPEG2 video decoder, used in v0.5-v0.8]
+
+Adam Williams:   <broadcast@earthling.net>
+- libmpeg3 (and xmovie) author  [MPEG1/MPEG2 video decoder, used in v0.1-v0.4]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DOCS/ChangeLog	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,479 @@
+ChangeLog:
+~~~~~~~~~~
+
+v0.12-pre1:  [ not yet released ]
+  - ffmpeg included into source tree
+
+===========================================================================
+Note: If you've sent patches not applied in pre22, please send them again!
+/|\   (I've got tons of mails last weeks, and can't re-read all of them)
+/~\   Please include in the Subject: MPLAYER-PATCH
+===========================================================================
+
+*** 0.11 release is coming SOON!!! ***
+
+v0.11-pre25:  small fixes again :(
+  - DOCS updated (email address changed from arpi@* -> maillist)
+  - LIRC fix, mplayer_lirc changed back to mplayer [Andreas Ackermann]
+  - stream.c: unsigned int fixes, required for some strange .asf files
+  - asfheader.c: using w=h=b=1 for audio_concealment_none
+  - VCD-related stuff moved from stream.c to vcd_read.c
+
+v0.11-pre24:  small fixes again :(
+  - DOCS/LIRC changed: users *must* enable lirc support manually, it is
+    not autodetected yet.  (./configure --enable-lirc)
+  - the {prefix} bug fixed by Gabucino
+  - added manpage by Gabucino
+  - manpage -vo fixes by A'rpi
+
+v0.11-pre23:  lirc support, text updates, mailinglists
+  - added "-ni" option to force usage of the non-interleaved AVI parser
+  - DOCS/* updated by Gabucino
+  - new homepage by Gabucino
+  - mplayer users & announce mailing lists by Dariusz Pietrzak (see README)
+  - LIRC support by Andreas Ackermann (see DOCS/LIRC)
+    enable with ./configure --enable-lirc
+    TODO: ./configure should detect LIRC installed and better Makefile handling
+  - added AVI_NINI parser for broken (no index) non-interleaved files
+
+v0.11-pre22:  last fixes, release is coming soon!
+  - non-interleaved avi EOF bug fixed  [thanks to DC-1 for help]
+  - "You" strings in Makefile after make dep bug fixed...  [thx to DC-1]
+  - SDL disabled by default. You have to ./configure --enable-sdl to enable.
+  - homepage updated by Gabucino
+  - homepage updated by A'rpi
+  - FAQ updated by A'rpi
+
+fork()  -> 0.12pre1
+
+v0.11-pre21:  mpeg1 pp, stereo fix
+  - "Skip chunk xxxx" messages moved from -v to -v -v -v debug level...
+    [thanks to Christoph H. Lampert]
+  - divx postprocess filter works for mpeg1 files too! (-divxq 1/3/7/31)
+  - mpeg layer-2 audio fixed - it's stereo again!!!
+  - audio select() detection: if detected audio buffer size == 0, then
+    exit with message "recompile mplayer with #undef HAVE_AUDIO_SELECT"...
+  - syncfb driver added to the source tree, under drivers/
+    (it's very similar to mga_vid, but has syncronization to screen and
+     de-interlace features)
+  - draw_slice in syncfb finished for G400 cards (plays mpeg 1/2, opendivx)
+    (de-interlacing has been disabled, because it's buggy now)
+
+v0.11-pre20:  NI-AVI support, small fixes & patches...
+  - asf parser: flag 0x40 (explicit packet size) implemented [Marvin]
+  - new option to select DSP device:  -dsp   (default: /dev/dsp) [Pontscho]
+  - option -o changed to -vo
+  - ./configure: applied patches  [LGB,Ian Kumlien,Magnus Pfeffer]
+  - avi chunk_id->ds mapper moved to demux_avi_select_stream()
+  - added non-interleaved .AVI parser
+  - added non-interleaved .AVI detection (if a_pos-v_pos distance > 1MB)
+
+v0.11-pre19:  small fixes...
+  - vo_xmga.c: G200 draw_slice fixed
+    xmga + mga: common part (draw_frame & draw_slice) moved to mga_common.c
+  - some independent code (asfinfo.c and GL-test) moved to the new TOOLS subdir
+  - movinfo.c added to TOOLS (small util to dump .mov file structure)
+  - AVI & ASF stream id detection changed: now using IDs from the header
+    (but still can be overriden by -aid or -vid)     [Christoph H. Lampert]
+  - native MS-GSM audio codec ported from avifile source  (-afm 6)
+    [thanks for the testfile to Christoph H. Lampert]
+  - README updated (input & codec lists)
+  - implemented .asf audio descrambling  [Dirk Vornheder & Einon]
+    -> that weird_al_yankovic asf is not so weird now :)
+  - AUTHORS file changed
+
+v0.11-pre18:  patch release :)
+  - skip broken .asf fragments (for better seeking)
+  - seeking code cleanup in sources (now it's in a switch(){})
+  - opendivx encoding bitrate option changed from -divxq to -br
+    (for the divx -> divx re-encoding)
+  - TO DO section moved to file TODO
+  - applied ./configure and Makefile changes patch from LGB
+  - libvo function changes by Pontscho: x11 (with -fs), xmga (bugfixed!)
+  - libvo: driver sources renamed from video_out_*.c -> vo_*.c
+  - libvo: added uninit() function to drivers
+  - libvo: fork()'ed X11 eventhandler for x11 and xmga drivers  [me & Pontscho]
+     (gl and xv version is coming soon!)
+  - libvo: sdl driver now closes SDL at QUIT...
+  - small english fixes (docs & messages)   [Balazs Tibor]
+
+v0.11-pre17:  fixes
+  - asf "missing video stream" fixed (stream id & 0x7F)  [Christoph H. Lampert]
+  - added GL-test directory, it contains source and compiler script of a
+    very simple open-gl texture updating (glTexSubImage) test program.
+    if it runs well, then mplayer -o gl should work too.
+    it works on G400+Utah-GLX, but segfaults in the G400 driver of X 4.0.2/DRI.
+    try it with different cards/drivers, and please report me the results.
+  - benchmarking in gltest.c: calculate fps and process times
+  - .asf seeking v0.01-pre0.1 :)
+
+v0.11-pre16:  ACM fixed
+  - Win32/ACM audio codec fixed (most important for asf with divx audio):
+    There was an output buffer size problem with the Win32/ACM audio codec
+    at low bitrates (usually used for .asf files with divx audio)
+    Input and output buffer sizes are now queryed, problem solved :)
+  - SDL support compiling hint by Michael Durller added to the FAQ
+  - opendivx support in .asf files   [Gérard Lantau]
+  - ./configure & Makefiles patch by Aaron Hope applied.
+    (adds --with-win32libdir and fixes --with-x11libdir)
+  - ./configure fixed, now it defaults to /usr/lib/win32 if detection failed
+
+v0.11-pre15:  asf sync fixed
+  - asf parser: now supports other than 0x5D segments  [Dirk Vornheder]
+  - new asf PTS reading: sync works now, including fps...
+    (-fps no longer required!)  [thanks again to Eugene Kuznetsov for docs!]
+
+v0.11-pre14:  small fixes, asf sync v0.1 :)
+  - version number incremented :)))
+  - libvo / Xv driver swapped Red-Blue fixed
+  - asf timestamps implemented - now asf A-V should be in sync if you
+    specify the correct fps at commandline (-fps), +-1 fps allowed...
+    [i haven't yet found method to get fps out from asf headers :(((]
+  - some error and consistency checking into demux_asf
+    if you see many warning! messages playing an .asf file, then contact
+    me and upload the file (first 1MB is enough if it represents the problem)
+    Don't forget: there is no public doc about the .asf file format, so 
+    everything we know is suspected and can be wrong... without your help
+    we never will have working .asf player...
+  - asf fragment offset checks disabled for grouping...
+
+v0.11-pre13:  libvo changes, mpeg bitrate, vcd fix, asf grouping
+  - libvo: draw_slice() interface changed, now it has src stride[3] and
+    destination rect dimension (w,h,x,y)
+    It's able to blit whole frames, not only 16-pixel slices...
+  - libmpeg2 and opendivx codec changed to use new draw_slice()
+    -> opendivx extra 64-pixel width band at right disappeared!
+  - mpeg bitrate fix: if picture->bitrate==0x3FFFF (means "unspecified" ?)
+    then using standard VCD bitrate (75*2324 bytes/sec)
+    -> fixed seeking for those mpegs with "16MBit/s" bitrate...
+  - drivers/sis_vid: video4linux interface disabled
+  - broken VCD playing fixed: stream_reset shouldn't seek to 0x0...
+    [bugreport: Kang Sun]
+  - asf_parser: grouping implemented!  [test file provided by Gabucino :))]
+
+v0.11-pre12:  ./configure fixes, improved odivx-encoding, streaming fixes
+  - ./configure: using /tmp/main$$.c instead /tmp.main.c, and
+    remove file after tests  [SaPe]
+  - ./configure: trying the gcc optimize options and fallback to 'pentium'
+    if fails (useful for people with old gcc and new cpu :))
+  - removed -fomit-frame-pointer from OPTFLAGS at config.mak
+  - version number incremented [Gabucino]
+  - odivx encoder fix: allow long (longer than xxxx.avi) destination filenames
+    (sizeof() changed to strlen()...)  [Gabucino]
+  - avi writer - overwrite disabled (exits with error message if destination
+    file already exists...)  [Gabucino]
+  - use -divxq to set encoding bitrate (in bits (no kbits!) default: 780000)
+  - no audio decoding if -encode option is used
+  - audio streaming disabled if -nosound specified (setting audio_id to -2)
+  - fast Mpeg-ES detection (doesn't read the whole Mpeg-PS file)
+  - compile-time option to disable using soundcard driver's select()
+    (requires for some people with buggy/pre-alpha/etc sound driver...)
+
+v0.11-pre11:  streaming fixes, asf support pre, indeo5 fix
+  - asf/asfinfo.c improved: now it dumps streams to files - need testing!
+    (it's ready to be converted to asf demuxer and intergated into MPlayer)
+  - stream.c / stream_reset() fix: now it really seek back to 0 position!
+  - .asf file format detection added (no .asf reading yet!!!)
+  - .asf demultiplexer added, changes in demuxer.c to handle fragmented packets
+  > it plays .asf video well, but still has problems with divx/wma audio. :(((
+  - indeo 5 playing fixed (removed ICDECOMPRESS_UPDATE from flags)
+  - xmga resizing problems with some window managers, so default order is
+    changed xmga,xma... to mga,xmga,...
+  - found gcc bug: compiling MPlayer with flags 
+    OPTFLAGS=-O -g -march=i686 -mcpu=i686 -pipe -fomit-frame-pointer -ffast-math
+    cause image sizes negating -> mga_vid kernel driver Oops... :(((
+  - runaway.bride.sample.avi seeking segfault discovered: AC3 resync fails :(
+  - improved signal handling: module name is now printed. audio_resync added.
+  - RGB opendivx encoding implemented, now AVI->opendivx is possible.
+
+v0.11-pre10:  OpenDivX encoding, streaming fixes, avi seek fixes
+  - new libvo driver: odivx  (OpenDivX File Writer)
+  - AVI file writting support, new option:  -encode filename
+    to encode an mpeg/vob/vcd to opendivx:
+      mplayer file1.mpg -encode file2.avi -o odivx -nosound
+    (sound encoding/copy is not yet supported)
+  - libvo: default driver priority changed to: xmga,mga,syncfb,3dfx,xv,x11,gl
+  - avi writer: index support
+  - small fixes in avi writer to be compliant (adjusted chunk/list lengths)
+  - demuxer.c: stream buffering fixes:
+    - missing {} in mplayer.c occuring audio reads when has_audio=0
+    - reordered packet reader and pack count checks -> no more unwanted EOF
+    - added 4MB buffer memory usage limit to demuxed streams
+  - CPU flags in ./configure changed:
+      k7 -> k6  (current stable gcc doesn't supports k7)
+      386,486 -> i386,i486    [Balazs Tibor]
+  - demux_avi: index check now accepts (raw.len+1)==idx.len  [Balazs Tibor]
+  - FAQ added
+
+    **  Now we are ready with planned features & urgent fixes, **
+    **  it's time to final testing and then the 0.11 release!! **
+
+v0.11-pre9:  OpenDivX fixes,speedup
+  - solved OpenDivX width problem (stride=width+(Quality?0:64))
+    now -divxq 0 works, and 0 is the default
+  - libvo call moved out from my_convert_yuv() so it can be measured (cpu %)
+  - IDCT code ported from libmpeg2 -> much faster OpenDivX decoding
+
+v0.11-pre8:  SDL fixes, OpenDivX support
+  - added -I/usr/X11R6/include to libvo CFLAGS
+  - (removed later: applied libvo SDL driver fixes by Jeffrey Boser)
+  - OpenDivX support, initial hack, maybe not work for you...
+    (I need testfiles, I have just only one)
+    use -divxq option to adjust quality (1..29 works), 1=default
+
+v0.11-pre7:  SDL support
+  - ported SDL driver from mpeg2dec/libvo (currect CVS)
+    (it's slower than internal X11 driver, but supports software scaling!)
+  - fixed SDL driver to support -fs and pass keyboard events
+  - SDL driver changed to support YV12 and YUY2 formats instead of IYUV
+    (now works with DivX files too)
+  - 'q' (Quit) disabled in SDL fullscreen mode (because it's impossible
+    to restore screen before exiting so it gets unusable state now)
+
+v0.11-pre6:  audio fix
+  - fixed video_out_xv.c compiling problems [bugreport: Kalle Mellerup]
+  - modified audio playing: always keep buffer (both internal and card's)
+    filled using select() -> -alsa audio delays should be fixed.
+  - updated DOCS/AUTHORS and DOCS/README
+
+v0.11-pre5:  xmmp audio support, applied Pontscho's libvo patch
+  - xmmp audio driver support by Arthur Kleer
+  - new video_out driver by Pontscho: xmga  (Matrox G200/G400 only!)
+    It does same under X 3.3.x what Xv extension does under X 4.0.x!
+    (you will have a moveable/resizeable window but see an YUV video
+     overlay in it using color keying)
+  - added keyboard event support in X11 windows    [Pontscho]
+    (using mplayer_[put|get]_key() in codecctrl.c)
+
+v0.11-pre4:  x11 driver fixes, 15/16bpp support
+  - version in version.h fixed :))) [Pontscho]
+  - inttypes.h moved to DOCS/ (copy back to the root if you need it)
+  - depth calculation in vo_init() changed (Pontscho's version couldn't
+    make difference between 15 and 16bpp)
+  - x11 driver now uses vo_init() instead of get_depth()
+  - yuv2mmx: 15bpp not really supported -> removed from list, now
+    conversion is done (well) by the C code -> MPEG play in 15bpp works!
+  - avi playing support added in 15bpp (memcpy)
+  - avi playing support added in 16bpp (C 15->16 converter by me)
+  - avi playing support added in 16bpp (MMX 15->16 converter by Strepto)
+  - libvo/x11: yuv2rgb used MMX code on non-MMX CPUs too!!! fixed...
+  - all x11 modes tested (and mpeg/24bpp byteorder fixed):
+                  MPEG:            AVI/VfW:
+        15bpp    C convert        memcpy
+        16bpp    MMX/C convert    MMX/C convert
+        24bpp    C convert        memcpy
+        32bpp    MMX/C convert    memcpy / C conv.
+    => now all the movie types are viewable using the -o x11 driver!
+
+v0.11-pre3:  mpeg fixes, fullscreen support
+  - vertical.mpg serious libvo (x11,gl) segfaults fixed:
+    yuv2rgb_mmx requires one more lines that vertical image size...
+    fixed (allocating memory for width*(height+1)).   [bugreport: Gabucino]
+  - Pontscho's fullscreen patch applied!
+    Using option -fs will maximize window size (for all resizeable drivers
+    including mga!) and disable window decorations (x11,Xv,gl only)
+  - simple inttypes.h included for libc5 (and glibc2.0 too?) users
+  - homepage updates (links changed ftp->http)
+
+v0.11-pre2:  better user messages, mp3 codec selection, demuxer changes
+  - w32codec.zip restored at the FTP site (somehow it damaged...)
+  - added version.h, and used its content everywhere
+  - 'premature end-of-file' problem fixed: freeing audio buffers and
+    setting d_audio->id=-2 if has_audio==0  [bugreport by Dmitri Pogosyan]
+  - some more messages added if verbose>=1
+  - demuxer.c: error message printed if A or V chunk buffer is full
+    'mplayer test.avi -aid -2' still not works without option '-nosound'
+  - adding new config.h option to set default MP3 audio codec (mpg123/l3codeca)
+    ./configure selects mp3lib only if you have 3Dnow    [idea: Gabucino]
+  - automatic fallback to mp3lib/mpg123 if l3codeca.acm can't be loaded/inited
+
+v0.11-pre1:  AVI sync fixes
+  - AVI audio seeking improvements: now using nBlockAlign value to seek
+    inside the chunk, so divx audio works without big delays!!!
+  - AVI PTS calculation modified: counting video PTS when skip_video_frames>0
+    so new audio PTS values will be correct. Solved many sync probs!
+  - A-V sync with AVI files fixed!
+    Now only the Desperado-trailer has 1.0 sec delay after seeking.
+  - fixed AVI sync in -bps mode too! :)  (perfect except that Desperado avi)
+
+v0.10:  The new year release!
+  - testing
+  - docs changed
+  - it's time to release and remove the old buggy 0.09 version...
+  - release!!!
+  
+v0.10-pre8:  libvo/x11 changes
+  - libvo: x11/xv driver separated to x11 and xv drivers
+  - libvo: DUMMY_VO_FUNC removed from driver sources
+  - libvo: default driver order changed, because some users with software-only
+           opengl though that this 'slow' player can only play at 1-3fps :)
+
+v0.10-pre7:  libmpeg2 interface changes, display size/area changes, AVI fixes
+  - libmpeg2/decode.c modified:
+    - removed unused OMS and mpeg2dec stuff
+    - decode_data rewritten, now works like parse_es.c
+      => doesn't copy any data -> faster and less memory usage
+  - mplayer.c sends code 0x1FF after every frame, so libmpeg2 knows
+    when has to display it
+  - mplayer.c: in_frame flag fixes, didn't work well with mpeg2 streams
+    (because there is a 0x1B2 chunk between 0x100 and 0x101)
+  - 'picture' changed from static to shmem-allocated
+    -> better picture after codec restart (tested with JapAd.mpg)
+    -> keep information of the header changes (after init)
+  - mpeg image size changed, now only the real part of frame is displayed
+    (no more green strip at the bottom)
+    - picture struct: new fields: display_picture_width/height
+    - image buffer allocation (shmem) is done by decode.c instead of libvo
+  - new option:  -xy <value>  (resize both x/y direction)
+    if value<=8  ->  x_scale = y_scale = value
+    else         ->  x_size=value  y_size=aspectratio*x_size
+  - mplayer.c: video output moved out from avi/mpg init sections and
+    now it's common code (added movie_size_x/y variables and out_fmt global)
+  - new keys:
+    ESC       => quit
+    + and -   => adjust audio delay +- 0.1 second
+    k         => kill/restart the mpeg codec process (for testing)
+  - codec control interface changed: wait for syncword after (re)start
+    to avoid receiving old frames => it's stable again!
+  - removed (now unused) allocate/free image buffer code from libvo
+  - mplayer: new internal variable for video format: has_video
+       0 = none (unused yet)
+       1 = mpeg 1/2 video
+       2 = win32/VfW video codec
+  - config.h has defaults for bps-based AVI sync and ALSA timer code options:
+     #undef AVI_SYNC_BPS  => now it's disabled by default!!! use -bps to enable
+     #define ALSA_TIMER   => now it's enabled by default!!! use -noalsa to dis.
+  - help updated
+  - prints max compressed framesize at exit (both avi & mpeg)
+  - AVI audio seeking fixed: some ACM codecs (divx audio and ms-adpcm)
+    can't seek inside a chunk, they are only able to play whole chunks.
+    Current audio seeking has changed to seek inside the chunk only if the
+    codec supports it (only internal codecs and ACM/mp3 allows it).
+  - AVI: audio delay correction if can't seek inside the chunk
+
+v0.10-pre6:  mpeg signal & EOF fixes
+  - ./configure: k6_mtrr (2.4.test11+) added [Pontscho]
+  - `term destroys if mplayer (mpg) called from mc.ext` bug fixed:
+    added sighandler to the 3rd process (mpeg codec) to avoid sig. recursion
+  - better output at exit (handled now by exit_player())
+  - mpeg EOF problem (codec restart) fixed: added EOF detection to parse_es.c
+  - internal flag 'current_module' added to get more info at segfaults
+    (contains module number where the segfault occured)
+  - audio detection changed: using afm=4 (Win32/ACM) for MP3 audio (AVI files)
+    (you MUST have l3codeca.acm at /usr/lib/win32, or you have to use '-afm 1')
+
+v0.10-pre5:  flipping fixed
+  - AVI image flipping reworked:
+    - new flag: avi_header.flipped, TRUE if upside-down
+    - image flipping code removed/disabled from libvo modules
+    - duplicate flip_page() calls removed (overload with x11 and mga)
+  - aLaw audio codec (AVI id 0x06) added (uses code from xanim source)
+
+v0.10-pre4:  test release, small fixes
+  - video_out driver <-> codec incompatibility message changed
+  - fixed the config.format bug in drivers/mga_vid_test, so it works again!
+    [thanks to David Whysong]
+  - libmpeg2 upgraded
+
+v0.10-pre3:  test release, verbose mode, new docs
+  - new option:  -v  =  increment verbose level
+    (debug printf's changed to verbose level-dependent)
+    - default level: 0, only some informal output
+    - init debug:    1, some basic debug infos, avi header, function values
+    - player debug:  2, print avi indexes, chunk inputs, more debug infos
+    - parser debug:  3, prints everything related to input parsers
+    to increment verbose level, use multiple -v options (-v -v -v for level-3)
+  - bitrate calculation for AVI files
+  - README rewritten, added Troubleshooting and Bugreports sections
+  - TVout directory added (only the scripts)
+
+v0.10-pre2:  bugfix test release, bps-sync enabled
+  - avi: supporting both 0-based and movi-based index types (autodetect)
+  - avi: tested with VBR audio: plays well with -mc 0 option, seek doesn't
+    work yet   [thanks to Alan Chen for testfile]
+  - avi: A-V sync to avg. byte/sec implemented (again) and enabled by default
+    (disable with -nobps if you want)
+  - ./configire: 3rd name ('kni') of the P3 added. Where is the compatibility?
+  - useless '\' removed from libac3/Makefile  [Otvos Ferenc]
+
+v0.10-pre1:  test release, players merged!!!
+  - avip and mpegp has been merged to a single binary called 'mplayer'
+    - file type detection (AVI/MPEG-PS/MPEG-ES/Other)
+    - no redundant code (common code for common jobs)
+    - big format-dependent codes moved to functions (separated files)
+    - better error messages, removed some debug stuff, code cleanups
+  - old libmpeg2 version removed from source tree
+  - help texts merged (help_avi+help_mpg -> help_mp)
+  - new options:  -x <x> -y <y>     = scale image (if selected driver supports)
+    if value<=8 then image size will be multiplied by value, otherwise
+    image size will be scaled to <value> pixels.
+    For example:
+      2x ZOOM:  mplayer -x 2 -y 2 test.mpg
+      800x600:  mplayer -x 800 -y 600 test.mpg
+    [default values are still configurable at compile-time, see config.h]
+  - TV project (not finished) codebase added (see tvision.c, or: make tvision)
+
+v0.09:  Beta release [same as 0.09-pre3]
+  - version changed in the files
+  - docs updated  
+  
+v0.09-pre3:  bugfix test-release, X11 support testing
+  - fixed the  if [ -z $pparam ]  bug in ./configure  [Christian Birchinger]
+  - many changes in AVI seek code, resulting near-perfect seeking now!
+    current method calc absolute audio position, so with VBR audio it
+    doesn't work yet...
+  - avip: Xv support (YUY2 image format)
+  - avip: X11 support (24 & 32 bpp only, BGR format)
+    I need a very fast 15->16bpp converter for 16bpp support... anyone helps?
+
+v0.09-pre2:  bugfix test-release 
+  - removed unnecessary code from libmpeg2/header.c
+    Walken told me that standard mpg/vob streams must NOT use framerate
+    and bitrate extension... and the ext. id check is done by the caller.
+  - CRC support to mp3lib's mpeg audio layer-2 decoder
+    thanks for bugreport & testfile to Samson
+
+v0.09-pre1:  bugfix test-release
+  - imported new libmpeg2 files (under testing...)
+  - GL renderer flickering bug fixed (MMX missing emms() between yuv2rgb and
+    glTexSubImage(), bug triggered by new Utah-GLX code)
+    [thanks for Christian Birchinger]
+
+v0.08: Index support, avi seeking, DLL loader fix, compilation fixes
+  - Added support for chunk index usage (disable with -noidx option)
+  - Removed code optimization flags from loader/Makefile because
+    it segfaults if compile optimized code (it does some hacks with
+    pointers, maybe the reordered code confuses it)
+  - added new tool called aviparse  (read and check avi file structure)
+  - indexed and raw chunk info comparing, bad chunks dropped
+  - termcap usage is optional (for those debian users without termcap)
+  - #if HAVE_* fixed (to #ifdef HAVE_*)
+  - ./configure supports new /proc/cpuinfo (2.4.0-test11)
+      - sse is called 'sse' again
+      - 'flags' field renamed to 'features'
+  - Xv benchmark results added to DOCS/SPEED
+  - avi seeking (and other goodies, pause etc) implemented
+    no PTS resync after seek yet.
+  - default video_out driver changed from 'mga' to the first available driver
+    new driver priority:  mga_vid, opengl, x11
+
+v0.07: Easier compile
+  - Added Pontscho's ./configure script (it's modified a lot)
+  - Updated makefiles, and tested a lot :)
+  - Updated DOCS/INSTALL
+
+v0.06: Better codec selection
+  - avi audio&video codec selection moved to new codecs.c file,
+    loader/driver.c and loader/afl.c modified for this
+  - yuv support fixed, codecs.c setup flags to handle yuv properly
+    yuv works fine with divx, mpeg4, cvid, and upside-down iv50
+  - DOCS/INSTALL updated
+  - DOCS/SPEED updated, DivX benchmarks added
+
+v0.05: Merged with MPEGplayer 0.90pre6, first public release of AVI player
+  - code merged with mpegplayer, new Makefile, some small modifications
+  - docs updated and moved to DOCS
+
+v0.04: YUV support, some code cleanup, preview-release
+
+v0.01: first version based on new MPEGplayer's codebase.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DOCS/ChangeLog.mpeg	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,232 @@
+ChangeLog:
+~~~~~~~~~~
+v0.2:  [first public release]
+- parser: add support for VOB files (audio format still has problems...)
+- libmpeg3: improvements in file-type detector, supporting mpegs with RIFF hdr
+- libmpeg3: improvements on mpeg3_read_program() to handle damaged files better
+- libmpeg3: new functions for separated PTS access: mpeg3_audio_pts() and
+  mpeg3_video_pts(), they return timestamp in seconds, format: double
+- play: new audio-video sync method, using timestamps from streams.
+  much better, even on very damaged files!
+- play: measuring of audio buffer size instead constant hard-wired value
+- libmpeg3: more improvements to handle better strange files...
+- play: drop timestamp correction if > 2 seconds (good for concatenated files)
+
+v0.3:
+- much better audio-video sync, using limited timestamp correction
+- TVout directory added, with tools & scripts to setup TVout on Matrox cards
+  (it is able to play mpegs fullscreen on TV without using X)
+
+v0.5:
+- integrating dvdview for video decoding
+  (still using libmpeg3 for system stream parsing and audio decoding)
+  -> not works... some variable randomly changes (uninitialized pointers
+  in dvdview??? c++/c mixing problem?)
+
+v0.6:
+- new player from scratch, using my mp3lib for audio, parser.c for demuxing.
+  integrated dvdview is still buggy...
+
+v0.7:  [second edition]
+- dvdview as separated process, using FIFOs for communication.
+- some fixes in dvdview/system/sysdec1.cc, improved re-syncing on reset
+- double-buffering support into dvdview's mga_vid class (and some
+  changes in the mga_vid kernel module too!)
+- EOF problem solved
+- background playing option (using MGA Color-Keying and xsetroot)
+- rebuild README, added Standard Disclaimer section
+
+v0.71:
+- better missing-stream detection (counting only the real packets)
+- check for file and missing streams before fork()
+- fixed ugly byteorder bug when reading header dword
+- new system stream sync method (doesn't requires SYSTEM_HEADER_START_CODE)
+- seeking (byte or second pos), works *only* with streams with immediate
+  SYSTEM_HEADER frames.
+
+v0.8:  [seeking works]
+- implementing own video packet reader -> disabling the whole streaming part
+  of dvdview.
+- saving system headers, and re-sent after starting dvdview (seeking/resync)
+  -> allow seeking in single-header mpeg files (contact2.mpg)
+- advanced resync and seek_sec method, using video-packet type-checks
+- fix read() problem, when not enough bytes available in fifo (see man 2 read)
+- removed unused objects (postproc,options,streaming) from dvdview's Makefile
+  (smaller executable, faster compile)
+- sec. and bytepos seek fixed, works well now.
+- simple console gui, using my getch2 (from mailer3 source) for keyboard.
+  allows seek,pause,quit functions (for testing only)
+  it's time to begin develop some nice GUI with skins, plugins etc :)
+- improved runtime seeking, added force_redraw variable, and PTS audio
+  correction after every seek.
+
+v0.81:
+- fps fixed (other than 25fps supported again)
+- EOF handling fixed again
+- nosound support (currently only system streams supported, not video-only)
+  also see -nosound commandline option
+- mga_vid: changed mmap() to allow double buffering in 704x528
+- mga_vid: double buffering is optional from now (dvdview option -db )
+* it successfully plays .VOB files (without sound)
+- PTS/DTS support in mpeg-2 system streams (.vob files)
+- PCM audio (48kHz stereo, unsigned, swapped byteorder) playing implemented
+* it "plays" .VOB files with PCM sound, but it's too sloooooow :(((
+- some optimization of dvdview's bitstream handler (see FillBits & GetBitsFast)
+
+v0.82:  [VOB support]
+- updated dvdview from current CVS version (1.2.0-pre) -> about 25% faster!!!
+* it's now fast enough for VOB playback
+- AC3 audio support (using Aaron Holtzman's libac3 from ac3dec package)
+- new, simpler Makefile for libac3
+- re-organized text files (README splitted to ChangeLog and AUTHORS)
+
+v0.83:  [ALSA support]
+- some timing code to fix audio syncing with ALSA drivers (test it! I can't)
+  use -alsa cmdline option to enable this experimental code!
+- cmdline option (-abs) for overriding audio buffer size (default: measured)
+  why is it needed? some audio drivers has bad implementaion of select(),
+  so measuring buffer size gives false result.
+  if you hear sound before picture window appears, then you should use this!
+
+v0.84:
+- multiple DVD audio channels/streams support (use -aid option to select chn.)
+- cmdline option for maximum PTS time correction (-mc <value>)
+- PTS sync code moved to frame display loop -> more precise timing
+  now it sync audio after every 5 decoded frames
+- cmdline option for override frame rate (-fps <rate>)
+  some .VOB files has bad frame rate value in headers (why? any ideas?)
+- ac3 audio seeking works (some hack in libac3's parse.c)
+
+v0.85:  [first non-experimental release]
+- directory structure changed
+- better documentation, added new INSTALL
+- every Makefile uses OPTFLAGS environment variable, see INSTALL
+- help (run mpg12play without any parameters or with -h/--help)
+- fixed byte seeking (-sb)
+- allow selecting mpeg audio channel, see -aid (streams 0x1C0-1DF)
+- allow selecting video channel, see -vid   (0x1E0-1EF)
+- allow audio format override, see -afm
+- new streaming system (with 4k buffering)
+- initial VCD (Video CD) support, use -vcd to select track, and give
+  device name as filename (e.g.: mpg12play -vcd 2 /dev/cdrom)
+  Problems with dual streaming, it's very slow! reads every sectors twice...
+- VCD cache system... -> solved dual (A+V) streaming slowdown
+
+v0.86:  [cleanup]
+- last_frame_* thing removed + control fifo read() fixed -> better and
+  linear (no seek-back) resync if dvdview dies
+- better nosound timing (uses -alsa timer), seeking works
+- resync_to_pts eliminated (using new max_pts_correction)
+- cleanups, error checks, small fixes in the whole player.c
+- removed some unused old code
+- exit code moved to exit_player(), removed redundancy, fixed kill order
+
+v0.87:
+- i've found the reason of bad fps value with some vob files...
+  the fps is correct, but the dvdview doesn't decode all the frames
+  (reads repeat_first_field flag but don't rely on it)
+- new demuxer code: read & demux input stream only at once, and uses two
+  memory FIFO-s for packages. also new reader code, everyting named ds_*()
+  The new demuxer can autodetect video and audio stream ids, if not
+  specified with -aid / -vid option, and better implementation of -afm
+- vcd cache is optional (and disabled by default), because unneccesary with 
+  new demux/streaming code
+
+v0.90pre:
+- new codec added: mpeg2dec by Aaron Holtzman
+  after doing some fixes (see at bottom), it's able to play mpeg1/mpeg2 video
+- FIFO API changed: after frame_complete command (0x0) the codec must
+  send the fps*10000 and the length*100 value. length is 1.00 for a simple
+  frame, and >=1 for mpeg2 fields (eliminates the fps problem)
+  Now, using mpeg2dec we are able to play .vob files with correct fps timing!
+- better AC3 resync after seek (new func. in libac3: ac3_bitstream_reset())
+  using ac3_decode_frame() instead ds_fill_buffer() when syncing PTS
+
+v0.90pre2:
+- mpeg2dec integrated into player binary
+- using pipe() instead of named pipes
+- using shared memory (mmap(...MAP_ANON...)) for packet transfer to codec
+- stream_select() thing removed
+- some optimization in demuxer code
+- measuring codec CPU usage (relative to video time!!!, so it can be >100%
+  on a slow system)  This value must be <=100% for continous video playback.
+
+v0.90pre3:
+- ugly bug fixed causing packet loss at codec restarting
+  (i wrote control_fifo instead of control_fifo2 into codec controller)
+- video init part moved to the player
+- using shared memory for image buffers to avoid green flashes when
+  codec restarted...
+- new shared memory allocation code (the mmap() thing worked only with 
+  kernel 2.4.x). thanx to LGB for the info and help...  see linux/shmem.[ch]
+- config.h moved, Makefiles changed a bit (added libvo path, thanx to LGB)
+  you may select CPU extensions (3Dnow/MMX/SSE) *only* at config.h
+- meaningfull error messages if video stream cannot be synced
+  (many user asked about "missing video stream" error...)
+
+v0.90pre4:
+- included new mpeg2dec source (with SSE idct code)
+
+v0.90pre5:
+- libvo: OpenGL video renderer code by me
+- included new mpeg2dec and ac3dec from today CVS snapshot
+- new docs: SPEED and MTRR
+- seq. head processing and video init code moved into player.c, just
+  before fork()'ing, so the child inherits all this info!
+- removed all sequenceheader[] code, it's unneeded now
+- source cleanup, removed some debug printf()'s, old comments
+- EOF problem seems to be solved (maybe at the cleanup???)
+- implemented bitrate (and free framerate) reading into mpeg2dec/header.c
+- seeking skip times are better, based on bitrate
+
+
+Changed in libac3 source:
+~~~~~~~~~~~~~~~~~~~~~~~~~
+- ac3.h replaced with the old version from v0.6.0
+- decode.c modified to fit my interface
+- stats.h: use stats_* functions only if DEBUG defined
+
+Changed in libmpeg2 source:
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+- header.c: implemented repeat_first_field thing (see picture.repeat_count)
+- HACK_MODE set to 1 (default is 0, which works only with mpeg2 streams)
+- decode.c: some changes added, active only if MPG12PLAY #defined
+- header.c: implemented bitrate (and free framerate) reading
+
+Changed in libvo source:
+~~~~~~~~~~~~~~~~~~~~~~~~
+- fixed bug in mga_vid vo module: used dest_width/height instead src_*
+  (dst is important only for the card, we need (for memory, etc) the src size!)
+- added OpenGL video renderer (based on x11 rendere and Pontscho's opengl code)
+
+Changed in DVDview source:
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+main.cc:  replaced with my code
+Makefile: removed unneccesary objects, added optimization flags
+output/out_mgavid.cc & .hh:  added double-buffering and color-keying support
+system/userpack.cc & .hh: new code, by me  (interface to my packet reader)
+video12/vdecoder.hh: added GetSeqHeader() function (for accessing FPS value)
+video12/vdecoder.cc: commented out calls to PrintDataBin() (debug info only)
+
+TODO:
+~~~~~
+- multiple video packets (whole frame) transfer to codec - DONE
+- B-frame skipping (DVD for slow systems)
+- VCD support - DONE
+- DVD Audio downsampling (for 44kHz cards)
+- SEEKing in VOB files with AC3 sound (some hack needed in libac3) - DONE
+- own AC3 frame reader -> better resync after seek - DONE
+- player source is really ugly now... it's time to some cleanup - DONE?
+- seek/resync without immediate SYSTEM_HEADER frames. - DONE
+- end of file detecion !!! - DONE - NOT done (see matrix.vob!) - DONE
+- other than 25fps movies - DONE
+- test with mono sound - DONE (currently playing as stereo)
+- nosound (no audio card or no audio stream) - DONE
+- .vob support (non-crypted DVD/mpeg2 stream) - DONE
+- AC3 and PCM audio support - DONE
+- audio-only and video-only file support
+- nice GUI (something new written in gtk or modify xmovie's gui)
+- Xv support - DONE (libvo has it)
+- easier compile, maybe new ./configure and makefiles - DONE?
+- decss support (encrypted dvd)
+- test speed with pgcc (does it worth?)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DOCS/INSTALL	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,29 @@
+    =======================================================================
+     * HOW TO COMPILE MOVIE PLAYER COMPONENTS * (C) 2000. A'rpi/ESP-team *
+    =======================================================================
+
+Pontscho/Fresh! did some script and makefiles so compiling is much
+easier now. If you find a bug in that, please contact us:
+  pontscho@makacs.poliod.hu
+  arpi@esp-team.scene.hu
+
+1. The Player: (mplayer)
+~~~~~~~~~~~~~~
+  ./configure
+[* check config.h and config.mak files! *]
+  make dep
+  make
+  make install
+
+2. Drivers: (mga_vid.o)
+~~~~~~~~~~~~~~~~~~~~~~~
+  cd drivers
+  make
+  mknod /dev/mga_vid c 178 0
+  chmod go+rw /dev/mga_vid
+
+3. Matrox G400 DH TV-out tools:
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  cd TVout
+  ./compile.sh
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DOCS/LIRC	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,54 @@
+
+LIRC support for MPlayer
+ written by Andreas Ackermann in 2/2001
+ contact: acki@acki-netz.de
+
+o What is LIRC?
+
+ Linux Infrared Remote Control - use an easy to build home-brewn IR-receiver, 
+ an (almost) arbitrary remote control and control your linux box with it!
+ More about it at www.lirc.org.
+
+o MPlayer and LIRC
+
+ If you have installed the lirc-package, you can compile MPlayer with LIRC
+ support using  ./configure --enable-lirc
+ You should do 'make distclean' before re-compile with 'make dep;make'
+
+ If everything went fine, MPlayer will print a message like 
+   LIRC init was successful.
+ on startup. If an error occurs it will tell you. If it doens't tell you 
+ anything about LIRC there's no support compiled in. That's it :-)
+
+ The application name for MPlayer is - oh wonder - mplayer.
+ It understands the following commands:
+
+ PAUSE  - pause playing. Any other keystroke will continue replay.
+ QUIT   - exit mplayer
+ RWND   - 10 secs back
+ FRWND  - 60 secs back
+ FWD    - skip 10 secs
+ FFWD   - skip 60 secs
+
+ Don't forget to enable the repeat flag for RWND/FWD in .lircrc. Here's an
+ excerpt from my .lircrc:
+
+ begin
+  remote = CU-SX070
+  prog = mplayer
+  button = Tape_Play
+  repeat = 1
+  config = FFWD
+ end
+
+ begin
+  remote = CU-SX070
+  prog = mplayer
+  button = Tape_Stop
+  config = QUIT
+ end
+	      
+ Enjoy
+
+ -Andreas
+ 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DOCS/MPlayer-FAQ	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,120 @@
+Yes, this is the MPlayer FAQ.
+=============================
+
+About:
+~~~~~~
+Many people asked same questions so I decided to write this stuff.
+I know that people will never read this but at least i try to
+pull down number of these mails.
+And from now i can say that "read the fuckin' FAQ!" :-)
+
+Let's ask!
+~~~~~~~~~~
+Q: SDL output doesn't work or compile. Problem is ....
+A: It works only with SDL v1.1.7 (and maybe newer)
+   It does NOT work with 1.1.6, 1.1.5 1.1.4 1.1.3 1.0.4 etc, don't ask.
+
+Q: I am still having trouble compiling with SDL support. gcc says something
+   about "undefined reference to `SDL_EnableKeyRepeat'"   What's now?
+A: Where did you install the SDL library? If you installed in /usr/local
+   (the default) then edit the top level config.mak and add
+   "-L/usr/local/lib " after "X_LIBS=" Now type make. You're done!
+
+Q: I have problem ... with the SDL driver.
+A: It's very experimental & buggy code, and it's UNSUPPORTED by us.
+   Please do NOT report bugs or ask features relating to SDL.
+   But you can improve it, and send us patches!
+
+Q: It doesn't compile, and it misses uint64_t inttypes.h and similar things...
+A: copy DOCS/inttypes.h to MPlayer directory (cp DOCS/inttypes.h .)
+   try again... if fail, contact me
+
+Q: I have Pentium III but ./configure doesn't detect SSE
+A: Only kernel versions 2.4.x supports SSE
+
+Q: fullscreen option (-fs) and/or -xy doesn't work with x11 driver (-vo x11)
+A: x11 driver doesn't support scaling, and it can't change screen resolution.
+   Yes, I know that it should be but I have no time to write software
+   scaling routines and experiencing with XVidMode extension...
+   You can do it yourself, just press ALT,CTRL,- or ALT,CTRL,+ simultaneously,
+   see X-server docs for details.
+
+Q: audio goes out of sync playing .avi file
+A: try with -bps or -nobps option
+   if still bad, send me (upload to ftp) that file, I'll check.
+
+Q: what is the meaning of numbers in the status line?
+A: see:
+     A:   2.1  V:   2.2  A-V: -0.167  ct:  0.042   57  41%   0%  2.6% 0
+   - A: audio position in seconds
+   - V: video position in seconds
+   - A-V: audio-video difference in seconds (delay)
+   - ct: total A-V sync correction done
+   - frames played (counting from last seek)
+   - video codec cpu usage in percent (for mpeg it includes video_out too!)
+   - video_out cpu usage for avi, 0 for mpg (see above)
+   - audio codec cpu usage in percent
+   - dropped bad frames (mpg only)
+   Most of them are for debug purposes, and will be removed soon.
+
+Q: Why is video_out cpu usage zero (0%) for mpeg files?
+A: It's not zero, but it's built in into codec, so can't be measured separated.
+   You should try to play the file using -vo null and then -vo ... and check
+   the difference to see video_out speed...
+
+Q: OpenGL (-vo gl) output doesn't work (hangup/black window/X11 errors)
+A: your opengl driver doesn't support dynamic texture chanegs (glTexSubImage)
+   it's known not to work with X 4.0.x DRI drivers and nVidia's binary shit.
+   it's known to work with Utah-GLX and Matrox G400 card.
+   it will not work with 3DFX cards because the 256x256 texture size limit.
+
+Q: I have g200/g400, how to compile/use mga_vid driver?
+A: read INSTALL and README...
+
+Q: What's XMMP? (it's XMMS or XMPS but mispelled?)
+A: It's a new project, see www.frozenproductions.com for details
+
+Q: There are error messages about file not found /usr/lib/win32/....
+A: Download & install w32codec.zip from *our* FTP
+   (avifile's codec package has different DLL set)
+
+Q: It wants to load l3codeca.acm, but I don't have such file.
+A: You should use w32codec.zip from MPlayer FTP, instead of avifile's pack!
+
+Q: ...... works with avifile/aviplay while doesn't with MPlayer
+A: MPlayer != avifile
+   The only common thing between these players is the Win32 DLL loader.
+   The codecs (dll) sets, syncronization, demultiplexing etc is totaly
+   different and shouldn't be compared.
+   If something works with aviplay it doesn't mean that MPlayer should do
+   it and vice versa. You should contact me, I'll fix the bug!!!
+
+Q: Indeo 3.x/4.x movies are viewed upside-down!!!?
+A: It's a known bug (really it's a bug/limitation of the DLL codec)
+
+Q: Indeo 3.x,4.x video doesn't work at 32bpp resolutions (16,24 bpp are ok)
+A: It's a known bug (really it's a bug/limitation of the DLL codec)
+
+Q: I've got 'MPlayer interrupted by signal 11' in module audio_setup or
+   decode_audio.
+A: It's a damaged file with bad mp3 audio stream. Try it with  -afm 4
+
+Q: It aborts with signal 11 playing a file with IMA-ADPCM audio.
+A: This codec isn't yet supported!
+
+Q: Why do you enjoy making that much pre-releases?
+A: Download one and you'll know!
+
+Q: Are there rpm/deb/... packages of MPlayer?
+A: Not yet.
+
+Q: Are there any mailing lists on MPlayer?
+A: Yes! See README on how to subscribe them!
+
+Q: I've found a nasty bug when I tried to play my favourite video!!
+   Who should I inform?
+A: Inform the MPlayer-users mailing list about your problem. *ALWAYS*
+   read the README about what information we NEED to identify your problem.
+   Use the developers addresses (specified in AUTHORS) only if you want to
+   flame, or want to ask for a date. ;)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DOCS/MTRR	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,38 @@
+Setting up MTRR for X11 or mga_vid:
+===================================
+
+1. find the base address
+~~~~~~~~~~~~~~~~~~~~~~~~
+You have 3 cases to find it:
+
+- from X11 startup messages, for example:
+(--) SVGA: PCI: Matrox MGA G400 AGP rev 4, Memory @ 0xd8000000, 0xd4000000
+(--) SVGA: Linear framebuffer at 0xD8000000
+
+- from /proc/pci (use lspci -v command):
+01:00.0 VGA compatible controller: Matrox Graphics, Inc.: Unknown device 0525
+        Memory at d8000000 (32-bit, prefetchable)
+        
+- from mga_vid kernel driver messages (use dmesg):
+mga_mem_base = d8000000
+
+2. find memory size
+~~~~~~~~~~~~~~~~~~~
+This is much easier, just convert video ram size to hexadecimal, or
+use this table:
+   1 MB    0x100000
+   2 MB    0x200000
+   4 MB    0x400000
+   8 MB    0x800000
+  16 MB   0x1000000
+  32 MB   0x2000000
+
+3. setting up mtrr
+~~~~~~~~~~~~~~~~~~
+You know base address and memory size, let's setup mtrr registers!
+
+  For example, for the matrox card above (base=0xd8000000) with 32MB
+  ram (size=0x2000000) just execute:
+echo "base=0xd8000000 size=0x2000000 type=write-combining" >| /proc/mtrr
+
+(older K6-2's [around 266Mhz, stepping 0] may not support MTRR.)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DOCS/OpenDivX	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,30 @@
+
+OpenDivX support in MPlayer
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+See http://www.projectmayo.com for details on Open DivX codecs.
+It's an opensource DivX-like video codec written for windows.
+I did a fast hack to get it compile under linux (it has some
+dependency on windows header files and some visualc extensions).
+
+Decoder:
+~~~~~~~~
+Now it's used for AVI files with fourcc 'dvx1'
+You can adjust Quality level using the -divxq option. Valid values:
+
+ postprcc_level =  0      ---->  no post processing (fastest)
+ postproc_level =  1 ~  9 ---->  horizontal Y deblocking only
+ postproc_level = 10 ~ 19 ---->  hor. + ver. Y deblocking
+ postproc_level = 20 ~ 29 ---->  hor. + ver. Y and hor. C deblocking
+ postproc_level = 30 ~ 39 ---->  hor. + ver. Y and hor.+ver. C deblocking
+ postproc_level = 40 ~ 49 ---->  h+v Y, h+v C deblock and Y deringing
+ postproc_level = 50 ~ 59 ---->  h+v Y, h+v C deblock and Y+C deringing
+
+Note: last level (Chroma deringing) sometimes crashes.
+
+Encoder:
+~~~~~~~~
+There is a very alpha hack to convert mpeg video into OpenDivX .avi files.
+You should disable audio, and select 'odivx' video device as output:
+  mplayer input.mpg -nosound -vo odivx -encode output.avi
+Yes, I know that it's unusable now, it's only for testing purposes.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DOCS/README	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,271 @@
+MoviePlayer v0.11        (C) 2000-2001. by Arpad Gereoffy  (A'rpi/ESP-team)
+=================           * See the file AUTHORS for the complete list! *
+
+About:
+~~~~~~
+Yes. Yet another movie player for linux.
+What is the special with this? It works, at least for me :)
+I've tried lots of players under linux (mtv,xmps,dvdview,livid/oms,VideoLAN,
+xine,xanim,avifile,xmmp) but they all have some problem. Mostly with
+special files or with audio/video sync. Most of them is unable to play
+both mpeg1, mpeg2 and avi (DivX) files. Many players have image quality
+or speed problems too. So I've decided to write/modify one...
+
+Short history:
+- mpg12play v0.1 has born, using libmpeg3 from www.heroinewarrior.com
+- mpg12play 2nd generation (v0.5-), using dvdview by Dirk Farin
+- mpg12play 3nd generation (v0.9-), using libmpeg2 (mpeg2dec) by Aaron Holtzman
+- mplayer has born, containing mpg12play 0.90pre5 and a new simple avi player
+- mplayer 0.10, mpeg and avi player in a single binary
+- mplayer 0.11: added .asf file support, and OpenDivX en/decoding
+
+As you see, I didn't write any codecs, just some players. But I spent
+a lot of time finding the best way to parse bad damaged input files
+(both mpg and avi) and to do perfect A-V sync with seeking ability.
+My player is rock solid playing damaged mpeg files (useful for some VCDs),
+and it plays bad AVI files which are unplayable with the famous
+windows media player. Even AVI files without index chunk are playable!
+As you see, stability and quality are the most important things for me,
+speed has lower priority, but is still very important.
+
+What about the GUI?
+I'm not a GUI programmer. I hate GUIs, I like the pure black 80x25 console.
+So the player has only keyboard control from the controlling console/xterm now.
+But there is a GUI development for the player, coordinated by Pontscho/Fresh!
+It's still under development, but it will be merged and released soon.
+BTW he needs some nice skins, if you are a good graphician, contact him!!!
+
+Win32 codecs?
+Yes, we are using Win32 (Video for Windows) codecs for AVI/ASF decoding.
+They must be installed to the /usr/lib/win32/ directory, with all lower case.
+You can grab the codecs package from 
+  ftp://thot.banki.hu/esp-team/linux/MPlayer/w32codec.zip
+or can be found in your C:\WINDOWS\SYSTEM\ dir, see codecs.c for filenames.
+Some people asked why don't we use ActiveMovie/DirectShow codecs. The reason is
+simple: we'd have to emulate the whole DirectX architecture and implement the
+(patented!) COM interface to be able to use them. BTW the old VfW DivX codec
+is faster than the new .AX version, but it has no quality/CPU setting
+option (this is an improper name, since it doesn't affect the decoder. If
+it's set to 1 or higher, it applies a filter which decreases blockiness and
+eats away CPU cycles).
+
+Supported input formats:
+~~~~~~~~~~~~~~~~~~~~~~~~
+- VCD (Video CD) directly from CD-ROM or from CDRwin's .bin image file
+- MPEG 1/2 System Stream (PS/VOB) and Elementary Stream (ES) file formats
+- RIFF AVI file format
+- ASF 1.0 file format
+
+Supported audio codecs:
+~~~~~~~~~~~~~~~~~~~~~~~
+- PCM (uncompressed) audio (8/16 bit, mono/stereo)
+- MPEG layer 2/3 audio  (using mp3lib, based on mpg123)
+- AC3 audio             (using ac3dec/libac3)
+- Win32 ACM audio codecs (the *.ACM files)  [Only in the AVI player]
+  tested with: DivX audio, MS-ADPCM
+- aLaw audio            (using code from xanim)
+- MS-GSM audio          (using modified xa_gsm.c from avifile)
+
+Supported video codecs:
+~~~~~~~~~~~~~~~~~~~~~~~
+- MPEG 1 and MPEG 2 video decoder (using mpeg2dec/libmpeg2, supports         
+  3DNow! and MMX)
+- Win32 ICM (VfW) video codecs (for example DivX using DIVXC32.DLL)
+- OpenDivX encore & decore (see ProjectMayo)
+
+Supported video output devices:
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+- mga:  Matrox G200/G400 hardware YUV overlay via the mga_vid device
+	(Some people reported that G200 is broken :(  if you are a programmer
+	and you have a G200, please check it and fix if you can!)
+- xmga: Matrox G200/G400 overlay (mga_vid) in X11 window
+	(Xv emulation on X 3.3.x !)
+- x11:  X11 optionally with SHM extension
+- xv:   X11 using overlays with the Xvideo extension (hardware YUV & scaling)
+- gl:   OpenGL renderer, requires Utah-GLX or DRI or nVidia's new driver
+- syncfb: Matrox G400 YUV support on framebuffer (not tested, maybe broken)
+- 3dfx: Voodoo2/3 hardware YUV (/dev/3dfx) support (not yet tested, maybe broken)
+- sdl:  SDL v1.1.7 driver (slower than 'x11', but supports software scaling)
+- null: Null output (for speed tests/benchmarking)
+- pgm:  PGM file output (for testing purposes)
+- md5:  MD5sum output (for mpeg conformance tests)
+NOTE: not all are available for AVI files
+
+Supported audio output devices:                                              
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+- OSS driver
+- ALSA driver with OSS emulation
+- ESD with the esddsp utility
+
+Speed:
+~~~~~~
+Most of time-critical parts are optimized for MMX/SSE/3DNow!.
+You can improve rendering speed by setting up MTRR registers, see doc in MTRR.
+Some benchmark results can be found in the doc file SPEED.
+
+Usage:
+~~~~~~
+  mplayer [options] [-vo driver] [path/]filename
+
+  Options:
+    see  mplayer -h for options
+    see  mplayer -vo help for available output drivers
+
+  Keys:
+    <-  or  ->      seek backward/forward 10 seconds
+    up or down      seek backward/forward 1 minute
+    p or SPACE      pause movie (press any key to continue)
+    q  or  ^C       stop playing and quit program
+
+  Examples:
+    mplayer -vo x11 /mnt/Films/Contact/contact2.mpg
+    mplayer -afm 3 /mnt/DVDtrailers/alien4.vob
+    mplayer -vcd 2 /dev/cdrom
+    mplayer -alsa -abs 65536 -delay -0.4 -nobps ~/movies/test.avi
+
+  Note:  for using Matrox YUV driver (-vo mga or xmga), you have to first
+         load the driver: insmod drivers/mga_vid.o
+
+License:                                                                     
+~~~~~~~~
+Since MPlayer incorporates a lot of code from other projects, this isn't
+decided yet.
+We're going for GPL (will be pretty hard, though).
+
+TV output:
+~~~~~~~~~~
+If you have a Matrox G400 Dual-Head card, you can watch movies on TV,
+using TV-out feature of the second head. You must have matroxfb support
+enabled in your kernel (2.4.x kernels). You don't need X11 for this!
+Tested only with PAL TV!
+
+  cd TVout
+  ./modules
+  ./cloning or ./independ
+  ./TV-704x528 (or another TV* script)
+
+Sending bugreports:
+~~~~~~~~~~~~~~~~~~~
+First please read all the docs in this package, most of the problems are
+described somewhere. At least read the Troubleshooting section!
+We don't like answering questions which are already answered in this
+readme or other docs.
+You should try the latest test (pre) release version too, maybe your bug
+is already fixed, but the new version hasn't been released.
+If you couldn't solve the problem, then send a quality bugreport
+via E-Mail to the MPlayer-users list : mplayer@alan.umcs.lublin.pl
+
+*NEVER* send attached AVIs, MPEGs, or any big files to this list!!!
+Upload them to ftp://thot.banki.hu/incoming , and inform the list about
+your upload.
+
+Please include these:
+- your kernel version number ('uname -a')
+- linux distribution and glibc version  (example: Slackware 7.1 + glibc 2.1.3)
+- gcc and binutils version ('gcc -v' and 'as --version')
+- your X11 version         (example: X 4.0.2 + DRI snapshot2001jan12)
+- video card vendor/model  (example: Matrox G400 MAX AGP)
+- CPU vendor and type      (example: Intel Celeron2-566 at 850MHz)
+
+Also include the required logs (as attachment, may be compressed zip/gz/bz2)
+depending the problem type (see bellow at Troubleshooting section).
+
+To log output to a file, use the &> shell operator. For example:
+  ./configure &>configure.log
+  mplayer -v test.avi &>play.log
+
+If we ask you for the file, then you have two choices:
+- upload the file to ftp://thot.banki.hu/incoming (at least a few megabytes)
+- send the exact URL of the file, and we'll download it soon.
+
+Please do not ask for features already listed in the TODO!
+
+Troubleshooting:
+~~~~~~~~~~~~~~~~
+1. Please read the docs first...
+
+2. If you have compiling problems:
+   - if you are an experienced programmer, please try to fix it, and send
+     us the patch
+   - if gcc reports problems around inttypes.h, try to copy DOCS/inttypes.h
+     to the directory where the error occured. (or upgrade glibc to 2.1/newer)
+   - if gcc reports problems around video_out_gl.c, try disabling OpenGL
+     support: ./configure --disable-gl (you have broken OpenGL headers/libs)
+   - if you are a user, send us a bugreport (see above), including these:
+      - output of ./configure
+      - output of make dep and make
+      - config.h and all of config.mak files
+   Note: many users reported that SSE was not detected while running on P3.
+   Current stable 2.2.x kernels does NOT support SSE, so you can't use it
+   without patches or using the 2.4.x series.
+
+3. If you have a problem with the player, please run it with -v option, and
+   send the output of it, with a detailed description of the problem.
+   - can't play AVI files: check that codec .DLL and .ACM files are installed to
+     /usr/lib/win32/ and are all lowercase (divxc32.dll instead of DivXc32.DLL)
+   
+4. If you have a file-specific problem (can't play a special file,
+   crashes with it or similar) then please run with -v -v -v (debug level 3).
+   Send us the output and the problem description via email bugreport.
+   We may ask you to upload the file.
+   - if it segfaults with an AVI file with MP3 audio, try with -afm 1 or -afm 4
+   - if it's still bad, try with -nosound
+
+5. If you have problem with display driver, please first check the list above,
+   many of them isn't yet capable to AVI playing, and some of them are
+   untested and/or unfinished.
+
+6. If you have speed problems (too slow playing), then please first check that:
+   - you don't use OpenGL driver while have software-only opengl (DRI disabled,
+     or not yet installed, conflicting libs installed, or your hardware not
+     supported etc...)
+   - you have set up MTRR registers properly (many new cards are really
+     slow without setting up MTRR registers. it's NOT done by X 3.3.x! Also,
+     there are older K6-2's, which lack MTRR support /stepping=0/).
+   - you have a fast machine (don't report that your 386 can't play DivX)
+   - try with Null output (-vo null) and check CPU usage (first % value)
+
+7. sound-related problems:
+   - maybe your card doesn't support 48kHz playback and the movie requires it.
+   - try player with the -noalsa option
+   - delayed audio with some AVI files: try with -bps or -nobps option!
+   - if you experienced delayed audio, try to compensate with -delay or -abs.
+     you can specify audio card's buffer size in bytes with -abs option, or
+     specify audio delay in seconds (positive/negative float) with -delay
+     for example:  mplayer -alsa -delay -0.75 test.avi
+                   mplayer -abs 65536 -delay 0.3 test.mpg
+   - to play AVI files with VBR MP3 audio use the  -mc 0  option!
+   - no sound at all: check that you have working OSS driver (/dev/dsp),
+     and it isn't used by another program (for example esd, xmms etc.)
+
+8. unsupported codecs (AVI files):
+   We may add support for your movie, but we need the following things:
+   - the codec DLL file: find it in your WINDOWS directory. In the SYSTEM.INI
+     there will be a listing of the installed codecs (vids.<codecname>=DLLfile)
+   - a sample file encoded with that codec.
+
+
+Download:
+~~~~~~~~~
+Download:  ftp://thot.banki.hu/esp-team/linux/MPlayer/
+      or:  http://thot.banki.hu/esp-ftp/linux/MPlayer/
+Homepage:  http://thot.banki.hu/esp-team/MPlayer.html
+
+Mailing lists:
+~~~~~~~~~~~~~~
+There are two public mailing lists on MPlayer. Subscribing can be achieved by
+writing to the following addresses, and specifying "subscribe" in the Subject,
+or message body.
+
+- MPlayer-users
+       Write an e-mail to mplayer-request@alan.umcs.lublin.pl
+- MPlayer-announce
+       Write an e-mail to mplayer-announce-request@alan.umcs.lublin.pl
+
+Special thanks to Dariusz Pietrzak for the list hosting!
+
+Standard Disclaimer:
+~~~~~~~~~~~~~~~~~~~~
+Use only at your own risk! There may be errors and inaccuracies that could 
+be damaging to your system or your eye. Proceed with caution, and although
+this is highly unlikely, I don't take any responsibility for that!
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DOCS/SOUNDCARDS	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,21 @@
+Recommended options for better sound sync:
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+(first try without these, maybe it works well without 'hacking' defaults)
+
+ALSA:			-alsa -abs 65536
+
+Aureal Vortex2:		-alsa -abs 65536 -delay -0.5
+
+SB Live!:		kernel 2.2.x: -alsa
+                               2.4.x: nothing
+
+OSS/Free:	        please contact me for good parameters
+
+
+... and not use your soundcard by other application ( for ex. XMMS ) ...
+... and use very-very high speed hdd or CDROM and CPU ...
+
+
+        Pontscho/fresh!mindworkz 
+	 pontscho@makacs.poliod.hu
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DOCS/SPEED	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,40 @@
+Some benchmark values
+=====================
+
+Test system: Abit BE6-2 mb, Intel Celeron2-566 @ 850Mhz, Matrox G400 MAX
+Linux: Slackware 7.0, kernel 2.4.0-test8, glibc 2.1.2
+
+MPEG 1/2 Video codec CPU usage in percent (%) :
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+1. Setup: mga_vid YUV, MMX idct, no mtrr settings
+2. Setup: mga_vid YUV, SSE idct, with mtrr settings
+3. Setup: Utah-GLX OpenGL + software C YUV->RGB, SSE idct
+4. Setup: X11 Shm (32bpp) + software MMX YUV->RGB, SSE idct, with mtrr
+5. Setup: null output (codec speed only)
+6. Setup: X11 4.0.1e + Xv extension, SSE idct, with mtrr
+
+                               1.   2.   3.   4.   5.   6.
+  DolbyDigitalBroadway.vob:   60%  35%  78%  67%  26%  47%
+  matrix.vob (trailer):       51%  30%  62%  56%  23%  40%
+  PAL (352x288/25) mpeg1:     16%   9%  30%  13%   7%   8%
+  3D anim (30fps mpeg1):      20%  14%  35%  25%  12%  14% 
+
+Win32 Video codec CPU usage in percent (%) :
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+(All tests with YUV/YUY2 output format to null device)
+  DivX 720x416/30fps          27%
+  DivX 704x320/25fps          24%
+  DivX 640x352/24fps          22%
+  DivX 480x204/24fps          12%
+  IV50 320x240/15fps           7%
+
+Audio codec CPU usage in percent (%) :
+~~~~~~~~~~~~~~~~~~~~~
+  Mpeg layer-2 audio (VCD):  1.2%
+  PCM audio (DVD, 48khz):    1.3%
+  AC3 audio (DVD, 2.0 mode)  4.1%
+  AC3 audio (DVD, 5.1 mode)  6.5%
+  AC3 audio (DivX, 5.1 mode) 3.5%
+  MP3 audio (mp3lib)         2.8%
+  MP3 audio (l3codeca.dll)   1.8%
+  DivX audio (divxa32.dll)   3.3%
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DOCS/TODO	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,30 @@
+TO DO:
+~~~~~~
+Urgent:
+- asterix.avi audio delays after 5-10 mins (bps mode only)
+- PAUSE doesn't work in the X11 and SDL windows (because no Check X Events)
+- SDL fullscreen problems at quit/eof - DONE?
+- finish ASF seeking
+- fix vo_syncfb - DONE for G400
+
+Fix compilation problems:
+- SDL version detection into ./configure - DONE (disabled :))
+
+Libvo features:
+- framebuffer and svgalib support (both)
+- DGA support (LGB?)
+- real fullscreen (black bands at unused areas) support - DONE for xmga & x11
+- fix X4.0.x/DRI OpenGL (doesn't work, at least mga & tdfx & nvidia)
+- change libmpeg2 & libvo interface to be compatible with libmpeg2-0.2.0 release
+
+Player features:
+- libcss support
+- subtitles support (.sub files)
+- show movie length / position in percent
+- show current frame number [Gabucino]
+- seek_to_frame and seek_to_index options
+- fix mp3lib to avoid segfault with some damaged .avi files (workaround: -afm 4)
+- integrating the gui?
+- support for more codecs  (sample .avi files and .dll needed!) - HELP!
+- support for MPEG TS (transport streams) and PES format - I need sample files!
+- verify valid range of numeric options (like '-xy 0')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DOCS/inttypes.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,13 @@
+
+// fallback if the user doesn't have inttypes.h (libc5 systems)
+
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned long uint32_t;
+typedef unsigned long long uint64_t;
+
+typedef signed char int8_t;
+typedef signed short int16_t;
+typedef signed long int32_t;
+typedef signed long long int64_t;
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DOCS/mplayer.1	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,190 @@
+.\" MPlayer (C) 2000-2001 Arpad Gereoffy <arpi@esp-team.scene.hu>
+.\" This manpage was/is done by Gabucino
+.\" Manpage v1.1
+.\"
+.TH MPlayer 0.11
+.SH NAME
+mplayer \- Movie Player for Linux
+.SH SYNOPSIS
+.B mplayer
+.RB [ \-vo\ output\ driver ]
+.RB [ \-vcd\ track\ number ]
+.RB [ \-sb\ byte\ position ]
+.RB [ \-nosound\ ]
+.RB [ \-abs\ seconds ]
+.RB [ \-delay\ secs ]
+.RB [ \-bps\ value ]
+.RB [ \-noalsa\ ]
+.RB [ \-aid\ id ]
+.RB [ \-vid\ id ]
+.RB [ \-fps\ rate ]
+.RB [ \-mc\ seconds/5f ]
+.RB [ \-afm\ audio\ decoder ]
+.RB [ \-fs\ ]
+.RB [ \-x\ x ]
+.RB [ \-y\ y ]
+.RB [ \-xy\ factor ]
+.RB [ \-dsp\ device ]
+.RB [ \-divxq\ quality ]
+.I file
+.PP
+.SH DESCRIPTION
+.I mplayer
+Yes. Yet another movie player for linux.
+What is the special with this? It works, at least for me :)
+I've tried lots of players under linux (mtv,xmps,dvdview,livid/oms,VideoLAN,
+xine,xanim,avifile,xmmp) but they all have some problem. Mostly with
+special files or with audio/video sync. Most of them is unable to play
+both mpeg1, mpeg2 and avi (DivX) files. Many players have image quality
+or speed problems too. So I've decided to write/modify one...
+.LP
+.SH "GENERAL OPTIONS"
+.TP
+.I NOTE
+MPlayer works out-of-the-box, so you generally don't have to mess with
+any options.
+.TP
+.BI \-vo\ output\ driver
+select output driver
+
+you can get the list of available drivers executing
+.I mplayer -vo help
+
+.TP
+.BI \-vcd\ track
+play video cd track from device instead of plain file
+.TP
+.BI \-nosound
+don't play sound
+.TP
+.B \-fs
+fullscreen playing (only gl, xmga and xv drivers)
+
+.I NOTE
+The X11 driver doesn't support fullscreen and scaling.
+However, you can do it yourself, just press ALT,CTRL,-
+or ALT,CTRL,+ simultaneously, see X-server docs for details.
+.TP
+.B \-x\ x
+scale image to x width [if driver suppports!]
+.TP
+.B \-y\ y
+scale image to y height
+.TP
+.B \-xy\ factor
+scale image by <factor>
+.TP
+.B \-dsp\ device
+select another DSP output device
+.TP
+.B \-divxq\ quality
+apply postprocess filter on decoded image.
+You need a STRONG CPU in order to use this!
+The supported formats and settings are:
+
+        MPEG1     1, 3, 7, 31
+        OpenDivX  1-59 (maybe less/more)
+        DivX      not YET supported
+
+.I NOTE
+You can use this with OpenDivX encoding too! See ALPHA/BETA CODE section.
+.IP
+.SH KEYBOARD CONTROL
+.TP
+.I NOTE
+These keys may/may not work, depending on your video output driver.
+.TP
+	  <-  or  ->      seek backward/forward  10 seconds
+
+up or down      seek backward/forward   1 minute
+
+p or SPACE      pause movie (press any key)
+
+q or ESC        stop playing and quit program
+
++ or -          adjust audio delay by +/- 0.1 second
+.IP
+.SH "ADVANCED OPTIONS"
+.TP
+.I NOTE
+These options can help you solve your particular problem.. Also, see the DOCS!
+.TP
+.B \-afm <1-5>
+force audio format  1:MPEG 2:PCM 3:AC3 4:Win32 5:aLaw
+
+.I NOTE
+With DivX AVIs with MP3 audio, you can choose whether to use MP3LIB (option 1),
+or Win32 DLL l3codeca.acm (option 4) (default). On CPUs with the 3DNow!
+instruction set, the first gives more performance. Your mileage may vary.
+.TP
+.BI \-sb\ position
+seek to byte position
+.TP
+.BI \-abs\ bytes
+audio buffer size (in bytes, default: measuring)
+.TP
+.B \-delay\ secs
+audio delay in seconds (may be +/- float value)
+.TP
+.B \-bps
+use avg. byte/sec value for A-V sync (AVI)
+.TP
+.B \-noalsa
+disable timing code
+.TP
+.B \-aid\ id
+select audio channel [MPG: 0-31  AVI: 1-99]
+.TP
+.B \-vid\ id
+select video channel [MPG: 0-15  AVI:  -- ]
+.TP
+.B \-fps\ value
+force frame rate (if value is wrong in the header)
+.TP
+.B \-mc\ seconds/5frame
+maximum sync correction per 5 frames (in seconds)
+.TP
+.B \-ni
+force usage of non-interleaved AVI parser
+.IP
+.SH "ALPHA/BETA CODE"
+.TP
+.I NOTE
+These are included in this manpage just for completeness! If you don't
+know what are these, you DON'T need these! In either case, double-check DOCS!
+.TP
+.B \-br\ rate
+used with '-vo odivx' .
+Specifies the bitrate to encode OpenDivx at
+(in bits! e.g: 780000).
+.TP
+.B \-encode\ file
+used with '-vo odivx' .
+Specifies the output OpenDivX file. Won't overwrite.
+.IP
+.SH "EXAMPLES"
+Just launch it! :)
+.LP
+.SH BUGS
+Possibly. Check DOCS.
+
+Bugreports should be addressed to the MPlayer-users mailing list
+(mplayer@alan.umcs.lublin.pl) ! If you want to submit a bugreport
+(which we love to receive!), please double-check the README, and
+tell us all that we need to know to identify your problem.
+
+.LP
+.SH AUTHORS
+Check DOCS/AUTHORS !
+
+MPlayer is (C) 2000-2001
+.I Arpad Gereoffy <arpi@thot.banki.hu>
+
+This manpage is maintained by
+.I Gabucino.
+.LP
+.SH STANDARD DISCLAIMER
+Use only at your own risk! There may be errors and inaccuracies that could 
+be damaging to your system or your eye. Proceed with caution, and although
+this is highly unlikely, the author doesn't take any responsibility for that!
+.\" end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,82 @@
+# LINUX Makefile made by A'rpi / Astral
+# Some cleanup by LGB: 	* 'make -C dir' instead of 'cd dir;make;cd..'
+#			* for loops instead of linear sequence of make directories
+#			* some minor problems with make clean and distclean were corrected
+
+include config.mak
+
+PRG = mplayer
+PRG_AVIP = aviparse
+PRG_TV = tvision
+prefix = /usr/local
+BINDIR = ${prefix}/bin
+# BINDIR = /usr/local/bin
+SRCS = linux/getch2.c linux/timer-lx.c linux/shmem.c xa/xa_gsm.c lirc_mp.c
+OBJS = linux/getch2.o linux/timer-lx.o linux/shmem.o xa/xa_gsm.o lirc_mp.o
+CFLAGS = $(OPTFLAGS) -Iloader -Ilibvo # -Wall
+A_LIBS = -Lmp3lib -lMP3 -Llibac3 -lac3
+VO_LIBS = -Llibvo -lvo $(X_LIBS)
+
+.SUFFIXES: .c .o
+
+# .PHONY: all clean
+
+all:	$(PRG)
+# $(PRG_AVIP)
+
+.c.o:
+	$(CC) -c $(CFLAGS) -o $@ $<
+
+COMMONLIBS = libvo/libvo.a libac3/libac3.a mp3lib/libMP3.a
+
+loader/libloader.a:
+	$(MAKE) -C loader
+
+libmpeg2/libmpeg2.a:
+	$(MAKE) -C libmpeg2
+
+libvo/libvo.a:
+	$(MAKE) -C libvo
+
+libac3/libac3.a:
+	$(MAKE) -C libac3
+
+mp3lib/libMP3.a:
+	$(MAKE) -C mp3lib
+
+opendivx/libdecore.a:
+	$(MAKE) -C opendivx
+
+encore/libencore.a:
+	$(MAKE) -C encore
+
+$(PRG):	mplayer.o $(OBJS) loader/libloader.a libmpeg2/libmpeg2.a opendivx/libdecore.a $(COMMONLIBS) encore/libencore.a
+	$(CC) $(CFLAGS) -o $(PRG) mplayer.o $(OBJS) $(XMM_LIBS) $(LIRC_LIBS) $(A_LIBS) -lm $(TERMCAP_LIB) -Lloader -lloader -ldl -Llibmpeg2 -lmpeg2 -Lopendivx -ldecore $(VO_LIBS) -Lencore -lencore -lpthread
+
+$(PRG_AVIP):	aviparse.o $(OBJS) loader/libloader.a $(COMMONLIBS)
+	$(CC) $(CFLAGS) -o $(PRG_AVIP) aviparse.o $(OBJS) $(A_LIBS) -lm $(TERMCAP_LIB) -Lloader -lloader -ldl $(VO_LIBS) -lpthread
+
+$(PRG_TV):	tvision.o $(OBJS) $(COMMONLIBS)
+	$(CC) $(CFLAGS) -o $(PRG_TV) tvision.o $(OBJS) -lm $(TERMCAP_LIB) $(VO_LIBS)
+
+install: $(PRG)
+	strip $(PRG)
+	cp $(PRG) $(BINDIR)
+	install -m 644 DOCS/mplayer.1 $(prefix)/man/man1/mplayer.1
+
+clean:
+	rm -f *.o *~ $(OBJS)
+
+distclean:
+	@for a in mp3lib libac3 libmpeg2 opendivx encore libvo loader drivers drivers/syncfb ; do $(MAKE) -C $$a distclean ; done
+	makedepend
+	rm -f *~ $(PRG) $(PRG_AVIP) $(PRG_TV) $(OBJS) *.o *.a Makefile.bak
+
+dep:	depend
+
+depend:
+	@for a in mp3lib libac3 libmpeg2 libvo opendivx encore ; do $(MAKE) -C $$a dep ; done
+#	cd loader;make dep;cd ..
+	makedepend -- $(CFLAGS) -- mplayer.c aviparse.c tvision.c $(SRCS) &>/dev/null
+
+# DO NOT DELETE
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TOOLS/GL-test/compile.sh	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,2 @@
+
+gcc -g -O4 gltest.c ../../linux/timer-lx.o -o gltest -L/usr/X11/lib -lglut -lGL -lGLU -lX11 -lXext -lXmu -lXi -lm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TOOLS/GL-test/gltest.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,189 @@
+// OpenGL glTexSubImage() test/benchmark prg  (C) 2001. by A'rpi/ESP-team
+
+#include <GL/glut.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <inttypes.h>
+
+// pixel size:  3 or 4
+#define BYTES_PP 3
+
+// blit by lines (defined) or frames (not defined)
+#define FAST_BLIT
+
+static uint32_t image_width=720;        // DVD size
+static uint32_t image_height=576;
+
+static uint32_t image_format;
+static uint32_t image_bpp;
+static uint32_t image_bytes;
+
+static uint32_t texture_width=512;
+static uint32_t texture_height=512;
+
+static unsigned char *ImageData=NULL;
+
+static GLvoid resize(int x,int y){
+  printf("Resize: %dx%d\n",x,y);
+  glViewport( 0, 0, x, y );
+
+  glMatrixMode(GL_PROJECTION);
+  glLoadIdentity();
+  glOrtho(0, image_width, image_height, 0, -1,1);
+
+  glMatrixMode(GL_MODELVIEW);
+  glLoadIdentity();
+}
+
+float akarmi=0;
+
+int counter=0;
+float gen_time=0;
+float up_time=0;
+float render_time=0;
+
+unsigned char sintable[4096];
+
+extern float GetRelativeTime();
+
+static void redraw(void)
+{
+//  glClear(GL_COLOR_BUFFER_BIT);
+  int x,y,i;
+  unsigned char *d=ImageData;
+  int dstride=BYTES_PP*image_width;
+  
+  GetRelativeTime();
+  
+  // generate some image:
+  for(y=0;y<image_height;y++){
+    int y1=2048*sin(akarmi*0.36725+y*0.0165);
+    int y2=2048*sin(akarmi*0.45621+y*0.02753);
+    int y3=2048*sin(akarmi*0.15643+y*0.03732);
+    for(x=0;x<image_width;x++){
+      d[0]=sintable[(y1+x*135)&4095];
+      d[1]=sintable[(y2+x*62)&4095];
+      d[2]=sintable[(y3+x*23)&4095];
+      d+=BYTES_PP;
+    }
+  }
+  
+  gen_time+=GetRelativeTime();
+
+#ifdef FAST_BLIT
+  // upload texture:
+    for(i=0;i<image_height;i++){
+      glTexSubImage2D( GL_TEXTURE_2D,  // target
+		       0,              // level
+		       0,              // x offset
+		       i,            // y offset
+		       image_width,              // width
+		       1,              // height
+		       (BYTES_PP==4)?GL_RGBA:GL_RGB,        // format
+		       GL_UNSIGNED_BYTE, // type
+		       ImageData+i*dstride );        // *pixels
+    }
+#else
+      glTexSubImage2D( GL_TEXTURE_2D,  // target
+		       0,              // level
+		       0,              // x offset
+		       0,            // y offset
+		       image_width,              // width
+		       image_height,              // height
+		       (BYTES_PP==4)?GL_RGBA:GL_RGB,        // format
+		       GL_UNSIGNED_BYTE, // type
+		       ImageData );        // *pixels
+#endif
+
+  up_time+=GetRelativeTime();
+
+  glColor3f(1,1,1);
+  glBegin(GL_QUADS);
+    glTexCoord2f(0,0);glVertex2i(0,0);
+    glTexCoord2f(0,1);glVertex2i(0,texture_height);
+    glTexCoord2f(1,1);glVertex2i(texture_width,texture_height);
+    glTexCoord2f(1,0);glVertex2i(texture_width,0);
+  glEnd();
+  
+  glFinish();
+  glutSwapBuffers();
+
+  render_time+=GetRelativeTime();
+
+  ++counter;
+  { float total=gen_time+up_time+render_time;
+    if(total>2.0){
+    printf("%8.3f fps  (gen: %2d%%  upload: %2d%%  render: %2d%%)\n",
+       (float)counter/total,
+       (int)(100.0*gen_time/total),
+       (int)(100.0*up_time/total),
+       (int)(100.0*render_time/total)
+    );
+    gen_time=up_time=render_time=0;
+    counter=0;
+  } }
+
+}
+
+static GLvoid IdleFunc(){
+  akarmi+=0.1;
+  glutPostRedisplay();
+}
+
+int
+main(int argc, char **argv)
+{
+  int i;
+  
+  glutInit(&argc, argv);
+  glutInitWindowSize(640, 480);
+  glutInitDisplayMode(GLUT_DOUBLE);
+  (void) glutCreateWindow("csg");
+
+  glutDisplayFunc(redraw);
+  glutReshapeFunc(resize);
+  glutIdleFunc(IdleFunc);
+
+  texture_width=32;
+  while(texture_width<image_width) texture_width*=2;
+  while(texture_width<image_height) texture_width*=2;
+  texture_height=texture_width;
+
+    image_bpp=8*BYTES_PP;
+    image_bytes=BYTES_PP;
+
+  ImageData=malloc(texture_width*texture_height*image_bytes);
+  memset(ImageData,128,texture_width*texture_height*image_bytes);
+
+  glDisable(GL_BLEND); 
+  glDisable(GL_DEPTH_TEST);
+  glDepthMask(GL_FALSE);
+  glDisable(GL_CULL_FACE);
+
+  glEnable(GL_TEXTURE_2D);
+
+  printf("Creating %dx%d texture...\n",texture_width,texture_height);
+
+#if 1
+//  glBindTexture(GL_TEXTURE_2D, texture_id);
+  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+#ifdef TEXTUREFORMAT_32BPP
+  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, texture_width, texture_height, 0,
+#else
+  glTexImage2D(GL_TEXTURE_2D, 0, BYTES_PP, texture_width, texture_height, 0,
+#endif
+       (image_bytes==4)?GL_RGBA:GL_BGR, GL_UNSIGNED_BYTE, ImageData);
+#endif
+
+  resize(640,480);
+
+  glClearColor( 1.0f,0.0f,1.0f,0.0f );
+  glClear( GL_COLOR_BUFFER_BIT );
+  
+  for(i=0;i<4096;i++) sintable[i]=128+127*sin(2.0*3.14159265*i/4096.0);
+
+  glutMainLoop();
+  return 0;             /* ANSI C requires main to return int. */
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TOOLS/asfinfo.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,255 @@
+#define SAVE_STREAMS
+
+// simple ASF header display program by A'rpi/ESP-team
+// .asf fileformat docs from http://divx.euro.ru
+
+#include <stdio.h>
+#include <stdlib.h>
+
+typedef struct __attribute__((packed)) 
+{
+    long        biSize; // sizeof(BITMAPINFOHEADER)
+    long        biWidth;
+    long        biHeight;
+    short       biPlanes; // unused
+    short       biBitCount;
+    long        biCompression; // fourcc of image
+    long        biSizeImage;   // size of image. For uncompressed images
+                               // ( biCompression 0 or 3 ) can be zero.
+
+
+    long        biXPelsPerMeter; // unused
+    long        biYPelsPerMeter; // unused
+    long        biClrUsed;     // valid only for palettized images.
+                               // Number of colors in palette.
+    long        biClrImportant;
+} BITMAPINFOHEADER;
+
+typedef struct
+{
+  short   wFormatTag; // value that identifies compression format
+  short   nChannels;
+  long  nSamplesPerSec;
+  long  nAvgBytesPerSec;
+  short   nBlockAlign; // size of a data sample
+  short   wBitsPerSample;
+  short   cbSize;    // size of format-specific data
+} WAVEFORMATEX;
+
+typedef struct __attribute__((packed)) {
+  unsigned char guid[16];
+  unsigned long long size;
+} ASF_obj_header_t;
+
+typedef struct __attribute__((packed)) {
+  ASF_obj_header_t objh;
+  unsigned int cno; // number of subchunks
+  unsigned char v1; // unknown (0x01)
+  unsigned char v2; // unknown (0x02)
+} ASF_header_t;
+
+typedef struct __attribute__((packed)) {
+  unsigned char client[16]; // Client GUID
+  unsigned long long file_size;
+  unsigned long long creat_time; //File creation time FILETIME 8
+  unsigned long long packets;    //Number of packets UINT64 8
+  unsigned long long end_timestamp; //Timestamp of the end position UINT64 8
+  unsigned long long duration;  //Duration of the playback UINT64 8
+  unsigned long start_timestamp; //Timestamp of the start position UINT32 4
+  unsigned long unk1; //Unknown, maybe reserved ( usually contains 0 ) UINT32 4
+  unsigned long flags; //Unknown, maybe flags ( usually contains 2 ) UINT32 4
+  unsigned long packetsize; //Size of packet, in bytes UINT32 4
+  unsigned long packetsize2; //Size of packet ( confirm ) UINT32 4
+  unsigned long frame_size; //Size of uncompressed video frame UINT32 4
+} ASF_file_header_t;
+
+typedef struct __attribute__((packed)) {
+  unsigned char type[16]; // Stream type (audio/video) GUID 16
+  unsigned char concealment[16]; // Audio error concealment type GUID 16
+  unsigned long long unk1; // Unknown, maybe reserved ( usually contains 0 ) UINT64 8
+  unsigned long type_size; //Total size of type-specific data UINT32 4
+  unsigned long stream_size; //Size of stream-specific data UINT32 4
+  unsigned short stream_no; //Stream number UINT16 2
+  unsigned long unk2; //Unknown UINT32 4
+} ASF_stream_header_t;
+
+typedef struct __attribute__((packed)) {
+  unsigned char streamno;
+  unsigned char seq;
+  unsigned long x;
+  unsigned char flag;
+} ASF_segmhdr_t;
+
+
+ASF_header_t asfh;
+ASF_obj_header_t objh;
+ASF_file_header_t fileh;
+ASF_stream_header_t streamh;
+unsigned char buffer[8192];
+
+int i;
+
+char* chunk_type(unsigned char* guid){
+  switch(*((unsigned int*)guid)){
+    case 0xF8699E40: return "guid_audio_stream";
+    case 0xBC19EFC0: return "guid_video_stream";
+    case 0x49f1a440: return "guid_audio_conceal_none";
+    case 0xbfc3cd50: return "guid_audio_conceal_interleave";
+    case 0x75B22630: return "guid_header";
+    case 0x75b22636: return "guid_data_chunk";
+    case 0x33000890: return "guid_index_chunk";
+    case 0xB7DC0791: return "guid_stream_header";
+    case 0xD6E229D1: return "guid_header_2_0";
+    case 0x8CABDCA1: return "guid_file_header";
+  }
+  return NULL;
+}
+
+void print_wave_header(WAVEFORMATEX *h){
+
+  printf("======= WAVE Format =======\n");
+  
+  printf("Format Tag: %d (0x%X)\n",h->wFormatTag,h->wFormatTag);
+  printf("Channels: %d\n",h->nChannels);
+  printf("Samplerate: %d\n",h->nSamplesPerSec);
+  printf("avg byte/sec: %d\n",h->nAvgBytesPerSec);
+  printf("Block align: %d\n",h->nBlockAlign);
+  printf("bits/sample: %d\n",h->wBitsPerSample);
+  printf("cbSize: %d\n",h->cbSize);
+  
+  switch(h->wFormatTag){
+      case 0x01:        printf("Audio in PCM format\n");break;
+      case 0x50:        printf("Audio in MPEG Layer 1/2 format\n");break;
+      case 0x55:        printf("Audio in MPEG Layer-3 format\n");break; // ACM
+      case 0x02:        printf("Audio in MS ADPCM format\n");break;  // ACM
+      case 0x11:        printf("Audio in IMA ADPCM format\n");break; // ACM
+      case 0x31:
+      case 0x32:        printf("Audio in MS GSM 6.10 format\n");break; // ACM
+      case 0x160:
+      case 0x161:       printf("Audio in DivX WMA format\n");break; // ACM
+      default:          printf("Audio in UNKNOWN (id=0x%X) format\n",h->wFormatTag);
+  }
+
+  printf("===========================\n");
+  
+
+}
+
+void print_video_header(BITMAPINFOHEADER *h){
+  printf("======= VIDEO Format ======\n");
+	printf("  biSize %d\n", h->biSize);
+	printf("  biWidth %d\n", h->biWidth);
+	printf("  biHeight %d\n", h->biHeight);
+	printf("  biPlanes %d\n", h->biPlanes);
+	printf("  biBitCount %d\n", h->biBitCount);
+	printf("  biCompression %d='%.4s'\n", h->biCompression, &h->biCompression);
+	printf("  biSizeImage %d\n", h->biSizeImage);
+  printf("===========================\n");
+}
+
+FILE* streams[128];
+
+int main(int argc,char* argv[]){
+FILE *f=fopen(argc>1?argv[1]:"Alice Deejay - Back In My Life.asf","rb");
+
+if(!f){ printf("file not found\n");exit(1);}
+
+//printf("sizeof=%d\n",sizeof(objh));
+//printf("sizeof=%d\n",sizeof(asfh));
+
+fread(&asfh,sizeof(asfh),1,f); // header obj
+//for(i=0;i<16;i++) printf("%02X ",asfh.objh.guid[i]);
+printf("[%s] %d  (subchunks: %d)\n",chunk_type(asfh.objh.guid),(int) asfh.objh.size,asfh.cno);
+
+while(fread(&objh,sizeof(objh),1,f)>0){
+  int pos=ftell(f);
+//  for(i=0;i<16;i++) printf("%02X ",objh.guid[i]);
+  printf("0x%08X  [%s] %d\n",pos-sizeof(objh), chunk_type(objh.guid),(int) objh.size);
+  switch(*((unsigned int*)&objh.guid)){
+    case 0xB7DC0791: // guid_stream_header
+      fread(&streamh,sizeof(streamh),1,f);
+      printf("stream type: %s\n",chunk_type(streamh.type));
+      printf("stream concealment: %s\n",chunk_type(streamh.concealment));
+      printf("type: %d bytes,  stream: %d bytes  ID: %d\n",(int)streamh.type_size,(int)streamh.stream_size,(int)streamh.stream_no);
+      printf("FILEPOS=0x%X\n",ftell(f));
+      // type-specific data:
+      fread(buffer,streamh.type_size,1,f);
+      switch(*((unsigned int*)&streamh.type)){
+      case 0xF8699E40:  // guid_audio_stream
+        print_wave_header((WAVEFORMATEX*)buffer);
+        break;
+      case 0xBC19EFC0:  // guid_video_stream
+        print_video_header((BITMAPINFOHEADER*)&buffer[4+4+1+2]);
+        break;
+      }
+      // stream-specific data:
+      fread(buffer,streamh.stream_size,1,f);
+      break;
+//    case 0xD6E229D1: return "guid_header_2_0";
+    case 0x8CABDCA1: // guid_file_header
+      fread(&fileh,sizeof(fileh),1,f);
+      printf("packets: %d  flags: %d  pack_size: %d  frame_size: %d\n",(int)fileh.packets,(int)fileh.flags,(int)fileh.packetsize,(int)fileh.frame_size);
+      break;
+    case 0x75b22636: // guid_data_chunk
+      { int endp=pos+objh.size-sizeof(objh);
+        unsigned char* packet=malloc((int)fileh.packetsize);
+        int fpos;
+        fseek(f,26,SEEK_CUR);
+        while((fpos=ftell(f))<endp){
+          fread(packet,(int)fileh.packetsize,1,f);
+          if(packet[0]==0x82){
+            unsigned char flags=packet[3];
+            unsigned char* p=&packet[5];
+            unsigned long time;
+            unsigned short duration;
+            int segs=1;
+            int seg;
+            int padding=0;
+            if(flags&8){
+              padding=p[0];++p;
+            } else
+            if(flags&16){
+              padding=p[0]|(p[1]<<8);p+=2;
+            }
+            time=*((unsigned long*)p);p+=4;
+            duration=*((unsigned short*)p);p+=2;
+            if(flags&1){
+              segs=p[0]-0x80;++p;
+            }
+            printf("%08X:  flag=%02X  segs=%d  pad=%d  time=%d  dur=%d\n",
+              fpos,flags,segs,padding,time,duration);
+            for(seg=0;seg<segs;seg++){
+              ASF_segmhdr_t* sh=(ASF_segmhdr_t*)p;
+              int len=0;
+              p+=sizeof(ASF_segmhdr_t);
+              if(sh->flag&8) p+=8;// else
+              if(sh->flag&1) ++p;
+              if(flags&1){
+                len=*((unsigned short*)p);p+=2;
+              }
+              printf("  seg #%d: streamno=%d  seq=%d  flag=%02X  len=%d\n",seg,sh->streamno&0x7F,sh->seq,sh->flag,len);
+#ifdef SAVE_STREAMS
+              if(!streams[sh->streamno&0x7F]){
+                char name[256];
+                sprintf(name,"stream%02X.dat",sh->streamno&0x7F);
+                streams[sh->streamno&0x7F]=fopen(name,"wb");
+              }
+              fwrite(p,len,1,streams[sh->streamno&0x7F]);
+#endif
+              p+=len;
+            }
+          } else
+            printf("%08X:  UNKNOWN  %02X %02X %02X %02X %02X...\n",fpos,packet[0],packet[1],packet[2],packet[3],packet[4]);
+        }
+      }
+      break;
+
+//    case 0x33000890: return "guid_index_chunk";
+
+  }
+  fseek(f,pos+objh.size-sizeof(objh),SEEK_SET);
+}
+
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TOOLS/c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,1 @@
+gcc movinfo.c -o movinfo
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TOOLS/movinfo.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,124 @@
+// show QuickTime .mov file structure     (C) 2001. by A'rpi/ESP-team
+
+#include <stdio.h>
+#include <stdlib.h>
+
+unsigned int read_dword(FILE *f){
+ unsigned char atom_size_b[4];
+ if(fread(&atom_size_b,4,1,f)<=0) return -1;
+ return (atom_size_b[0]<<24)|(atom_size_b[1]<<16)|(atom_size_b[2]<<8)|atom_size_b[3];
+}
+
+void lschunks(FILE *f,int level,unsigned int endpos){
+ unsigned int atom_size;
+ unsigned int atom_type;
+ int pos;
+ while(endpos==0 || ftell(f)<endpos){
+  pos=ftell(f);
+  atom_size=read_dword(f);//  if(fread(&atom_size_b,4,1,f)<=0) break;
+  if(fread(&atom_type,4,1,f)<=0) break;
+  
+  if(atom_size<8) break; // error
+  
+  printf("%08X:  %*s %.4s (%08X) %d\n",pos,level*2,"",&atom_type,atom_type,atom_size);
+  
+  if(atom_type==0x64737473) {  // stsd
+    unsigned int tmp;
+    unsigned int count;
+    int i;
+    fread(&tmp,4,1,f);
+    count=read_dword(f);//    fread(&count,4,1,f);
+    printf("desc count = %d\n",count);
+    for(i=0;i<count;i++){
+      unsigned int len;
+      unsigned int format;
+      len=read_dword(f); //      fread(&len,4,1,f);
+      fread(&format,4,1,f);
+      printf("  desc #%d: %.4s  (%d)\n",i+1,&format,len);
+      fseek(f,len-8,SEEK_CUR);
+    }
+  }
+  
+  if(atom_type==0x6F637473) {  // stco
+    int len,i;
+    read_dword(f);
+    len=read_dword(f);
+    printf("Chunk table size :%d\n",len);
+    for(i=0;i<len;i++) printf("  chunk #%d: 0x%X\n",i+1,read_dword(f));
+  }
+
+
+  if(atom_type==0x73747473) {  // stts
+    int len,i;
+    read_dword(f);
+    len=read_dword(f);
+    printf("T->S table size :%d\n",len);
+    for(i=0;i<len;i++){
+      int num=read_dword(f);
+      int dur=read_dword(f);
+      printf("%5d samples: %d duration\n",num,dur);
+    }
+  }
+
+  if(atom_type==0x63737473) {  // stsc
+    int len,i;
+    read_dword(f);
+    len=read_dword(f);
+    printf("S->C table size :%d\n",len);
+    for(i=0;i<len;i++){
+      int first=read_dword(f);
+      int spc=read_dword(f);
+      int sdid=read_dword(f);
+      printf("  chunk %d...  %d s/c   desc: %d\n",first,spc,sdid);
+    }
+  }
+
+  if(atom_type==0x7A737473) {  // stsz
+    int len,i,ss;
+    read_dword(f);
+    ss=read_dword(f);
+    len=read_dword(f);
+    printf("Sample size table len: %d\n",len);
+    if(ss){
+      printf("  common sample size: %d bytes\n",ss);
+    } else {
+      for(i=0;i<len;i++) printf("  sample #%d: %d bytes\n",i+1,read_dword(f));
+    }
+  }
+
+  
+#if 1
+  switch(atom_type){
+  case 0x75716D72: // rmqu
+  case 0x65657266: // free  JUNK
+  case 0x64686B74: // tkhd  Track header
+  case 0x61746475: // udta  User data
+  case 0x7461646D: // mdat  Movie data
+  case 0x64737473: // stsd  Sample description
+  case 0x6F637473: // stco  Chunk offset table
+  case 0x73747473: // stts  Sample time table
+  case 0x63737473: // stsc  Sample->Chunk mapping table
+  case 0x7A737473: // stsz  Sample size table
+      break;
+  default: lschunks(f,level+1,pos+atom_size);
+  }
+#else
+  switch(atom_type){
+  case 0x766F6F6D: // moov
+  case 0x61726D72: // rmra
+  case 0x61646D72: // rmda
+    lschunks(f,level+1,pos+atom_size);
+  }
+#endif
+  fseek(f,pos+atom_size,SEEK_SET);
+ }
+}
+
+int main(int argc,char* argv[]){
+int pos;
+FILE *f=fopen(argc>1?argv[1]:"Akira.mov","rb");
+if(!f) return 1;
+
+lschunks(f,0,0);
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/Mon-640x400	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,3 @@
+
+fbset/fbset -fb /dev/fb1 -db fbset.db 640x400-60
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/Mon-640x480	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,3 @@
+
+fbset/fbset -fb /dev/fb1 -db fbset.db 640x480-60
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/TV-640x512	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,2 @@
+
+fbset/fbset -fb /dev/fb0 -left 60 -right 0 -upper 70 -lower 39 -hslen 76 -vslen 4 -xres 640 -yres 512 -bcast true
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/TV-640x528	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,3 @@
+
+fbset/fbset -fb /dev/fb0 -left 40 -right 0 -upper 63 -lower 29 -hslen 56 -vslen 4 -xres 640 -yres 528 -vxres 640 -vyres 528 -depth 32 -laced false -bcast true
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/TV-704x528	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,3 @@
+
+fbset/fbset -fb /dev/fb0 -left 40 -right 0 -upper 63 -lower 29 -hslen 56 -vslen 4 -xres 640 -yres 528 -vxres 704 -vyres 528 -depth 32 -laced false -bcast true
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/TV-704x576	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,3 @@
+
+fbset/fbset -fb /dev/fb0 -left 42 -right 0 -upper 29 -lower 20 -hslen 46 -vslen 4 -xres 704 -yres 576 -vxres 704 -vyres 576 -depth 32 -laced false -bcast true
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/TV-720x576	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,3 @@
+
+fbset/fbset -fb /dev/fb0 -left 18 -right 0 -upper 39 -lower 10 -hslen 46 -vslen 4 -xres 720 -yres 576 -vxres 720 -vyres 576 -depth 32 -laced false -bcast true
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/clean.sh	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,13 @@
+
+# Compile TVout tools
+
+rm -f con2fb/con2fb
+
+cd matroxset
+make clean
+cd ..
+
+cd fbset
+make clean
+cd ..
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/cloning	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,14 @@
+
+# SETUP TVout
+# Same picture on TV & Monitor
+
+# CRTC1 -> TVout & Monitor
+matroxset/matroxset -f /dev/fb1 -m 0
+matroxset/matroxset -f /dev/fb0 -m 3
+
+# Enable TV
+matroxset/matroxset 1
+
+# Keep consoles on CRTC1
+con2fb/con2fb /dev/fb0 /dev/tty1
+con2fb/con2fb /dev/fb0 /dev/tty2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/compile.sh	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,15 @@
+
+# Compile TVout tools
+
+cd con2fb
+gcc con2fb.c -o con2fb
+cd ..
+
+cd matroxset
+make
+cd ..
+
+cd fbset
+make
+cd ..
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/con2fb/con2fb.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,79 @@
+/* this is userspace utility which allows you to redirect console to another fb device 
+ * You can specify devices & consoles by both numbers and devices. Framebuffers numbers
+ * are zero based (/dev/fb0 ... ), consoles begins with 1 (/dev/tty1 ... )
+ */
+#include <linux/fb.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int main(int argc, char* argv[]) {
+	struct fb_con2fbmap c2m;
+	char* fbPath;
+	u_int32_t con, fb;
+	char* e;
+	char* progname = strrchr(argv[0], '/');
+	int f;
+
+	if (progname)
+		progname++;
+	else
+		progname = argv[0];
+	if (argc < 3) {
+		fprintf(stderr, "usage: %s fbdev console\n", progname);
+		return 1;
+	}
+	fb = strtoul(argv[1], &e, 10);
+	if (*e) {
+		struct stat sbf;
+
+		if (stat(argv[1], &sbf)) {	
+			fprintf(stderr, "%s: are you sure that %s can be used to describe fbdev?\n", progname, argv[1]);
+			return 1;
+		}
+		if (!S_ISCHR(sbf.st_mode)) {
+			fprintf(stderr, "%s: %s must be character device\n", progname, argv[1]);
+			return 1;
+		}
+		fb = sbf.st_rdev & 0xFF;
+		if (fb >= 32)
+			fb >>= 5;
+		fbPath = argv[1];
+	} else 
+		fbPath = "/dev/fb0";
+	con = strtoul(argv[2], &e, 10);
+	if (*e) {
+		struct stat sbf;
+
+		if (stat(argv[2], &sbf)) {
+			fprintf(stderr, "%s: are you sure that %s can be used to describe vt?\n", progname, argv[2]);
+			return 1;
+		}
+		if (!S_ISCHR(sbf.st_mode)) {
+			fprintf(stderr, "%s: %s must be character device\n", progname, argv[2]);
+			return 1;
+		}
+		con = sbf.st_rdev & 0xFF;
+	}
+	c2m.console = con;
+	c2m.framebuffer = fb;
+	f = open(fbPath, O_RDWR);
+	if (f < 0) {
+		fprintf(stderr, "%s: Cannot open %s\n", progname, fbPath);
+		return 1;
+	}
+	if (ioctl(f, FBIOPUT_CON2FBMAP, &c2m)) {
+		fprintf(stderr, "%s: Cannot set console mapping\n", progname);
+		close(f);
+		return 1;
+	}
+	close(f);
+	return 0;
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/fbset.db	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,34 @@
+
+# FBset mode database
+
+mode "640x480"                         # H: 33.78 kHz, V: 67.56 Hz
+   geometry 640 480 640 480 4
+   timings 35242 24 64 17 1 112 2
+endmode
+
+mode "640x480-60"
+    # D: 25.176 MHz, H: 31.469 kHz, V: 59.942 Hz
+    geometry 640 480 640 480 16
+    timings 39721 48 16 33 10 96 2
+    hsync high
+    accel true
+#    rgba 5/11,6/5,5/0,0/0
+endmode
+
+mode "640x400-60"
+    # D: 25.176 MHz, H: 31.469 kHz, V: 59.942 Hz
+    geometry 640 400 640 400 16
+    timings 39721 48 16 33 10 96 2
+    hsync high
+    accel true
+#    rgba 5/11,6/5,5/0,0/0
+endmode
+
+mode "vga70"
+    # H: 31.113 kHz, V: 69.294 Hz
+    geometry 640 400 640 400 4
+    timings 35242 64 96 35 12 112 2
+#    vsync high
+#    csync high
+endmode
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/fbset/INSTALL	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,20 @@
+
+
+			FBSET INSTALLATION GUIDE
+
+
+Change the current directory to the directory containing the fbset sources and
+type
+
+    make install
+
+This will create the fbset binary and install it, together with the manual
+pages. It also creates the standard frame buffer special device nodes.
+
+
+The etc subdirectory contains sample frame buffer mode definitions files. Copy
+one of them to /etc/fb.modes and edit it to your needs.
+
+
+Enjoy!
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/fbset/Makefile	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,41 @@
+#
+# Linux Frame Buffer Device Configuration
+#
+
+CC =		gcc -Wall -O2 -I.
+BISON =		bison -d
+FLEX =		flex
+INSTALL =	install
+RM =		rm -f
+
+All:		fbset
+
+
+fbset:		fbset.o modes.tab.o lex.yy.o
+
+fbset.o:	fbset.c fbset.h fb.h
+modes.tab.o:	modes.tab.c fbset.h fb.h
+lex.yy.o:	lex.yy.c fbset.h modes.tab.h
+
+lex.yy.c:	modes.l
+		$(FLEX) modes.l
+
+modes.tab.c:	modes.y
+		$(BISON) modes.y
+
+install:	fbset
+		if [ -f /sbin/fbset ]; then rm /sbin/fbset; fi
+		$(INSTALL) fbset /usr/sbin
+		$(INSTALL) fbset.8 /usr/man/man8
+		$(INSTALL) fb.modes.5 /usr/man/man5
+		if [ ! -c /dev/fb0 ]; then mknod /dev/fb0 c 29 0; fi
+		if [ ! -c /dev/fb1 ]; then mknod /dev/fb1 c 29 32; fi
+		if [ ! -c /dev/fb2 ]; then mknod /dev/fb2 c 29 64; fi
+		if [ ! -c /dev/fb3 ]; then mknod /dev/fb3 c 29 96; fi
+		if [ ! -c /dev/fb4 ]; then mknod /dev/fb4 c 29 128; fi
+		if [ ! -c /dev/fb5 ]; then mknod /dev/fb5 c 29 160; fi
+		if [ ! -c /dev/fb6 ]; then mknod /dev/fb6 c 29 192; fi
+		if [ ! -c /dev/fb7 ]; then mknod /dev/fb7 c 29 224; fi
+
+clean:
+		$(RM) *.o fbset lex.yy.c modes.tab.c modes.tab.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/fbset/fb.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,497 @@
+#ifndef _LINUX_FB_H
+#define _LINUX_FB_H
+
+#include <asm/types.h>
+
+/* Definitions of frame buffers						*/
+
+#define FB_MAJOR	29
+
+#define FB_MODES_SHIFT		5	/* 32 modes per framebuffer */
+#define FB_NUM_MINORS		256	/* 256 Minors               */
+#define FB_MAX			(FB_NUM_MINORS / (1 << FB_MODES_SHIFT))
+#define GET_FB_IDX(node)	(MINOR(node) >> FB_MODES_SHIFT)
+
+/* ioctls
+   0x46 is 'F'								*/
+#define FBIOGET_VSCREENINFO	0x4600
+#define FBIOPUT_VSCREENINFO	0x4601
+#define FBIOGET_FSCREENINFO	0x4602
+#define FBIOGETCMAP		0x4604
+#define FBIOPUTCMAP		0x4605
+#define FBIOPAN_DISPLAY		0x4606
+/* 0x4607-0x460B are defined below */
+/* #define FBIOGET_MONITORSPEC	0x460C */
+/* #define FBIOPUT_MONITORSPEC	0x460D */
+/* #define FBIOSWITCH_MONIBIT	0x460E */
+#define FBIOGET_CON2FBMAP	0x460F
+#define FBIOPUT_CON2FBMAP	0x4610
+
+#define FB_TYPE_PACKED_PIXELS		0	/* Packed Pixels	*/
+#define FB_TYPE_PLANES			1	/* Non interleaved planes */
+#define FB_TYPE_INTERLEAVED_PLANES	2	/* Interleaved planes	*/
+#define FB_TYPE_TEXT			3	/* Text/attributes	*/
+#define FB_TYPE_VGA_PLANES		4	/* EGA/VGA planes	*/
+
+#define FB_AUX_TEXT_MDA		0	/* Monochrome text */
+#define FB_AUX_TEXT_CGA		1	/* CGA/EGA/VGA Color text */
+#define FB_AUX_TEXT_S3_MMIO	2	/* S3 MMIO fasttext */
+#define FB_AUX_TEXT_MGA_STEP16	3	/* MGA Millenium I: text, attr, 14 reserved bytes */
+#define FB_AUX_TEXT_MGA_STEP8	4	/* other MGAs:      text, attr,  6 reserved bytes */
+
+#define FB_AUX_VGA_PLANES_VGA4		0	/* 16 color planes (EGA/VGA) */
+#define FB_AUX_VGA_PLANES_CFB4		1	/* CFB4 in planes (VGA) */
+#define FB_AUX_VGA_PLANES_CFB8		2	/* CFB8 in planes (VGA) */
+
+#define FB_VISUAL_MONO01		0	/* Monochr. 1=Black 0=White */
+#define FB_VISUAL_MONO10		1	/* Monochr. 1=White 0=Black */
+#define FB_VISUAL_TRUECOLOR		2	/* True color	*/
+#define FB_VISUAL_PSEUDOCOLOR		3	/* Pseudo color (like atari) */
+#define FB_VISUAL_DIRECTCOLOR		4	/* Direct color */
+#define FB_VISUAL_STATIC_PSEUDOCOLOR	5	/* Pseudo color readonly */
+
+#define FB_ACCEL_NONE		0	/* no hardware accelerator	*/
+#define FB_ACCEL_ATARIBLITT	1	/* Atari Blitter		*/
+#define FB_ACCEL_AMIGABLITT	2	/* Amiga Blitter                */
+#define FB_ACCEL_S3_TRIO64	3	/* Cybervision64 (S3 Trio64)    */
+#define FB_ACCEL_NCR_77C32BLT	4	/* RetinaZ3 (NCR 77C32BLT)      */
+#define FB_ACCEL_S3_VIRGE	5	/* Cybervision64/3D (S3 ViRGE)	*/
+#define FB_ACCEL_ATI_MACH64GX	6	/* ATI Mach 64GX family		*/
+#define FB_ACCEL_DEC_TGA	7	/* DEC 21030 TGA		*/
+#define FB_ACCEL_ATI_MACH64CT	8	/* ATI Mach 64CT family		*/
+#define FB_ACCEL_ATI_MACH64VT	9	/* ATI Mach 64CT family VT class */
+#define FB_ACCEL_ATI_MACH64GT	10	/* ATI Mach 64CT family GT class */
+#define FB_ACCEL_SUN_CREATOR	11	/* Sun Creator/Creator3D	*/
+#define FB_ACCEL_SUN_CGSIX	12	/* Sun cg6			*/
+#define FB_ACCEL_SUN_LEO	13	/* Sun leo/zx			*/
+#define FB_ACCEL_IMS_TWINTURBO	14	/* IMS Twin Turbo		*/
+#define FB_ACCEL_3DLABS_PERMEDIA2 15	/* 3Dlabs Permedia 2		*/
+#define FB_ACCEL_MATROX_MGA2064W 16	/* Matrox MGA2064W (Millenium)	*/
+#define FB_ACCEL_MATROX_MGA1064SG 17	/* Matrox MGA1064SG (Mystique)	*/
+#define FB_ACCEL_MATROX_MGA2164W 18	/* Matrox MGA2164W (Millenium II) */
+#define FB_ACCEL_MATROX_MGA2164W_AGP 19	/* Matrox MGA2164W (Millenium II) */
+#define FB_ACCEL_MATROX_MGAG100	20	/* Matrox G100 (Productiva G100) */
+#define FB_ACCEL_MATROX_MGAG200	21	/* Matrox G200 (Myst, Mill, ...) */
+#define FB_ACCEL_SUN_CG14	22	/* Sun cgfourteen		 */
+#define FB_ACCEL_SUN_BWTWO	23	/* Sun bwtwo			 */
+#define FB_ACCEL_SUN_CGTHREE	24	/* Sun cgthree			 */
+#define FB_ACCEL_SUN_TCX	25	/* Sun tcx			 */
+#define FB_ACCEL_MATROX_MGAG400	26	/* Matrox G400			 */
+
+struct fb_fix_screeninfo {
+	char id[16];			/* identification string eg "TT Builtin" */
+	char *smem_start;		/* Start of frame buffer mem */
+					/* (physical address) */
+	__u32 smem_len;			/* Length of frame buffer mem */
+	__u32 type;			/* see FB_TYPE_*		*/
+	__u32 type_aux;			/* Interleave for interleaved Planes */
+	__u32 visual;			/* see FB_VISUAL_*		*/ 
+	__u16 xpanstep;			/* zero if no hardware panning  */
+	__u16 ypanstep;			/* zero if no hardware panning  */
+	__u16 ywrapstep;		/* zero if no hardware ywrap    */
+	__u32 line_length;		/* length of a line in bytes    */
+	char *mmio_start;		/* Start of Memory Mapped I/O   */
+					/* (physical address) */
+	__u32 mmio_len;			/* Length of Memory Mapped I/O  */
+	__u32 accel;			/* Type of acceleration available */
+	__u16 reserved[3];		/* Reserved for future compatibility */
+};
+
+/* Interpretation of offset for color fields: All offsets are from the right,
+ * inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you
+ * can use the offset as right argument to <<). A pixel afterwards is a bit
+ * stream and is written to video memory as that unmodified. This implies
+ * big-endian byte order if bits_per_pixel is greater than 8.
+ */
+struct fb_bitfield {
+	__u32 offset;			/* beginning of bitfield	*/
+	__u32 length;			/* length of bitfield		*/
+	__u32 msb_right;		/* != 0 : Most significant bit is */ 
+					/* right */ 
+};
+
+#define FB_NONSTD_HAM		1	/* Hold-And-Modify (HAM)        */
+
+#define FB_ACTIVATE_NOW		0	/* set values immediately (or vbl)*/
+#define FB_ACTIVATE_NXTOPEN	1	/* activate on next open	*/
+#define FB_ACTIVATE_TEST	2	/* don't set, round up impossible */
+#define FB_ACTIVATE_MASK       15
+					/* values			*/
+#define FB_ACTIVATE_VBL	       16	/* activate values on next vbl  */
+#define FB_CHANGE_CMAP_VBL     32	/* change colormap on vbl	*/
+#define FB_ACTIVATE_ALL	       64	/* change all VCs on this fb	*/
+
+#define FB_ACCELF_TEXT		1	/* text mode acceleration */
+
+#define FB_SYNC_HOR_HIGH_ACT	1	/* horizontal sync high active	*/
+#define FB_SYNC_VERT_HIGH_ACT	2	/* vertical sync high active	*/
+#define FB_SYNC_EXT		4	/* external sync		*/
+#define FB_SYNC_COMP_HIGH_ACT	8	/* composite sync high active   */
+#define FB_SYNC_BROADCAST	16	/* broadcast video timings      */
+					/* vtotal = 144d/288n/576i => PAL  */
+					/* vtotal = 121d/242n/484i => NTSC */
+#define FB_SYNC_ON_GREEN	32	/* sync on green */
+
+#define FB_VMODE_NONINTERLACED  0	/* non interlaced */
+#define FB_VMODE_INTERLACED	1	/* interlaced	*/
+#define FB_VMODE_DOUBLE		2	/* double scan */
+#define FB_VMODE_MASK		255
+
+#define FB_VMODE_YWRAP		256	/* ywrap instead of panning     */
+#define FB_VMODE_SMOOTH_XPAN	512	/* smooth xpan possible (internally used) */
+#define FB_VMODE_CONUPDATE	512	/* don't update x/yoffset	*/
+
+struct fb_var_screeninfo {
+	__u32 xres;			/* visible resolution		*/
+	__u32 yres;
+	__u32 xres_virtual;		/* virtual resolution		*/
+	__u32 yres_virtual;
+	__u32 xoffset;			/* offset from virtual to visible */
+	__u32 yoffset;			/* resolution			*/
+
+	__u32 bits_per_pixel;		/* guess what			*/
+	__u32 grayscale;		/* != 0 Graylevels instead of colors */
+
+	struct fb_bitfield red;		/* bitfield in fb mem if true color, */
+	struct fb_bitfield green;	/* else only length is significant */
+	struct fb_bitfield blue;
+	struct fb_bitfield transp;	/* transparency			*/	
+
+	__u32 nonstd;			/* != 0 Non standard pixel format */
+
+	__u32 activate;			/* see FB_ACTIVATE_*		*/
+
+	__u32 height;			/* height of picture in mm    */
+	__u32 width;			/* width of picture in mm     */
+
+	__u32 accel_flags;		/* acceleration flags (hints)	*/
+
+	/* Timing: All values in pixclocks, except pixclock (of course) */
+	__u32 pixclock;			/* pixel clock in ps (pico seconds) */
+	__u32 left_margin;		/* time from sync to picture	*/
+	__u32 right_margin;		/* time from picture to sync	*/
+	__u32 upper_margin;		/* time from sync to picture	*/
+	__u32 lower_margin;
+	__u32 hsync_len;		/* length of horizontal sync	*/
+	__u32 vsync_len;		/* length of vertical sync	*/
+	__u32 sync;			/* see FB_SYNC_*		*/
+	__u32 vmode;			/* see FB_VMODE_*		*/
+	__u32 reserved[6];		/* Reserved for future compatibility */
+};
+
+struct fb_cmap {
+	__u32 start;			/* First entry	*/
+	__u32 len;			/* Number of entries */
+	__u16 *red;			/* Red values	*/
+	__u16 *green;
+	__u16 *blue;
+	__u16 *transp;			/* transparency, can be NULL */
+};
+
+struct fb_con2fbmap {
+	__u32 console;
+	__u32 framebuffer;
+};
+
+struct fb_monspecs {
+	__u32 hfmin;			/* hfreq lower limit (Hz) */
+	__u32 hfmax; 			/* hfreq upper limit (Hz) */
+	__u16 vfmin;			/* vfreq lower limit (Hz) */
+	__u16 vfmax;			/* vfreq upper limit (Hz) */
+	unsigned dpms : 1;		/* supports DPMS */
+};
+
+#ifdef __KERNEL__
+
+#include <linux/fs.h>
+
+
+struct fb_info;
+struct fb_info_gen;
+struct vm_area_struct;
+struct file;
+
+    /*
+     *  Frame buffer operations
+     */
+
+struct fb_ops {
+    /* open/release and usage marking */
+    int (*fb_open)(struct fb_info *info, int user);
+    int (*fb_release)(struct fb_info *info, int user);
+    /* get non settable parameters */
+    int (*fb_get_fix)(struct fb_fix_screeninfo *fix, int con,
+		      struct fb_info *info); 
+    /* get settable parameters */
+    int (*fb_get_var)(struct fb_var_screeninfo *var, int con,
+		      struct fb_info *info);		
+    /* set settable parameters */
+    int (*fb_set_var)(struct fb_var_screeninfo *var, int con,
+		      struct fb_info *info);		
+    /* get colormap */
+    int (*fb_get_cmap)(struct fb_cmap *cmap, int kspc, int con,
+		       struct fb_info *info);
+    /* set colormap */
+    int (*fb_set_cmap)(struct fb_cmap *cmap, int kspc, int con,
+		       struct fb_info *info);
+    /* pan display */
+    int (*fb_pan_display)(struct fb_var_screeninfo *var, int con,
+			  struct fb_info *info);
+    /* perform fb specific ioctl */
+    int (*fb_ioctl)(struct inode *inode, struct file *file, unsigned int cmd,
+		    unsigned long arg, int con, struct fb_info *info);
+    /* perform fb specific mmap */
+    int (*fb_mmap)(struct fb_info *info, struct file *file, struct vm_area_struct *vma);
+    /* switch to/from raster image mode */
+    int (*fb_rasterimg)(struct fb_info *info, int start);
+};
+
+
+   /*
+    *    This is the interface between the low-level console driver and the
+    *    low-level frame buffer device
+    */
+
+struct display {
+    /* Filled in by the frame buffer device */
+
+    struct fb_var_screeninfo var;   /* variable infos. yoffset and vmode */
+				    /* are updated by fbcon.c */
+    struct fb_cmap cmap;            /* colormap */
+    char *screen_base;              /* pointer to top of virtual screen */    
+				    /* (virtual address) */
+    int visual;
+    int type;                       /* see FB_TYPE_* */
+    int type_aux;                   /* Interleave for interleaved Planes */
+    u_short ypanstep;               /* zero if no hardware ypan */
+    u_short ywrapstep;              /* zero if no hardware ywrap */
+    u_long line_length;             /* length of a line in bytes */
+    u_short can_soft_blank;         /* zero if no hardware blanking */
+    u_short inverse;                /* != 0 text black on white as default */
+    struct display_switch *dispsw;  /* low level operations */
+    void *dispsw_data;		    /* optional dispsw helper data */
+
+#if 0
+    struct fb_fix_cursorinfo fcrsr;
+    struct fb_var_cursorinfo *vcrsr;
+    struct fb_cursorstate crsrstate;
+#endif
+
+    /* Filled in by the low-level console driver */
+
+    struct vc_data *conp;           /* pointer to console data */
+    struct fb_info *fb_info;        /* frame buffer for this console */
+    int vrows;                      /* number of virtual rows */
+    unsigned short cursor_x;	    /* current cursor position */
+    unsigned short cursor_y;
+    int fgcol;                      /* text colors */
+    int bgcol;
+    u_long next_line;               /* offset to one line below */
+    u_long next_plane;              /* offset to next plane */
+    u_char *fontdata;               /* Font associated to this display */
+    unsigned short _fontheightlog;
+    unsigned short _fontwidthlog;
+    unsigned short _fontheight;
+    unsigned short _fontwidth;
+    int userfont;                   /* != 0 if fontdata kmalloc()ed */
+    u_short scrollmode;             /* Scroll Method */
+    short yscroll;                  /* Hardware scrolling */
+    unsigned char fgshift, bgshift;
+    unsigned short charmask;	    /* 0xff or 0x1ff */
+};
+
+
+struct fb_info {
+   char modename[40];			/* default video mode */
+   kdev_t node;
+   int flags;
+#define FBINFO_FLAG_MODULE	1	/* Low-level driver is a module */
+   struct fb_ops *fbops;
+   struct fb_monspecs monspecs;
+   struct display *disp;		/* initial display variable */
+   struct vc_data *display_fg;		/* Console visible on this display */
+   char fontname[40];			/* default font name */
+   int (*changevar)(int);		/* tell console var has changed */
+   int (*switch_con)(int, struct fb_info*);
+					/* tell fb to switch consoles */
+   int (*updatevar)(int, struct fb_info*);
+					/* tell fb to update the vars */
+   void (*blank)(int, struct fb_info*);	/* tell fb to (un)blank the screen */
+					/* arg = 0: unblank */
+					/* arg > 0: VESA level (arg-1) */
+
+   /* From here on everything is device dependent */
+};
+
+#ifdef MODULE
+#define FBINFO_FLAG_DEFAULT	FBINFO_FLAG_MODULE
+#else
+#define FBINFO_FLAG_DEFAULT	0
+#endif
+
+    /*
+     *  This structure abstracts from the underlying hardware. It is not
+     *  mandatory but used by the `generic' frame buffer operations.
+     *  Read drivers/video/skeletonfb.c for more information.
+     */
+
+struct fbgen_hwswitch {
+    void (*detect)(void);
+    int (*encode_fix)(struct fb_fix_screeninfo *fix, const void *par,
+		      struct fb_info_gen *info);
+    int (*decode_var)(const struct fb_var_screeninfo *var, void *par,
+		      struct fb_info_gen *info);
+    int (*encode_var)(struct fb_var_screeninfo *var, const void *par,
+		      struct fb_info_gen *info);
+    void (*get_par)(void *par, struct fb_info_gen *info);
+    void (*set_par)(const void *par, struct fb_info_gen *info);
+    int (*getcolreg)(unsigned regno, unsigned *red, unsigned *green,
+		     unsigned *blue, unsigned *transp, struct fb_info *info);
+    int (*setcolreg)(unsigned regno, unsigned red, unsigned green,
+		     unsigned blue, unsigned transp, struct fb_info *info);
+    int (*pan_display)(const struct fb_var_screeninfo *var,
+		       struct fb_info_gen *info);
+    int (*blank)(int blank_mode, struct fb_info_gen *info);
+    void (*set_disp)(const void *par, struct display *disp,
+		     struct fb_info_gen *info);
+};
+
+struct fb_info_gen {
+    struct fb_info info;
+
+    /* Entries for a generic frame buffer device */
+    /* Yes, this starts looking like C++ */
+    u_int parsize;
+    struct fbgen_hwswitch *fbhw;
+
+   /* From here on everything is device dependent */
+};
+
+    /*
+     *  `Generic' versions of the frame buffer device operations
+     */
+
+extern int fbgen_get_fix(struct fb_fix_screeninfo *fix, int con,
+			 struct fb_info *info);
+extern int fbgen_get_var(struct fb_var_screeninfo *var, int con,
+			 struct fb_info *info);
+extern int fbgen_set_var(struct fb_var_screeninfo *var, int con,
+			 struct fb_info *info);
+extern int fbgen_get_cmap(struct fb_cmap *cmap, int kspc, int con,
+			  struct fb_info *info);
+extern int fbgen_set_cmap(struct fb_cmap *cmap, int kspc, int con,
+			  struct fb_info *info);
+extern int fbgen_pan_display(struct fb_var_screeninfo *var, int con,
+			     struct fb_info *info);
+extern int fbgen_ioctl(struct inode *inode, struct file *file,
+		       unsigned int cmd, unsigned long arg, int con,
+		       struct fb_info *info);
+
+    /*
+     *  Helper functions
+     */
+
+extern int fbgen_do_set_var(struct fb_var_screeninfo *var, int isactive,
+			    struct fb_info_gen *info);
+extern void fbgen_set_disp(int con, struct fb_info_gen *info);
+extern void fbgen_install_cmap(int con, struct fb_info_gen *info);
+extern int fbgen_update_var(int con, struct fb_info *info);
+extern int fbgen_switch(int con, struct fb_info *info);
+extern void fbgen_blank(int blank, struct fb_info *info);
+
+
+struct fb_videomode {
+    const char *name;
+    struct fb_var_screeninfo var;
+};
+
+
+/* drivers/char/fbmem.c */
+extern int register_framebuffer(struct fb_info *fb_info);
+extern int unregister_framebuffer(const struct fb_info *fb_info);
+extern int fbmon_valid_timings(u_int pixclock, u_int htotal, u_int vtotal,
+			       const struct fb_info *fb_info);
+extern int fbmon_dpms(const struct fb_info *fb_info);
+
+
+extern int num_registered_fb;
+extern struct fb_info *registered_fb[FB_MAX];
+extern char con2fb_map[MAX_NR_CONSOLES];
+
+/* drivers/video/fbcon.c */
+extern struct display fb_display[MAX_NR_CONSOLES];
+
+/* drivers/video/fbcmap.c */
+extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp);
+extern void fb_copy_cmap(struct fb_cmap *from, struct fb_cmap *to,
+			 int fsfromto);
+extern int fb_get_cmap(struct fb_cmap *cmap, int kspc,
+		       int (*getcolreg)(u_int, u_int *, u_int *, u_int *,
+					u_int *, struct fb_info *),
+		       struct fb_info *fb_info);
+extern int fb_set_cmap(struct fb_cmap *cmap, int kspc,
+		       int (*setcolreg)(u_int, u_int, u_int, u_int, u_int,
+					struct fb_info *),
+		       struct fb_info *fb_info);
+extern struct fb_cmap *fb_default_cmap(int len);
+extern void fb_invert_cmaps(void);
+
+/* VESA Blanking Levels */
+#define VESA_NO_BLANKING	0
+#define VESA_VSYNC_SUSPEND	1
+#define VESA_HSYNC_SUSPEND	2
+#define VESA_POWERDOWN		3
+
+#endif /* __KERNEL__ */
+
+#if 1
+
+#define FBCMD_GET_CURRENTPAR	0xDEAD0005
+#define FBCMD_SET_CURRENTPAR	0xDEAD8005
+
+#endif
+
+
+#if 1 /* Preliminary */
+
+   /*
+    *    Hardware Cursor
+    */
+
+#define FBIOGET_FCURSORINFO     0x4607
+#define FBIOGET_VCURSORINFO     0x4608
+#define FBIOPUT_VCURSORINFO     0x4609
+#define FBIOGET_CURSORSTATE     0x460A
+#define FBIOPUT_CURSORSTATE     0x460B
+
+
+struct fb_fix_cursorinfo {
+	__u16 crsr_width;		/* width and height of the cursor in */
+	__u16 crsr_height;		/* pixels (zero if no cursor)	*/
+	__u16 crsr_xsize;		/* cursor size in display pixels */
+	__u16 crsr_ysize;
+	__u16 crsr_color1;		/* colormap entry for cursor color1 */
+	__u16 crsr_color2;		/* colormap entry for cursor color2 */
+};
+
+struct fb_var_cursorinfo {
+	__u16 width;
+	__u16 height;
+	__u16 xspot;
+	__u16 yspot;
+	__u8 data[1];			/* field with [height][width]        */
+};
+
+struct fb_cursorstate {
+	__s16 xoffset;
+	__s16 yoffset;
+	__u16 mode;
+};
+
+#define FB_CURSOR_OFF		0
+#define FB_CURSOR_ON		1
+#define FB_CURSOR_FLASH		2
+
+#endif /* Preliminary */
+
+#endif /* _LINUX_FB_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/fbset/fb.modes.5	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,228 @@
+.TH fb.modes 8 "Aug 1996" local "Linux frame buffer utils"
+.SH NAME
+fb.modes \- frame buffer modes file
+.SH DESCRIPTION
+.I /etc/fb.modes
+contains an unlimited number of video mode descriptions. The general format
+of a video mode is:
+.sp
+mode
+.RI \" name \"
+.RS
+geometry
+.RI < xres >
+.RI < yres >
+.RI < vxres >
+.RI < vyres >
+.RI < depth >
+.br
+timings
+.RI < pixclock >
+.RI < left >
+.RI < right >
+.RI < upper >
+.RI < lower >
+.RI < hslen >
+.RI < vslen >
+.br
+.B options
+.RI < value >
+.RE
+endmode
+.SH OPTIONS
+geometry options:
+.RS
+.TP
+.I xres
+visible horizontal resolution (in pixels)
+.TP
+.I yres
+visible vertical resolution (in pixels)
+.TP
+.I vxres
+virtual horizontal resolution (in pixels)
+.TP
+.I vyres
+virtual vertical resolution (in pixels)
+.TP
+.I depth
+display depth (in bits per pixel)
+.RE
+.PP
+timing options:
+.RS
+.TP
+.I pixclock
+length of one pixel (in picoseconds)
+.TP
+.I left
+left margin (in pixels)
+.TP
+.I right
+right margin (in pixels)
+.TP
+.I upper
+upper margin (in pixel lines)
+.TP
+.I lower
+lower margin (in pixel lines)
+.TP
+.I hslen
+horizontal sync length (in pixels)
+.TP
+.I vslen
+vertical sync length (in pixel lines)
+.RE
+.PP
+other options:
+.RS
+the first value of this options is the default
+.TP
+.IR \fBhsync "\ {" low | high }
+the horizontal sync polarity
+.TP
+.IR \fBvsync "\ {" low | high }
+the vertical sync polarity
+.TP
+.IR \fBcsync "\ {" low | high }
+the composite sync polarity
+.TP
+.IR \fBextsync "\ {" false | true }
+enable or disable external resync. If enabled the sync timings are not
+generated by the frame buffer device and must be provided externally
+instead. Note that this option may not be supported by every frame buffer
+device
+.TP
+.IR \fBlaced "\ {" false | true }
+enable or disable interlace. If enabled the display will be split in two
+frames, each frame contains only even and odd lines respectively. These two
+frames will be displayed alternating, this way twice the lines can be
+displayed and the vertical frequency for monitor stays the same, but the
+visible vertical frequency gets halved
+.TP
+.IR \fBdouble "\ {" false | true }
+enable or disable doublescan. If enabled every line will be displayed twice
+and this way the horizontal frequency can easily be doubled, so that the
+same resolution can be displayed on different monitors, even if the
+horizontal frequency specification differs. Note that this option may not be
+supported by every frame buffer device
+.RE
+.SH INTERNALS
+Generally a frame buffer display is organized as follows:
+.sp
+.ad c
++\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-+\-\-\-+
+.br
+.RB "|\ \ \ |\ \ \ \ \ \ \ " ^ "\ \ \ \ \ \ \ |\ \ \ |\ \ \ |"
+.br
+.RB "|\ \ \ |\ \ \ \ \ \ \ " | "\ " \fI5 "\ \ \ \ \ |\ \ \ |\ \ \ |"
+.br
+.RB "|\ \ \ |\ \ \ \ \ \ \ " v "\ \ \ \ \ \ \ |\ \ \ |\ \ \ |"
+.br
++\-\-\-#################\-\-\-+\-\-\-+
+.br
+.RB "|\ \ \ #\ \ \ \ \ \ \ " ^ "\ \ \ \ \ \ \ #\ \ \ |\ \ \ |"
+.br
+.RB "|\ \ \ #\ \ \ \ \ \ \ " | "\ \ \ \ \ \ \ #\ \ \ |\ \ \ |"
+.br
+.RB "|\ \ \ #\ \ \ \ \ \ \ " | "\ \ \ \ \ \ \ #\ \ \ |\ \ \ |"
+.br
+.RI "| " 1 " #       " \fB| "   " 2 "   # " 3 " | " 4 " |"
+.br
+.RB "|" "<\->" "#" "<\-\-\-\-\-\-+\-\-\-\-\-\->" "#" "<\->" "|" "<\->" "|"
+.br
+.RB "|\ \ \ #\ \ \ \ \ \ \ " | "\ \ \ \ \ \ \ #\ \ \ |\ \ \ |"
+.br
+.RB "|\ \ \ #\ \ \ \ \ \ \ " | "\ " \fI6 "\ \ \ \ \ #\ \ \ |\ \ \ |"
+.br
+.RB "|\ \ \ #\ \ \ \ \ \ \ " | "\ \ \ \ \ \ \ #\ \ \ |\ \ \ |"
+.br
+.RB "|\ \ \ #\ \ \ \ \ \ \ " v "\ \ \ \ \ \ \ #\ \ \ |\ \ \ |"
+.br
++\-\-\-#################\-\-\-+\-\-\-+
+.br
+.RB "|\ \ \ |\ \ \ \ \ \ \ " ^ "\ \ \ \ \ \ \ |\ \ \ |\ \ \ |"
+.br
+.RB "|\ \ \ |\ \ \ \ \ \ \ " | "\ " \fI7 "\ \ \ \ \ |\ \ \ |\ \ \ |"
+.br
+.RB "|\ \ \ |\ \ \ \ \ \ \ " v "\ \ \ \ \ \ \ |\ \ \ |\ \ \ |"
+.br
++\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-+\-\-\-+
+.br
+.RB "|\ \ \ |\ \ \ \ \ \ \ " ^ "\ \ \ \ \ \ \ |\ \ \ |\ \ \ |"
+.br
+.RB "|\ \ \ |\ \ \ \ \ \ \ " | "\ " \fI8 "\ \ \ \ \ |\ \ \ |\ \ \ |"
+.br
+.RB "|\ \ \ |\ \ \ \ \ \ \ " v "\ \ \ \ \ \ \ |\ \ \ |\ \ \ |"
+.br
++\-\-\-+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+\-\-\-+\-\-\-+
+.sp
+.ad n
+.RS
+.I 1
+\t left margin
+.br
+.I 2
+\t xres
+.br
+.I 3
+\t right margin
+.br
+.I 4
+\t horizontal sync len
+.br
+.I 5
+\t upper margin
+.br
+.I 6
+\t yres
+.br
+.I 7
+\t lower margin
+.br
+.I 8
+\t vertical sync len
+.RE
+.sp
+The area bordered with `#' is the visible display area. Horizontal and
+vertical frequencies can now easily be calculated, for this the sum of
+horizontal or vertical values are important
+.RS
+.sp
+htotal\ =\ left\ +\ xres\ +\ right\ +\ hslen
+.br
+vtotal\ =\ upper\ +\ yres\ +\ lower\ +\ vslen
+.sp
+.RE
+The length of one line can now be calculated with pixclock
+.RS
+.sp
+line\ =\ pixclock\ *\ htotal
+.sp
+.RE
+and we have the horizontal frequency
+.RS
+.sp
+hfreq\ =\ 1E12\ /\ line\ =\ 1E12\ /\ (pixclock\ *\ htotal)
+.sp
+.RE
+To get the vertical frequency vtotal must eventually adjusted. If the
+display is laced, vtotal must be halved or if the display is a doublescan
+one, vtotal must be doubled. Now we can calculate the length of one frame
+.RS
+.sp
+if\ (lace)\ \ \ vtotal\ /=\ 2
+.br
+if\ (double)\ vtotal\ *=\ 2
+.sp
+frame\ =\ vtotal\ *\ line
+.sp
+.RE
+and we get also the vertical frequency
+.RS
+.sp
+vfreq\ =\ 1E12\ /\ frame\ =\ hfreq\ /\ vtotal
+.sp
+.RE
+.SH SEE ALSO
+.BR fbset "(8), " fbdev (4)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/fbset/fbset.8	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,242 @@
+.TH fbset 8 "July 1998" local "Linux frame buffer utils"
+.SH NAME
+fbset \- show and modify frame buffer device settings
+.SH SYNOPSIS
+.B fbset
+.RI [ options ]
+.RI [ mode ]
+.SH DESCRIPTION
+.B This documentation is out of date!!
+.PP
+.B fbset
+is a system utility to show or change the settings of the frame buffer
+device. The frame buffer device provides a simple and unique interface to
+access different kinds of graphic displays.
+.PP
+Frame buffer devices are accessed via special device nodes located in the
+/dev directory. The naming scheme for these nodes is always
+.IR \fBfb < n >,
+where
+.I n
+is the number of the used frame buffer device.
+.PP
+.B fbset
+uses an own video mode database located in /etc/fb.modes. An unlimited
+number of video modes can be defined in this database. For further
+information see
+.BR fb.modes (5).
+.SH OPTIONS
+If no option is given,
+.B fbset
+will display the current frame buffer settings.
+.sp
+General options:
+.RS
+.TP
+.BR \-\-help ",\ " \-h
+display an usage information
+.TP
+.BR \-\-now ",\ " \-n
+change the video mode immediately. If no frame buffer device is given via
+.B \-fb
+, then this option is activated by default
+.TP
+.BR \-\-show ",\ " \-s
+display the video mode settings. This is default if no further option or
+only a frame buffer device via
+.B \-fb
+is given
+.TP
+.BR \-\-info ",\ " \-i
+display all available frame buffer information
+.TP
+.BR \-\-verbose ",\ " \-v
+display information what
+.B fbset
+is currently doing
+.TP
+.BR \-\-version ",\ " \-V
+display the version information about
+.B fbset
+.TP
+.BR \-\-xfree86 ",\ "  \-x
+display the timing information as it's needed by XFree86
+.RE
+.PP
+Frame buffer device nodes:
+.RS
+.TP
+.BR \-fb "\ <" \fIdevice >
+.I device
+gives the frame buffer device node. If no device via
+.B \-fb
+is given, 
+.I /dev/fb0
+is used
+.TP
+.RE
+.PP
+Video mode database:
+.RS
+.TP
+.BR \-db "\ <" \fIfile >
+set an alternative video mode database file (default is 
+.IR /etc/fb.modes ),
+see also
+.BR fb.modes (5)
+.RE
+.PP
+Display geometry:
+.RS
+.TP
+.BR \-xres "\ <" \fIvalue >
+set visible horizontal resolution (in pixels)
+.TP
+.BR \-yres "\ <" \fIvalue >
+set visible vertical resolution (in pixels)
+.TP
+.BR \-vxres "\ <" \fIvalue >
+set virtual horizontal resolution (in pixels)
+.TP
+.BR \-vyres "\ <" \fIvalue >
+set virtual vertical resolution (in pixels)
+.TP
+.BR \-depth "\ <" \fIvalue >
+set display depth (in bits per pixel)
+.TP
+.BR \-\-geometry ",\ " \-g "\ ..."
+set all geometry parameters at once in the order
+.RI < xres >
+.RI < yres >
+.RI < vxres >
+.RI < vyres >
+.RI < depth >,
+e.g.
+.B \-g
+.I 640 400 640 400 4
+.TP
+.BR \-match "\ \ \ \ \ \ "
+make the physical resolution match the virtual resolution
+.RE
+.PP
+Display timings:
+.RS
+.TP
+.BR \-pixclock "\ <" \fIvalue >
+set the length of one pixel (in picoseconds). Note that the frame buffer
+device may only support some pixel lengths
+.TP
+.BR \-left "\ <" \fIvalue >
+set left margin (in pixels)
+.TP
+.BR \-right "\ <" \fIvalue >
+set right margin (in pixels)
+.TP
+.BR \-upper "\ <" \fIvalue >
+set upper margin (in pixel lines)
+.TP
+.BR \-lower "\ <" \fIvalue >
+set lower margin (in pixel lines)
+.TP
+.BR \-hslen "\ <" \fIvalue >
+set horizontal sync length (in pixels)
+.TP
+.BR \-vslen "\ <" \fIvalue >
+set vertical sync length (in pixel lines)
+.TP
+.BR \-\-timings ",\ " \-t "\ ..."
+set all timing parameters at once in the order
+.RI < pixclock >
+.RI < left >
+.RI < right >
+.RI < upper >
+.RI < lower >
+.RI < hslen >
+.RI < vslen >,
+e.g.
+.B \-g
+.I 35242 64 96 35 12 112 2
+.RE
+.PP
+Display flags:
+.RS
+.TP
+.IR \fB\-hsync "\ {" low | high }
+set the horizontal sync polarity
+.TP
+.IR \fB\-vsync "\ {" low | high }
+set the vertical sync polarity
+.TP
+.IR \fB\-csync "\ {" low | high }
+set the composite sync polarity
+.TP
+.IR \fB\-extsync "\ {" false | true }
+enable or disable external resync. If enabled the sync timings are not
+generated by the frame buffer device and must be provided externally
+instead. Note that this option may not be supported by every frame buffer
+device
+.TP
+.IR \fB\-bcast "\ {" false | true }
+enable or disable broadcast modes. If enabled the frame buffer generates the
+exact timings for several broadcast modes (e.g. PAL or NTSC). Note that
+this option may not be supported by every frame buffer device
+.TP
+.IR \fB\-laced "\ {" false | true }
+enable or disable interlace. If enabled the display will be split in two
+frames, each frame contains only even and odd lines respectively. These two
+frames will be displayed alternating, this way twice the lines can be
+displayed and the vertical frequency for the monitor stays the same, but the
+visible vertical frequency gets halved
+.TP
+.IR \fB\-double "\ {" false | true }
+enable or disable doublescan. If enabled every line will be displayed twice
+and this way the horizontal frequency can easily be doubled, so that the
+same resolution can be displayed on different monitors, even if the
+horizontal frequency specification differs. Note that this option may not be
+supported by every frame buffer device
+.RE
+.PP
+Display positioning:
+.RS
+.TP
+.IR \fB\-move "\ {" left | right | up | down }
+move the visible part of the display in the specified direction
+.TP
+.BR \-step "\ <" \fIvalue >
+set step size for display positioning (in pixels or pixel lines), if
+.B \-step
+is not given display will be moved 8 pixels horizontally or 2 pixel lines
+vertically
+.RE
+.SH EXAMPLE
+To set the used video mode for
+.B X
+insert the following in rc.local:
+.RS
+.sp
+.B fbset
+-fb
+.I /dev/fb0
+vga
+.sp
+.RE
+and make the used frame buffer device known to
+.BR X :
+.RS
+.sp
+.B export
+.RI FRAMEBUFFER= /dev/fb0
+.RE
+.SH FILES
+.I /dev/fb*
+.br
+.I /etc/fb.modes
+.SH SEE ALSO
+.BR fb.modes "(5), " fbdev (4)
+.SH AUTHORS
+.TP
+Geert Uytterhoeven <Geert.Uytterhoeven@cs.kuleuven.ac.be>
+.TP
+Roman Zippel <zippel@fh-brandenburg.de>
+.br
+man files
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/fbset/fbset.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,1054 @@
+/*
+ *  Linux Frame Buffer Device Configuration
+ *
+ *  © Copyright 1995-1999 by Geert Uytterhoeven
+ *		       (Geert.Uytterhoeven@cs.kuleuven.ac.be)
+ *
+ *  --------------------------------------------------------------------------
+ *
+ *  This file is subject to the terms and conditions of the GNU General Public
+ *  License. See the file COPYING in the main directory of the Linux
+ *  distribution for more details.
+ *
+ *  Petr Vandrovec <vandrove@vc.cvut.cz>:
+ *           -grayscale, -rgba, -nonstd, VGA modes reporting
+ *
+ *  Brad Midgley <brad@exodus.pht.com>:
+ *           -match
+ *
+ */
+
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <ctype.h>
+#include <sys/stat.h>
+
+struct file;
+struct inode;
+
+#include "fb.h"
+
+#include "fbset.h"
+
+
+    /*
+     *  Default Frame Buffer Special Device Node
+     */
+
+#define DEFAULT_FRAMEBUFFER	"/dev/fb0"
+
+
+    /*
+     *  Default Video Mode Database File
+     */
+
+#define DEFAULT_MODEDBFILE	"/etc/fb.modes"
+
+
+    /*
+     *  Command Line Options
+     */
+
+static const char *ProgramName;
+
+static int Opt_test = 0;
+static int Opt_show = 0;
+static int Opt_info = 0;
+static int Opt_version = 0;
+static int Opt_verbose = 0;
+static int Opt_xfree86 = 0;
+static int Opt_change = 0;
+static int Opt_all = 0;
+
+static const char *Opt_fb = NULL;
+const char *Opt_modedb = DEFAULT_MODEDBFILE;
+static const char *Opt_xres = NULL;
+static const char *Opt_yres = NULL;
+static const char *Opt_vxres = NULL;
+static const char *Opt_vyres = NULL;
+static const char *Opt_depth = NULL;
+static const char *Opt_pixclock = NULL;
+static const char *Opt_left = NULL;
+static const char *Opt_right = NULL;
+static const char *Opt_upper = NULL;
+static const char *Opt_lower = NULL;
+static const char *Opt_hslen = NULL;
+static const char *Opt_vslen = NULL;
+static const char *Opt_accel = NULL;
+static const char *Opt_hsync = NULL;
+static const char *Opt_vsync = NULL;
+static const char *Opt_csync = NULL;
+static const char *Opt_gsync = NULL;
+static const char *Opt_extsync = NULL;
+static const char *Opt_bcast = NULL;
+static const char *Opt_laced = NULL;
+static const char *Opt_double = NULL;
+static const char *Opt_move = NULL;
+static const char *Opt_step = NULL;
+static const char *Opt_modename = NULL;
+static const char *Opt_rgba = NULL;
+static const char *Opt_nonstd = NULL;
+static const char *Opt_grayscale = NULL;
+static const char *Opt_matchyres = NULL;
+
+static struct {
+    const char *name;
+    const char **value;
+    const int change;
+} Options[] = {
+    { "-fb", &Opt_fb, 0 },
+    { "-db", &Opt_modedb, 0 },
+    { "-xres", &Opt_xres, 1 },
+    { "-yres", &Opt_yres, 1 },
+    { "-vxres", &Opt_vxres, 1 },
+    { "-vyres", &Opt_vyres, 1 },
+    { "-depth", &Opt_depth, 1 },
+    { "-nonstd", &Opt_nonstd, 1},
+    { "-pixclock", &Opt_pixclock, 1 },
+    { "-left", &Opt_left, 1 },
+    { "-right", &Opt_right, 1 },
+    { "-upper", &Opt_upper, 1 },
+    { "-lower", &Opt_lower, 1 },
+    { "-hslen", &Opt_hslen, 1 },
+    { "-vslen", &Opt_vslen, 1 },
+    { "-accel", &Opt_accel, 1 },
+    { "-hsync", &Opt_hsync, 1 },
+    { "-vsync", &Opt_vsync, 1 },
+    { "-csync", &Opt_csync, 1 },
+    { "-gsync", &Opt_gsync, 1 },
+    { "-extsync", &Opt_extsync, 1 },
+    { "-bcast", &Opt_bcast, 1 },
+    { "-laced", &Opt_laced, 1 },
+    { "-double", &Opt_double, 1 },
+    { "-move", &Opt_move, 1 },
+    { "-step", &Opt_step, 1 },
+    { "-rgba", &Opt_rgba, 1 },
+    { "-grayscale", &Opt_grayscale, 1 },
+    { NULL, NULL, 0 }
+};
+
+
+    /*
+     *  Video Mode Database
+     */
+
+struct VideoMode *VideoModes = NULL;
+
+
+    /*
+     *  Hardware Text Modes
+     */
+
+static struct textentry {
+    __u32 id;
+    const char *name;
+} Textmodes[] = {
+    { FB_AUX_TEXT_MDA, "Monochrome text" },
+    { FB_AUX_TEXT_CGA, "CGA/EGA/VGA Color text" },
+    { FB_AUX_TEXT_S3_MMIO, "S3 MMIO fasttext" },
+    { FB_AUX_TEXT_MGA_STEP16, "MGA Millennium I step 16 text" },
+    { FB_AUX_TEXT_MGA_STEP8, "MGA step 8 text" },
+};
+
+static struct textentry VGAModes[] = {
+    { FB_AUX_VGA_PLANES_VGA4, "VGA 16 colors in 4 planes" },
+    { FB_AUX_VGA_PLANES_CFB4, "VGA 16 colors in 1 plane" },
+    { FB_AUX_VGA_PLANES_CFB8, "VGA 256 colors in 4 planes" },
+    /* last entry has name == NULL */
+    { 0,                      NULL}
+};
+
+    /*
+     *  Hardware Accelerators
+     */
+
+static struct accelentry {
+    __u32 id;
+    const char *name;
+} Accelerators[] = {
+    { FB_ACCEL_NONE, "No" },
+    { FB_ACCEL_ATARIBLITT, "Atari Blitter" },
+    { FB_ACCEL_AMIGABLITT, "Amiga Blitter" },
+    { FB_ACCEL_S3_TRIO64, "S3 Trio64" },
+    { FB_ACCEL_NCR_77C32BLT, "NCR 77C32BLT" },
+    { FB_ACCEL_S3_VIRGE, "S3 ViRGE" },
+    { FB_ACCEL_ATI_MACH64GX, "ATI Mach64GX" },
+    { FB_ACCEL_DEC_TGA, "DEC 21030 TGA" },
+    { FB_ACCEL_ATI_MACH64CT, "ATI Mach64CT" },
+    { FB_ACCEL_ATI_MACH64VT, "ATI Mach64VT" },
+    { FB_ACCEL_ATI_MACH64GT, "ATI Mach64GT" },
+    { FB_ACCEL_SUN_CREATOR, "Sun Creator/Creator3D" },
+    { FB_ACCEL_SUN_CGSIX, "Sun cg6" },
+    { FB_ACCEL_SUN_LEO, "Sun leo/zx" },
+    { FB_ACCEL_IMS_TWINTURBO, "IMS Twin Turbo" },
+    { FB_ACCEL_3DLABS_PERMEDIA2, "3Dlabs Permedia 2" },
+    { FB_ACCEL_MATROX_MGA2064W, "Matrox MGA2064W (Millennium)" },
+    { FB_ACCEL_MATROX_MGA1064SG, "Matrox MGA1064SG (Mystique)" },
+    { FB_ACCEL_MATROX_MGA2164W, "Matrox MGA2164W (Millennium II)" },
+    { FB_ACCEL_MATROX_MGA2164W_AGP, "Matrox MGA2164W (Millennium II AGP)" },
+    { FB_ACCEL_MATROX_MGAG100, "Matrox G100 (Productiva G100)" },
+    { FB_ACCEL_MATROX_MGAG200, "Matrox G200 (Millennium, Mystique)" },
+    { FB_ACCEL_SUN_CG14, "Sun cg14" },
+    { FB_ACCEL_SUN_BWTWO, "Sun bw2" },
+    { FB_ACCEL_SUN_CGTHREE, "Sun cg3" },
+    { FB_ACCEL_SUN_TCX, "Sun tcx" },
+    { FB_ACCEL_MATROX_MGAG400, "Matrox G400" },
+};
+
+
+    /*
+     *  Current Video Mode
+     */
+
+struct VideoMode Current;
+
+
+    /*
+     *  Function Prototypes
+     */
+
+int OpenFrameBuffer(const char *name);
+void CloseFrameBuffer(int fh);
+void GetVarScreenInfo(int fh, struct fb_var_screeninfo *var);
+void SetVarScreenInfo(int fh, struct fb_var_screeninfo *var);
+void GetFixScreenInfo(int fh, struct fb_fix_screeninfo *fix);
+static void ConvertFromVideoMode(const struct VideoMode *vmode,
+				 struct fb_var_screeninfo *var);
+static void ConvertToVideoMode(const struct fb_var_screeninfo *var,
+			       struct VideoMode *vmode);
+static int atoboolean(const char *var);
+static void ReadModeDB(void);
+static struct VideoMode *FindVideoMode(const char *name);
+static void ModifyVideoMode(struct VideoMode *vmode);
+static void DisplayVModeInfo(struct VideoMode *vmode);
+static void DisplayFBInfo(struct fb_fix_screeninfo *fix);
+static int FillScanRates(struct VideoMode *vmode);
+static void Usage(void) __attribute__ ((noreturn));
+int main(int argc, char *argv[]);
+
+
+    /*
+     *  Print an Error Message and Exit
+     */
+
+void Die(const char *fmt, ...)
+{
+    va_list ap;
+
+    fflush(stdout);
+    va_start(ap, fmt);
+    vfprintf(stderr, fmt, ap);
+    va_end(ap);
+    exit(1);
+}
+
+
+    /*
+     *  Open the Frame Buffer Device
+     */
+
+int OpenFrameBuffer(const char *name)
+{
+    int fh;
+
+    if (Opt_verbose)
+	printf("Opening frame buffer device `%s'\n", name);
+
+    if ((fh = open(name, O_RDONLY)) == -1)
+	Die("open %s: %s\n", name, strerror(errno));
+    return fh;
+}
+
+
+    /*
+     *  Close the Frame Buffer Device
+     */
+
+void CloseFrameBuffer(int fh)
+{
+    close(fh);
+}
+
+    /*
+     *  Get the Variable Part of the Screen Info
+     */
+
+void GetVarScreenInfo(int fh, struct fb_var_screeninfo *var)
+{
+    if (ioctl(fh, FBIOGET_VSCREENINFO, var))
+	Die("ioctl FBIOGET_VSCREENINFO: %s\n", strerror(errno));
+}
+
+
+    /*
+     *  Set (and Get) the Variable Part of the Screen Info
+     */
+
+void SetVarScreenInfo(int fh, struct fb_var_screeninfo *var)
+{
+    if (ioctl(fh, FBIOPUT_VSCREENINFO, var))
+	Die("ioctl FBIOPUT_VSCREENINFO: %s\n", strerror(errno));
+}
+
+
+    /*
+     *  Get the Fixed Part of the Screen Info
+     */
+
+void GetFixScreenInfo(int fh, struct fb_fix_screeninfo *fix)
+{
+    if (ioctl(fh, FBIOGET_FSCREENINFO, fix))
+	Die("ioctl FBIOGET_FSCREENINFO: %s\n", strerror(errno));
+}
+
+
+    /*
+     *  Conversion Routines
+     */
+
+static void ConvertFromVideoMode(const struct VideoMode *vmode,
+				 struct fb_var_screeninfo *var)
+{
+    memset(var, 0, sizeof(struct fb_var_screeninfo));
+    var->xres = vmode->xres;
+    var->yres = vmode->yres;
+    var->xres_virtual = vmode->vxres;
+    var->yres_virtual = vmode->vyres;
+    var->bits_per_pixel = vmode->depth;
+    var->nonstd = vmode->nonstd;
+    if (Opt_test)
+	var->activate = FB_ACTIVATE_TEST;
+    else
+	var->activate = FB_ACTIVATE_NOW;
+    if (Opt_all)
+	var->activate = FB_ACTIVATE_ALL;
+    var->accel_flags = vmode->accel_flags;
+    var->pixclock = vmode->pixclock;
+    var->left_margin = vmode->left;
+    var->right_margin = vmode->right;
+    var->upper_margin = vmode->upper;
+    var->lower_margin = vmode->lower;
+    var->hsync_len = vmode->hslen;
+    var->vsync_len = vmode->vslen;
+    if (vmode->hsync == HIGH)
+	var->sync |= FB_SYNC_HOR_HIGH_ACT;
+    if (vmode->vsync == HIGH)
+	var->sync |= FB_SYNC_VERT_HIGH_ACT;
+    if (vmode->csync == HIGH)
+	var->sync |= FB_SYNC_COMP_HIGH_ACT;
+    if (vmode->gsync == HIGH)
+	var->sync |= FB_SYNC_ON_GREEN;
+    if (vmode->extsync == TRUE)
+	var->sync |= FB_SYNC_EXT;
+    if (vmode->bcast == TRUE)
+	var->sync |= FB_SYNC_BROADCAST;
+    if (vmode->laced == TRUE)
+	var->vmode = FB_VMODE_INTERLACED;
+    else if (vmode->dblscan == TRUE)
+	var->vmode = FB_VMODE_DOUBLE;
+    else
+	var->vmode = FB_VMODE_NONINTERLACED;
+    var->vmode |= FB_VMODE_CONUPDATE;
+    var->red.length = vmode->red.length;
+    var->red.offset = vmode->red.offset;
+    var->green.length = vmode->green.length;
+    var->green.offset = vmode->green.offset;
+    var->blue.length = vmode->blue.length;
+    var->blue.offset = vmode->blue.offset;
+    var->transp.length = vmode->transp.length;
+    var->transp.offset = vmode->transp.offset;
+    var->grayscale = vmode->grayscale;
+}
+
+
+static void ConvertToVideoMode(const struct fb_var_screeninfo *var,
+			       struct VideoMode *vmode)
+{
+    vmode->name = NULL;
+    vmode->xres = var->xres;
+    vmode->yres = var->yres;
+    vmode->vxres = var->xres_virtual;
+    vmode->vyres = var->yres_virtual;
+    vmode->depth = var->bits_per_pixel;
+    vmode->nonstd = var->nonstd;
+    vmode->accel_flags = var->accel_flags;
+    vmode->pixclock = var->pixclock;
+    vmode->left = var->left_margin;
+    vmode->right = var->right_margin;
+    vmode->upper = var->upper_margin;
+    vmode->lower = var->lower_margin;
+    vmode->hslen = var->hsync_len;
+    vmode->vslen = var->vsync_len;
+    vmode->hsync = var->sync & FB_SYNC_HOR_HIGH_ACT ? HIGH : LOW;
+    vmode->vsync = var->sync & FB_SYNC_VERT_HIGH_ACT ? HIGH : LOW;
+    vmode->csync = var->sync & FB_SYNC_COMP_HIGH_ACT ? HIGH : LOW;
+    vmode->gsync = var->sync & FB_SYNC_ON_GREEN ? TRUE : FALSE;
+    vmode->extsync = var->sync & FB_SYNC_EXT ? TRUE : FALSE;
+    vmode->bcast = var->sync & FB_SYNC_BROADCAST ? TRUE : FALSE;
+    vmode->grayscale = var->grayscale;
+    vmode->laced = FALSE;
+    vmode->dblscan = FALSE;
+    switch (var->vmode & FB_VMODE_MASK) {
+	case FB_VMODE_INTERLACED:
+	    vmode->laced = TRUE;
+	    break;
+	case FB_VMODE_DOUBLE:
+	    vmode->dblscan = TRUE;
+	    break;
+    }
+    vmode->red.length = var->red.length;
+    vmode->red.offset = var->red.offset;
+    vmode->green.length = var->green.length;
+    vmode->green.offset = var->green.offset;
+    vmode->blue.length = var->blue.length;
+    vmode->blue.offset = var->blue.offset;
+    vmode->transp.length = var->transp.length;
+    vmode->transp.offset = var->transp.offset;
+    FillScanRates(vmode);
+}
+
+
+static int atoboolean(const char *var)
+{
+    int value = 0;
+
+    if (!strcasecmp(var, "false") || !strcasecmp(var, "low") ||
+	!strcasecmp(var, "no") || !strcasecmp(var, "off") ||
+	!strcmp(var, "0"))
+	value = 0;
+    else if (!strcasecmp(var, "true") || !strcasecmp(var, "high") ||
+	     !strcasecmp(var, "yes") || !strcasecmp(var, "on") ||
+	     !strcmp(var, "1"))
+	value = 1;
+    else
+	Die("Invalid value `%s'\n", var);
+
+    return value;
+}
+
+
+void AddVideoMode(const struct VideoMode *vmode)
+{
+    struct VideoMode *vmode2;
+
+    if (FindVideoMode(vmode->name))
+	Die("%s:%d: Duplicate mode name `%s'\n", Opt_modedb, line,
+	    vmode->name);
+    vmode2 = malloc(sizeof(struct VideoMode));
+    *vmode2 = *vmode;
+    if (!FillScanRates(vmode2))
+	Die("%s:%d: Bad video mode `%s'\n", Opt_modedb, line, vmode2->name);
+    vmode2->next = VideoModes;
+    VideoModes = vmode2;
+}
+
+
+    /*
+     *  Read the Video Mode Database
+     */
+
+static void ReadModeDB(void)
+{
+    if (Opt_verbose)
+	printf("Reading mode database from file `%s'\n", Opt_modedb);
+
+    if (!(yyin = fopen(Opt_modedb, "r")))
+	Die("fopen %s: %s\n", Opt_modedb, strerror(errno));
+    yyparse();
+    fclose(yyin);
+}
+
+
+static void getColor(struct color *color, const char** opt)
+{
+    char* ptr;
+
+    color->length = 0;
+    color->offset = 0;
+    ptr = (char*)(*opt);
+    if (!ptr)
+	return;
+    color->length = strtoul(ptr, &ptr, 0);
+    if (!ptr)
+	return;
+    if (*ptr == '/')
+	color->offset = strtoul(ptr+1, &ptr, 0);
+    if (ptr) {
+	while (*ptr && isspace(*ptr))
+	    ptr++;
+	if (*ptr == ',') {
+	    ptr++;
+	} else if (*ptr)
+	    Die("Bad RGBA syntax, rL/rO,gL/gO,bL/bO,tL/tO or rL,gL,bL,tL\n");
+    }
+    *opt = ptr;
+    return;
+}
+
+void makeRGBA(struct VideoMode *vmode, const char* opt)
+{
+    getColor(&vmode->red, &opt);
+    getColor(&vmode->green, &opt);
+    getColor(&vmode->blue, &opt);
+    getColor(&vmode->transp, &opt);
+}
+
+    /*
+     *  Find a Video Mode
+     */
+
+static struct VideoMode *FindVideoMode(const char *name)
+{
+    struct VideoMode *vmode;
+
+    for (vmode = VideoModes; vmode; vmode = vmode->next)
+	if (!strcmp(name, vmode->name))
+	    break;
+
+    return vmode;
+}
+
+
+    /*
+     *  Modify a Video Mode
+     */
+
+static void ModifyVideoMode(struct VideoMode *vmode)
+{
+    u_int hstep = 8, vstep = 2;
+
+    if (Opt_xres)
+	vmode->xres = strtoul(Opt_xres, NULL, 0);
+    if (Opt_yres)
+	vmode->yres = strtoul(Opt_yres, NULL, 0);
+    if (Opt_vxres)
+	vmode->vxres = strtoul(Opt_vxres, NULL, 0);
+    if (Opt_vyres)
+	vmode->vyres = strtoul(Opt_vyres, NULL, 0);
+    if (Opt_depth)
+	vmode->depth = strtoul(Opt_depth, NULL, 0);
+    if (Opt_nonstd)
+	vmode->nonstd = strtoul(Opt_nonstd, NULL, 0);
+    if (Opt_accel)
+	vmode->accel_flags = atoboolean(Opt_accel) ? FB_ACCELF_TEXT : 0;
+    if (Opt_pixclock)
+	vmode->pixclock = strtoul(Opt_pixclock, NULL, 0);
+    if (Opt_left)
+	vmode->left = strtoul(Opt_left, NULL, 0);
+    if (Opt_right)
+	vmode->right = strtoul(Opt_right, NULL, 0);
+    if (Opt_upper)
+	vmode->upper = strtoul(Opt_upper, NULL, 0);
+    if (Opt_lower)
+	vmode->lower = strtoul(Opt_lower, NULL, 0);
+    if (Opt_hslen)
+	vmode->hslen = strtoul(Opt_hslen, NULL, 0);
+    if (Opt_vslen)
+	vmode->vslen = strtoul(Opt_vslen, NULL, 0);
+    if (Opt_hsync)
+	vmode->hsync = atoboolean(Opt_hsync);
+    if (Opt_vsync)
+	vmode->vsync = atoboolean(Opt_vsync);
+    if (Opt_csync)
+	vmode->csync = atoboolean(Opt_csync);
+    if (Opt_gsync)
+	vmode->gsync = atoboolean(Opt_gsync);
+    if (Opt_extsync)
+	vmode->extsync = atoboolean(Opt_extsync);
+    if (Opt_bcast)
+	vmode->bcast = atoboolean(Opt_bcast);
+    if (Opt_laced)
+	vmode->laced = atoboolean(Opt_laced);
+    if (Opt_double)
+	vmode->dblscan = atoboolean(Opt_double);
+    if (Opt_grayscale)
+	vmode->grayscale = atoboolean(Opt_grayscale);
+    if (Opt_step)
+	hstep = vstep = strtoul(Opt_step, NULL, 0);
+    if (Opt_matchyres)
+        vmode->vyres = vmode->yres;
+    if (Opt_move) {
+	if (!strcasecmp(Opt_move, "left")) {
+	    if (hstep > vmode->left)
+		Die("The left margin cannot be negative\n");
+	    vmode->left -= hstep;
+	    vmode->right += hstep;
+	} else if (!strcasecmp(Opt_move, "right")) {
+	    if (hstep > vmode->right)
+		Die("The right margin cannot be negative\n");
+	    vmode->left += hstep;
+	    vmode->right -= hstep;
+	} else if (!strcasecmp(Opt_move, "up")) {
+	    if (vstep > vmode->upper)
+		Die("The upper margin cannot be negative\n");
+	    vmode->upper -= vstep;
+	    vmode->lower += vstep;
+	} else if (!strcasecmp(Opt_move, "down")) {
+	    if (vstep > vmode->lower)
+		Die("The lower margin cannot be negative\n");
+	    vmode->upper += vstep;
+	    vmode->lower -= vstep;
+	} else
+	    Die("Invalid direction `%s'\n", Opt_move);
+    }
+    if (Opt_rgba) {
+	makeRGBA(vmode, Opt_rgba);
+    }
+    if (!FillScanRates(vmode))
+	Die("Bad video mode\n");
+}
+
+
+    /*
+     *  Display the Video Mode Information
+     */
+
+static void DisplayVModeInfo(struct VideoMode *vmode)
+{
+    u_int res, sstart, send, total;
+
+    puts("");
+    if (!Opt_xfree86) {
+	printf("mode \"%dx%d", vmode->xres, vmode->yres);
+	if (vmode->pixclock) {
+	    printf("-%d\"\n", (int)(vmode->vrate+0.5));
+	    printf("    # D: %5.3f MHz, H: %5.3f kHz, V: %5.3f Hz\n",
+		   vmode->drate/1E6, vmode->hrate/1E3, vmode->vrate);
+	} else
+	    puts("\"");
+	printf("    geometry %d %d %d %d %d\n", vmode->xres, vmode->yres,
+	       vmode->vxres, vmode->vyres, vmode->depth);
+	printf("    timings %d %d %d %d %d %d %d\n", vmode->pixclock,
+	       vmode->left, vmode->right, vmode->upper, vmode->lower,
+	       vmode->hslen, vmode->vslen);
+	if (vmode->hsync)
+	    puts("    hsync high");
+	if (vmode->vsync)
+	    puts("    vsync high");
+	if (vmode->csync)
+	    puts("    csync high");
+	if (vmode->gsync)
+	    puts("    gsync true");
+	if (vmode->extsync)
+	    puts("    extsync true");
+	if (vmode->bcast)
+	    puts("    bcast true");
+	if (vmode->laced)
+	    puts("    laced true");
+	if (vmode->dblscan)
+	    puts("    double true");
+	if (vmode->nonstd)
+            printf("    nonstd %u\n", vmode->nonstd);
+	if (vmode->accel_flags)
+	    puts("    accel true");
+	if (vmode->grayscale)
+	    puts("    grayscale true");
+	printf("    rgba %u/%u,%u/%u,%u/%u,%u/%u\n",
+	    vmode->red.length, vmode->red.offset, vmode->green.length,
+	    vmode->green.offset, vmode->blue.length, vmode->blue.offset,
+	    vmode->transp.length, vmode->transp.offset);
+	puts("endmode\n");
+    } else {
+	printf("Mode \"%dx%d\"\n", vmode->xres, vmode->yres);
+	if (vmode->pixclock) {
+	    printf("    # D: %5.3f MHz, H: %5.3f kHz, V: %5.3f Hz\n",
+		   vmode->drate/1E6, vmode->hrate/1E3, vmode->vrate);
+	    printf("    DotClock %5.3f\n", vmode->drate/1E6+0.001);
+	} else
+	    puts("    DotClock Unknown");
+	res = vmode->xres;
+	sstart = res+vmode->right;
+	send = sstart+vmode->hslen;
+	total = send+vmode->left;
+	printf("    HTimings %d %d %d %d\n", res, sstart, send, total);
+	res = vmode->yres;
+	sstart = res+vmode->lower;
+	send = sstart+vmode->vslen;
+	total = send+vmode->upper;
+	printf("    VTimings %d %d %d %d\n", res, sstart, send, total);
+	printf("    Flags   ");
+	if (vmode->laced)
+	    printf(" \"Interlace\"");
+	if (vmode->dblscan)
+	    printf(" \"DoubleScan\"");
+	if (vmode->hsync)
+	    printf(" \"+HSync\"");
+	else
+	    printf(" \"-HSync\"");
+	if (vmode->vsync)
+	    printf(" \"+VSync\"");
+	else
+	    printf(" \"-VSync\"");
+	if (vmode->csync)
+	    printf(" \"Composite\"");
+	if (vmode->extsync)
+	    puts("    # Warning: XFree86 doesn't support extsync\n");
+	if (vmode->bcast)
+	    printf(" \"bcast\"");
+	if (vmode->accel_flags)
+	    puts("    # Warning: XFree86 doesn't support accel\n");
+	if (vmode->grayscale)
+	    puts("    # Warning: XFree86 doesn't support grayscale\n");
+	puts("\nEndMode\n");
+    }
+}
+
+
+    /*
+     *  Display the Frame Buffer Device Information
+     */
+
+static void DisplayFBInfo(struct fb_fix_screeninfo *fix)
+{
+    int i;
+
+    puts("Frame buffer device information:");
+    printf("    Name        : %s\n", fix->id);
+    printf("    Address     : %p\n", fix->smem_start);
+    printf("    Size        : %d\n", fix->smem_len);
+    printf("    Type        : ");
+    switch (fix->type) {
+	case FB_TYPE_PACKED_PIXELS:
+	    puts("PACKED PIXELS");
+	    break;
+	case FB_TYPE_PLANES:
+	    puts("PLANES");
+	    break;
+	case FB_TYPE_INTERLEAVED_PLANES:
+	    printf("INTERLEAVED PLANES (%d bytes interleave)\n",
+		   fix->type_aux);
+	    break;
+	case FB_TYPE_TEXT:
+	    for (i = 0; i < sizeof(Textmodes)/sizeof(*Textmodes); i++)
+		if (fix->type_aux == Textmodes[i].id)
+		    break;
+	    if (i < sizeof(Textmodes)/sizeof(*Textmodes))
+		puts(Textmodes[i].name);
+	    else
+		printf("Unknown text (%d)\n", fix->type_aux);
+	    break;
+	case FB_TYPE_VGA_PLANES:
+	    {
+	    	struct textentry *t;
+		
+		for (t = VGAModes; t->name; t++)
+		    if (fix->type_aux == t->id)
+		    	break;
+		if (t->name)
+		    puts(t->name);
+		else
+	            printf("Unknown VGA mode (%d)\n", fix->type_aux);
+	    }
+	    break;
+	default:
+	    printf("%d (UNKNOWN)\n", fix->type);
+	    printf("    Type_aux    : %d\n", fix->type_aux);
+	    break;
+    }
+    printf("    Visual      : ");
+    switch (fix->visual) {
+	case FB_VISUAL_MONO01:
+	    puts("MONO01");
+	    break;
+	case FB_VISUAL_MONO10:
+	    puts("MONO10");
+	    break;
+	case FB_VISUAL_TRUECOLOR:
+	    puts("TRUECOLOR");
+	    break;
+	case FB_VISUAL_PSEUDOCOLOR:
+	    puts("PSEUDOCOLOR");
+	    break;
+	case FB_VISUAL_DIRECTCOLOR:
+	    puts("DIRECTCOLOR");
+	    break;
+	case FB_VISUAL_STATIC_PSEUDOCOLOR:
+	    puts("STATIC PSEUDOCOLOR");
+	    break;
+	default:
+	    printf("%d (UNKNOWN)\n", fix->visual);
+	    break;
+    }
+    printf("    XPanStep    : %d\n", fix->xpanstep);
+    printf("    YPanStep    : %d\n", fix->ypanstep);
+    printf("    YWrapStep   : %d\n", fix->ywrapstep);
+    printf("    LineLength  : %d\n", fix->line_length);
+    if (fix->mmio_len) {
+	printf("    MMIO Address: %p\n", fix->mmio_start);
+	printf("    MMIO Size   : %d\n", fix->mmio_len);
+    }
+    printf("    Accelerator : ");
+    for (i = 0; i < sizeof(Accelerators)/sizeof(*Accelerators); i++)
+	if (fix->accel == Accelerators[i].id)
+	    break;
+    if (i < sizeof(Accelerators)/sizeof(*Accelerators))
+	puts(Accelerators[i].name);
+    else
+	printf("Unknown (%d)\n", fix->accel);
+}
+
+
+    /*
+     *  Calculate the Scan Rates for a Video Mode
+     */
+
+static int FillScanRates(struct VideoMode *vmode)
+{
+    u_int htotal = vmode->left+vmode->xres+vmode->right+vmode->hslen;
+    u_int vtotal = vmode->upper+vmode->yres+vmode->lower+vmode->vslen;
+
+    if (vmode->dblscan)
+	vtotal <<= 2;
+    else if (!vmode->laced)
+	vtotal <<= 1;
+
+    if (!htotal || !vtotal)
+	return 0;
+
+    if (vmode->pixclock) {
+	vmode->drate = 1E12/vmode->pixclock;
+	vmode->hrate = vmode->drate/htotal;
+	vmode->vrate = vmode->hrate/vtotal*2;
+    } else {
+	vmode->drate = 0;
+	vmode->hrate = 0;
+	vmode->vrate = 0;
+    }
+
+    return 1;
+}
+
+
+    /*
+     *  Print the Usage Template and Exit
+     */
+
+static void Usage(void)
+{
+    puts(VERSION);
+    Die("\nUsage: %s [options] [mode]\n\n"
+	"Valid options:\n"
+	"  General options:\n"
+	"    -h, --help         : display this usage information\n"
+	"    --test             : don't change, just test whether the mode is "
+				 "valid\n"
+	"    -s, --show         : display video mode settings\n"
+	"    -i, --info         : display all frame buffer information\n"
+	"    -v, --verbose      : verbose mode\n"
+	"    -V, --version      : print version information\n"
+	"    -x, --xfree86      : XFree86 compatibility mode\n"
+	"    -a, --all          : change all virtual consoles on this device\n"
+	"  Frame buffer special device nodes:\n"
+	"    -fb <device>       : processed frame buffer device\n"
+	"                         (default is " DEFAULT_FRAMEBUFFER ")\n"
+	"  Video mode database:\n"
+	"    -db <file>         : video mode database file\n"
+	"                         (default is " DEFAULT_MODEDBFILE ")\n"
+	"  Display geometry:\n"
+	"    -xres <value>      : horizontal resolution (in pixels)\n"
+	"    -yres <value>      : vertical resolution (in pixels)\n"
+	"    -vxres <value>     : virtual horizontal resolution (in pixels)\n"
+	"    -vyres <value>     : virtual vertical resolution (in pixels)\n"
+	"    -depth <value>     : display depth (in bits per pixel)\n"
+	"    -nonstd <value>    : select nonstandard video mode\n"
+	"    -g, --geometry ... : set all geometry parameters at once\n"
+	"    -match             : set virtual vertical resolution by virtual resolution\n"
+	"  Display timings:\n"
+	"    -pixclock <value>  : pixel clock (in picoseconds)\n"
+	"    -left <value>      : left margin (in pixels)\n"
+	"    -right <value>     : right margin (in pixels)\n"
+	"    -upper <value>     : upper margin (in pixel lines)\n"
+	"    -lower <value>     : lower margin (in pixel lines)\n"
+	"    -hslen <value>     : horizontal sync length (in pixels)\n"
+	"    -vslen <value>     : vertical sync length (in pixel lines)\n"
+	"    -t, --timings ...  : set all timing parameters at once\n"
+	"  Display flags:\n"
+	"    -accel <value>     : hardware text acceleration enable (false or "
+				 "true)\n"
+	"    -hsync <value>     : horizontal sync polarity (low or high)\n"
+	"    -vsync <value>     : vertical sync polarity (low or high)\n"
+	"    -csync <value>     : composite sync polarity (low or high)\n"
+	"    -gsync <value>     : synch on green (false or true)\n"
+	"    -extsync <value>   : external sync enable (false or true)\n"
+	"    -bcast <value>     : broadcast enable (false or true)\n"
+	"    -laced <value>     : interlace enable (false or true)\n"
+	"    -double <value>    : doublescan enable (false or true)\n"
+	"    -rgba <r,g,b,a>    : recommended length of color entries\n"
+	"    -grayscale <value> : grayscale enable (false or true)\n"
+	"  Display positioning:\n"
+	"    -move <direction>  : move the visible part (left, right, up or "
+				 "down)\n"
+	"    -step <value>      : step increment (in pixels or pixel lines)\n"
+	"                         (default is 8 horizontal, 2 vertical)\n",
+	ProgramName);
+}
+
+
+    /*
+     *  Main Routine
+     */
+
+int main(int argc, char *argv[])
+{
+    struct VideoMode *vmode;
+    struct fb_var_screeninfo var;
+    struct fb_fix_screeninfo fix;
+    int fh = -1, i;
+
+    ProgramName = argv[0];
+
+    /*
+     *  Parse the Options
+     */
+
+    while (--argc > 0) {
+	argv++;
+	if (!strcmp(argv[0], "-h") || !strcmp(argv[0], "--help"))
+	    Usage();
+	else if (!strcmp(argv[0], "-v") || !strcmp(argv[0], "--verbose"))
+	    Opt_verbose = 1;
+	else if (!strcmp(argv[0], "-V") || !strcmp(argv[0], "--version"))
+	    Opt_version = 1;
+	else if (!strcmp(argv[0], "--test"))
+	    Opt_test = 1;
+	else if (!strcmp(argv[0], "-s") || !strcmp(argv[0], "--show"))
+	    Opt_show = 1;
+	else if (!strcmp(argv[0], "-i") || !strcmp(argv[0], "--info")) {
+	    Opt_show = 1;
+	    Opt_info = 1;
+	} else if (!strcmp(argv[0], "-x") || !strcmp(argv[0], "--xfree86"))
+	    Opt_xfree86 = 1;
+	else if (!strcmp(argv[0], "-a") || !strcmp(argv[0], "--all"))
+	    Opt_all = 1;
+	else if (!strcmp(argv[0], "-g") || !strcmp(argv[0], "--geometry")) {
+	    if (argc > 5) {
+		Opt_xres = argv[1];
+		Opt_yres = argv[2];
+		Opt_vxres = argv[3];
+		Opt_vyres = argv[4];
+		Opt_depth = argv[5];
+		Opt_change = 1;
+		argc -= 5;
+		argv += 5;
+	    } else
+		Usage();
+	} else if (!strcmp(argv[0], "-t") || !strcmp(argv[0], "--timings")) {
+	    if (argc > 7) {
+		Opt_pixclock = argv[1];
+		Opt_left = argv[2];
+		Opt_right = argv[3];
+		Opt_upper = argv[4];
+		Opt_lower = argv[5];
+		Opt_hslen = argv[6];
+		Opt_vslen = argv[7];
+		Opt_change = 1;
+		argc -= 7;
+		argv += 7;
+	    } else
+		Usage();
+	} else if (!strcmp(argv[0], "-match")) {
+	    Opt_matchyres = argv[0];
+	    Opt_change = 1;
+	} else {
+	    for (i = 0; Options[i].name; i++)
+		if (!strcmp(argv[0], Options[i].name))
+		    break;
+	    if (Options[i].name) {
+		if (argc-- > 1) {
+		    *Options[i].value = argv[1];
+		    Opt_change |= Options[i].change;
+		    argv++;
+		} else
+		    Usage();
+	    } else if (!Opt_modename) {
+		Opt_modename = argv[0];
+		Opt_change = 1;
+	    } else
+		Usage();
+	}
+    }
+
+    if (Opt_version || Opt_verbose)
+	puts(VERSION);
+
+    if (!Opt_fb)
+	Opt_fb = DEFAULT_FRAMEBUFFER;
+
+    /*
+     *  Open the Frame Buffer Device
+     */
+
+    fh = OpenFrameBuffer(Opt_fb);
+
+    /*
+     *  Get the Video Mode
+     */
+
+    if (Opt_modename) {
+
+	/*
+	 *  Read the Video Mode Database
+	 */
+
+	ReadModeDB();
+
+	if (!(vmode = FindVideoMode(Opt_modename)))
+	    Die("Unknown video mode `%s'\n", Opt_modename);      
+
+	Current = *vmode;
+	if (Opt_verbose)
+	    printf("Using video mode `%s'\n", Opt_modename);
+    } else {
+	GetVarScreenInfo(fh, &var);
+	ConvertToVideoMode(&var, &Current);
+	if (Opt_verbose)
+	    printf("Using current video mode from `%s'\n", Opt_fb);
+    }
+
+    if (Opt_change) {
+
+	/*
+	 *  Optionally Modify the Video Mode
+	 */
+
+	ModifyVideoMode(&Current);
+
+	/*
+	 *  Set the Video Mode
+	 */
+
+	ConvertFromVideoMode(&Current, &var);
+	if (Opt_verbose)
+	    printf("Setting video mode to `%s'\n", Opt_fb);
+	SetVarScreenInfo(fh, &var);
+	ConvertToVideoMode(&var, &Current);
+    }
+
+    /*
+     *  Display some Video Mode Information
+     */
+
+    if (Opt_show || !Opt_change)
+	DisplayVModeInfo(&Current);
+
+    if (Opt_info) {
+	if (Opt_verbose)
+	    puts("Getting further frame buffer information");
+	GetFixScreenInfo(fh, &fix);
+	DisplayFBInfo(&fix);
+    }
+
+    /*
+     *  Close the Frame Buffer Device
+     */
+
+    CloseFrameBuffer(fh);
+
+    exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/fbset/fbset.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,82 @@
+/*
+ *  Linux Frame Buffer Device Configuration
+ *
+ *  © Copyright 1995-1998 by Geert Uytterhoeven
+ *			(Geert.Uytterhoeven@cs.kuleuven.ac.be)
+ *
+ *  --------------------------------------------------------------------------
+ *
+ *  This file is subject to the terms and conditions of the GNU General Public
+ *  License. See the file COPYING in the main directory of the Linux
+ *  distribution for more details.
+ */
+
+
+#include <stdio.h>
+#include <sys/types.h>
+
+#ifdef __GLIBC__
+#include <asm/types.h>
+#endif
+
+#define VERSION         "Linux Frame Buffer Device Configuration " \
+			"Version 2.1 (23/06/1999)\n"  \
+			"(C) Copyright 1995-1999 by Geert Uytterhoeven\n"
+
+#define LOW		(0)
+#define HIGH		(1)
+
+#define FALSE		(0)
+#define TRUE		(1)
+
+struct color {
+    unsigned int length;
+    unsigned int offset;
+};
+
+struct VideoMode {
+    struct VideoMode *next;
+    const char *name;
+    /* geometry */
+    __u32 xres;
+    __u32 yres;
+    __u32 vxres;
+    __u32 vyres;
+    __u32 depth;
+    __u32 nonstd;
+    /* acceleration */
+    __u32 accel_flags;
+    /* timings */
+    __u32 pixclock;
+    __u32 left;
+    __u32 right;
+    __u32 upper;
+    __u32 lower;
+    __u32 hslen;
+    __u32 vslen;
+    /* flags */
+    unsigned hsync : 1;
+    unsigned vsync : 1;
+    unsigned csync : 1;
+    unsigned gsync : 1;
+    unsigned extsync : 1;
+    unsigned bcast : 1;
+    unsigned laced : 1;
+    unsigned dblscan : 1;
+    unsigned grayscale : 1;
+    /* scanrates */
+    double drate;
+    double hrate;
+    double vrate;
+    /* RGB entries */
+    struct color red, green, blue, transp;
+};
+
+extern FILE *yyin;
+extern int line;
+extern const char *Opt_modedb;
+
+extern int yyparse(void);
+extern void Die(const char *fmt, ...) __attribute__ ((noreturn));
+extern void AddVideoMode(const struct VideoMode *vmode);
+extern void makeRGBA(struct VideoMode *vmode, const char* opt);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/fbset/modeline2fb	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,150 @@
+#!/usr/bin/perl
+
+# Simple modeline-to-fb.modes translator
+# (c) 1998 by Patrick Reynolds
+# distributed under the GNU General Public License
+ 
+# mapping of modeline options to fb.modes options
+%options_map = (
+  "-hsync" => "hsync low",
+  "-vsync" => "vsync low",
+  "+hsync" => "hsync high",
+  "+vsync" => "vsync high",
+  "interlace" => "laced true",
+  "doublescan" => "double true"
+);
+
+@possible_vxres = ( 640, 800, 1024, 1152, 1280, 1600, 1920, 2048 );
+
+# default settings (override with -d and -r)
+$depth = 8;
+$rounding = 128;
+
+# parse options
+while ($ARGV[0] =~ /^-/) {
+  $arg = shift;
+  if ($arg eq "-d" || $arg eq "--depth") {
+    if (!($arg = shift @ARGV)) {
+      usage("-d requires an argument");
+    }
+    $depth = $arg;
+  }
+  elsif ($arg eq "-r" || $arg eq "--rounding") {
+    if (!($arg = shift @ARGV)) {
+      usage("-r requires an argument");
+    }
+    $rounding = $arg;
+  }
+  elsif ($arg eq "-x" || $arg eq "--vxres") {
+    if (!($arg = shift @ARGV)) {
+      usage("-x requires an argument");
+    }
+    push @possible_vxres, (split/,/,$arg);
+    @possible_vxres = sort { $a <=> $b } @possible_vxres;
+    print "new vxres: " . (join ",", @possible_vxres) . "\n";
+  }
+  elsif ($arg eq "-h" || $arg eq "--help") {
+    usage();
+  }
+  else {
+    usage("unknown option: $arg");
+  }
+}
+
+# find out how much video memory is available
+open(FBSET, "fbset -i|") || die "could not detect available video memory";
+while (<FBSET>) {
+  if (/Size\s*:\s*(\d+)/) {
+    $size = $1;
+    last;
+  }
+}
+if (!$size) { die "could not detect available video memory"; }
+
+# huge kludge (hey, that rhymes!) ...
+#   subtract 16384 from the available memory $size
+#   why?  the default 640x480 mode uses all but 16384, and when I set it
+#   to use more than that, it oopses (!).  So... for safety's sake, and
+#   because you probably don't use those 15-25 lines anyway...
+$size -= 16384;
+
+print "# modes.fb - video mode descriptions for fbset
+#
+# See fbset(8) and fb.modes(5) for more information
+
+";
+
+$flag = 0;
+# read all XF86Config files
+while(<>) {
+  chomp;
+  next if !(($name, $clock, $xres, $xsyncstart, $xsyncend, $xfres,
+                  $yres, $ysyncstart, $ysyncend, $yfres, $extra) =
+    /^\s*modeline\s+"([^"]+)"\s+([0-9.]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*(.*)$/i);
+  $flag = 1;
+
+  # timing transformations, as described in the fb HOWTO
+  $pixtime = int(1000000/$clock);
+  $left = $xfres - $xsyncend;
+  $right = $xsyncstart - $xres;
+  $hsynclen = $xsyncend - $xsyncstart;
+  $top = $yfres - $ysyncend;
+  $bottom = $ysyncstart - $yres;
+  $vsynclen = $ysyncend - $ysyncstart;
+
+  # pick a virtual X and Y resolution
+  $vxres = get_vxres($xres);
+  if ($vxres < 0) {
+    print STDERR "Could not guess a good virtual resolution for mode $name.\n";
+    print STDERR "Use the advanced options --rounding and --vxres.\n";
+    next;
+  }
+  $vyres = int($size/$vxres);
+
+  # print out our entry
+  print "mode \"$name\"\n";
+  print "  geometry   $xres $yres   $vxres $vyres   $depth\n";
+  print "  timings    $pixtime   $left $right   $top $bottom   $hsynclen $vsynclen\n";
+
+  # handle extra options at the end of the modeline
+  $extra =~ tr/A-Z/a-z/;
+  @options = split/\s+/,$extra;
+  foreach (@options) {
+    if ($options_map{$_}) {
+      print "  $options_map{$_}\n";
+    }
+    else {
+      print "  # unknown option: $_\n";
+    }
+  }
+  print "endmode\n\n";
+}
+
+if (!$flag) {
+  print STDERR "No modelines found.\n";
+  print STDERR "Make sure the file you specified was an XF86Config file and\n";
+  print STDERR "used the single-line Modeline format.\n\n";
+  print STDERR "Use \"$0 --help\" for help.\n";
+}
+
+sub get_vxres {
+  foreach (@possible_vxres) {
+    return $_ if ($_ >= $_[0] && ($_ % $rounding) == 0);
+  }
+  return -1;
+}
+
+sub usage {
+  print STDERR "$_[0]\n" if ($_[0]);
+  print STDERR "$0 [OPTION] [FILES]\n\n";
+  print STDERR "  -d,--depth depth     use a certain display depth (default is 8)\n";
+  print STDERR "  -h,--help            what you see here\n\n";
+  print STDERR "Advanced options:\n";
+  print STDERR "  -r,--rounding div    vxres divisor (default is 128)\n";
+  print STDERR "  -x,--vxres X,X,X,... extra possible vxres values\n\n";
+  print STDERR "[FILES] refers to one or more XF86Config files.  Note that\n";
+  print STDERR "all modelines must be in single-line format.\n\n";
+  print STDERR "Example:\n";
+  print STDERR "  $0 -d 16 /etc/X11/XF86Config\n";
+  exit 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/fbset/modes.l	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,136 @@
+
+/*
+ *  Linux Frame Buffer Device Configuration
+ *
+ *  © Copyright 1995-1998 by Geert Uytterhoeven
+ *		       (Geert.Uytterhoeven@cs.kuleuven.ac.be)
+ *
+ *  --------------------------------------------------------------------------
+ *
+ *  This file is subject to the terms and conditions of the GNU General Public
+ *  License. See the file COPYING in the main directory of the Linux
+ *  distribution for more details.
+ */
+
+
+%{
+
+#define YYSTYPE		long
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "fbset.h"
+#include "modes.tab.h"
+
+struct keyword {
+    const char *name;
+    int token;
+    int value;
+};
+
+static struct keyword keywords[] = {
+    { "mode", MODE, 0 },
+    { "geometry", GEOMETRY, 0 },
+    { "timings", TIMINGS, 0 },
+    { "hsync", HSYNC, 0 },
+    { "vsync", VSYNC, 0 },
+    { "csync", CSYNC, 0 },
+    { "gsync", GSYNC, 0 },
+    { "extsync", EXTSYNC, 0 },
+    { "bcast", BCAST, 0 },
+    { "laced", LACED, 0 },
+    { "double", DOUBLE, 0 },
+    { "rgba", RGBA, 0 },
+    { "nonstd", NONSTD, 0 },
+    { "accel", ACCEL, 0 },
+    { "grayscale", GRAYSCALE, 0 },
+    { "endmode", ENDMODE, 0 },
+    { "low", POLARITY, LOW },
+    { "high", POLARITY, HIGH },
+    { "false", BOOLEAN, FALSE },
+    { "true", BOOLEAN, TRUE },
+    { "", -1, 0 }
+};
+
+int line = 1;
+
+
+void yyerror(const char *s)
+{
+    Die("%s:%d: %s\n", Opt_modedb, line, s);
+}
+
+
+int yywrap(void)
+{
+    return 1;
+}
+
+
+static int FindToken(const char *s)
+{
+    int i;
+
+    for (i = 0; keywords[i].token > 0; i++)
+	if (!strcasecmp(s, keywords[i].name)) {
+	    yylval = keywords[i].value;
+	    return keywords[i].token;
+	}
+    Die("%s:%d: Unknown keyword `%s'\n", Opt_modedb, line, s);
+}
+
+
+static const char *CopyString(const char *s)
+{
+    int len;
+    char *s2;
+
+    len = strlen(s)-2;
+    if (!(s2 = malloc(len+1)))
+	Die("No memory\n");
+    strncpy(s2, s+1, len);
+    s2[len] = '\0';
+    return s2;
+}
+
+
+%}
+
+keyword	[a-zA-Z][a-zA-Z0-9]*
+number	[0-9]*
+string	\"[^\"\n]*\"
+comment	\#([^\n]*)
+space	[ \t]+
+junk	.
+
+%%
+
+{keyword}   {
+		return FindToken(yytext);
+	    }
+
+{number}    {
+		yylval = strtoul(yytext, NULL, 0);
+		return NUMBER;
+	    }
+
+{string}    {
+		yylval = (unsigned long)CopyString(yytext);
+		return STRING;
+	    }
+
+{comment}$  break;
+
+{space}	    break;
+
+\n	    {
+		line++;
+		break;
+	    }
+
+{junk}	    {
+		Die("%s:%d: Invalid token `%s'\n", Opt_modedb, line, yytext);
+	    }
+
+%%
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/fbset/modes.y	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,175 @@
+/*
+ *  Linux Frame Buffer Device Configuration
+ *
+ *  © Copyright 1995-1998 by Geert Uytterhoeven
+ *		       (Geert.Uytterhoeven@cs.kuleuven.ac.be)
+ *
+ *  --------------------------------------------------------------------------
+ *
+ *  This file is subject to the terms and conditions of the GNU General Public
+ *  License. See the file COPYING in the main directory of the Linux
+ *  distribution for more details.
+ */
+
+
+%{
+
+#define YYSTYPE		long
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "fb.h"
+#include "fbset.h"
+
+extern int yylex(void);
+extern void yyerror(const char *s);
+extern int line;
+
+
+static struct VideoMode VideoMode;
+
+static void ClearVideoMode(void)
+{
+    memset(&VideoMode, 0, sizeof(VideoMode));
+    VideoMode.accel_flags = FB_ACCELF_TEXT;
+}
+
+%}
+
+%start file
+
+%token MODE GEOMETRY TIMINGS HSYNC VSYNC CSYNC GSYNC EXTSYNC BCAST LACED DOUBLE
+       RGBA NONSTD ACCEL GRAYSCALE
+       ENDMODE POLARITY BOOLEAN STRING NUMBER 
+
+%%
+
+file	  : vmodes
+	  ;
+
+
+vmodes	  : /* empty */
+	  | vmodes vmode
+	  ;
+
+vmode	  : MODE STRING geometry timings options ENDMODE
+	    {
+		VideoMode.name = (const char *)$2;
+		AddVideoMode(&VideoMode);
+		ClearVideoMode();
+	    }
+	  ;
+
+geometry  : GEOMETRY NUMBER NUMBER NUMBER NUMBER NUMBER
+	    {
+		ClearVideoMode();
+		VideoMode.xres = $2;
+		VideoMode.yres = $3;
+		VideoMode.vxres = $4;
+		VideoMode.vyres = $5;
+		VideoMode.depth = $6;
+	    }
+	  ;
+
+timings	  : TIMINGS NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER
+	    {
+		VideoMode.pixclock = $2;
+		VideoMode.left = $3;
+		VideoMode.right = $4;
+		VideoMode.upper = $5;
+		VideoMode.lower = $6;
+		VideoMode.hslen = $7;
+		VideoMode.vslen = $8;
+	    }
+	  ;
+
+options	  : /* empty */
+	  | options hsync
+	  | options vsync
+	  | options csync
+	  | options gsync
+	  | options extsync
+	  | options bcast
+	  | options laced
+	  | options double
+	  | options rgba
+	  | options nonstd
+	  | options accel
+	  | options grayscale
+	  ;
+
+hsync	  : HSYNC POLARITY
+	    {
+		VideoMode.hsync = $2;
+	    }
+	  ;
+
+vsync	  : VSYNC POLARITY
+	    {
+		VideoMode.vsync = $2;
+	    }
+	  ;
+
+csync	  : CSYNC POLARITY
+	    {
+		VideoMode.csync = $2;
+	    }
+	  ;
+
+gsync	  : GSYNC POLARITY
+	    {
+		VideoMode.gsync = $2;
+	    }
+	  ;
+
+extsync	  : EXTSYNC BOOLEAN
+	    {
+		VideoMode.extsync = $2;
+	    }
+	  ;
+
+bcast	  : BCAST BOOLEAN
+	    {
+		VideoMode.bcast = $2;
+	    }
+	  ;
+
+laced	  : LACED BOOLEAN
+	    {
+		VideoMode.laced = $2;
+	    }
+	  ;
+
+double	  : DOUBLE BOOLEAN
+	    {
+		VideoMode.dblscan = $2;
+	    }
+	  ;
+
+rgba      : RGBA STRING
+            {
+		makeRGBA(&VideoMode, (const char*)$2);
+	    }
+	  ;
+
+nonstd    : NONSTD NUMBER
+            {
+	    	VideoMode.nonstd = $2;
+	    }
+	  ;
+
+accel	  : ACCEL BOOLEAN
+	    {
+		VideoMode.accel_flags = $2;
+	    }
+	  ;
+
+grayscale : GRAYSCALE BOOLEAN
+	    {
+		VideoMode.grayscale = $2;
+	    }
+	  ;
+	  
+%%
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/independ	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,16 @@
+
+# SETUP TVout
+# Independent picture on TV and Monitor
+
+# CRTC1 -> TVout
+matroxset/matroxset -f /dev/fb0 -m 2
+
+# CRTC2 -> Monitor
+matroxset/matroxset -f /dev/fb1 -m 1
+
+# Enable TV
+matroxset/matroxset 1
+
+# move tty1-2 to CRTC2
+con2fb/con2fb /dev/fb1 /dev/tty1
+con2fb/con2fb /dev/fb1 /dev/tty2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/matroxset/Makefile	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,10 @@
+CFLAGS = -O2 -W -Wall
+
+all: matroxset
+
+matrox:	matroxset.o
+
+matroxset.o:	matroxset.c
+
+clean:
+	-rm *.o matroxset
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/matroxset/fb.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,502 @@
+#ifndef _LINUX_FB_H
+#define _LINUX_FB_H
+
+#include <linux/tty.h>
+#include <asm/types.h>
+
+/* Definitions of frame buffers						*/
+
+#define FB_MAJOR		29
+#define FB_MAX			32	/* sufficient for now */
+
+/* ioctls
+   0x46 is 'F'								*/
+#define FBIOGET_VSCREENINFO	0x4600
+#define FBIOPUT_VSCREENINFO	0x4601
+#define FBIOGET_FSCREENINFO	0x4602
+#define FBIOGETCMAP		0x4604
+#define FBIOPUTCMAP		0x4605
+#define FBIOPAN_DISPLAY		0x4606
+/* 0x4607-0x460B are defined below */
+/* #define FBIOGET_MONITORSPEC	0x460C */
+/* #define FBIOPUT_MONITORSPEC	0x460D */
+/* #define FBIOSWITCH_MONIBIT	0x460E */
+#define FBIOGET_CON2FBMAP	0x460F
+#define FBIOPUT_CON2FBMAP	0x4610
+#define FBIOBLANK		0x4611		/* arg: 0 or vesa level + 1 */
+#define FBIOGET_VBLANK		_IOR('F', 0x12, struct fb_vblank)
+
+/* next 2 lines are temporary solution, support in 2.5 will be different */
+#define FBIOGET_VT_VSCREENINFO	0x4680
+#define FBIOPUT_VT_VSCREENINFO	0x4681
+
+
+#define FB_TYPE_PACKED_PIXELS		0	/* Packed Pixels	*/
+#define FB_TYPE_PLANES			1	/* Non interleaved planes */
+#define FB_TYPE_INTERLEAVED_PLANES	2	/* Interleaved planes	*/
+#define FB_TYPE_TEXT			3	/* Text/attributes	*/
+#define FB_TYPE_VGA_PLANES		4	/* EGA/VGA planes	*/
+
+#define FB_AUX_TEXT_MDA		0	/* Monochrome text */
+#define FB_AUX_TEXT_CGA		1	/* CGA/EGA/VGA Color text */
+#define FB_AUX_TEXT_S3_MMIO	2	/* S3 MMIO fasttext */
+#define FB_AUX_TEXT_MGA_STEP16	3	/* MGA Millenium I: text, attr, 14 reserved bytes */
+#define FB_AUX_TEXT_MGA_STEP8	4	/* other MGAs:      text, attr,  6 reserved bytes */
+
+#define FB_AUX_VGA_PLANES_VGA4		0	/* 16 color planes (EGA/VGA) */
+#define FB_AUX_VGA_PLANES_CFB4		1	/* CFB4 in planes (VGA) */
+#define FB_AUX_VGA_PLANES_CFB8		2	/* CFB8 in planes (VGA) */
+
+#define FB_VISUAL_MONO01		0	/* Monochr. 1=Black 0=White */
+#define FB_VISUAL_MONO10		1	/* Monochr. 1=White 0=Black */
+#define FB_VISUAL_TRUECOLOR		2	/* True color	*/
+#define FB_VISUAL_PSEUDOCOLOR		3	/* Pseudo color (like atari) */
+#define FB_VISUAL_DIRECTCOLOR		4	/* Direct color */
+#define FB_VISUAL_STATIC_PSEUDOCOLOR	5	/* Pseudo color readonly */
+
+#define FB_ACCEL_NONE		0	/* no hardware accelerator	*/
+#define FB_ACCEL_ATARIBLITT	1	/* Atari Blitter		*/
+#define FB_ACCEL_AMIGABLITT	2	/* Amiga Blitter                */
+#define FB_ACCEL_S3_TRIO64	3	/* Cybervision64 (S3 Trio64)    */
+#define FB_ACCEL_NCR_77C32BLT	4	/* RetinaZ3 (NCR 77C32BLT)      */
+#define FB_ACCEL_S3_VIRGE	5	/* Cybervision64/3D (S3 ViRGE)	*/
+#define FB_ACCEL_ATI_MACH64GX	6	/* ATI Mach 64GX family		*/
+#define FB_ACCEL_DEC_TGA	7	/* DEC 21030 TGA		*/
+#define FB_ACCEL_ATI_MACH64CT	8	/* ATI Mach 64CT family		*/
+#define FB_ACCEL_ATI_MACH64VT	9	/* ATI Mach 64CT family VT class */
+#define FB_ACCEL_ATI_MACH64GT	10	/* ATI Mach 64CT family GT class */
+#define FB_ACCEL_SUN_CREATOR	11	/* Sun Creator/Creator3D	*/
+#define FB_ACCEL_SUN_CGSIX	12	/* Sun cg6			*/
+#define FB_ACCEL_SUN_LEO	13	/* Sun leo/zx			*/
+#define FB_ACCEL_IMS_TWINTURBO	14	/* IMS Twin Turbo		*/
+#define FB_ACCEL_3DLABS_PERMEDIA2 15	/* 3Dlabs Permedia 2		*/
+#define FB_ACCEL_MATROX_MGA2064W 16	/* Matrox MGA2064W (Millenium)	*/
+#define FB_ACCEL_MATROX_MGA1064SG 17	/* Matrox MGA1064SG (Mystique)	*/
+#define FB_ACCEL_MATROX_MGA2164W 18	/* Matrox MGA2164W (Millenium II) */
+#define FB_ACCEL_MATROX_MGA2164W_AGP 19	/* Matrox MGA2164W (Millenium II) */
+#define FB_ACCEL_MATROX_MGAG100	20	/* Matrox G100 (Productiva G100) */
+#define FB_ACCEL_MATROX_MGAG200	21	/* Matrox G200 (Myst, Mill, ...) */
+#define FB_ACCEL_SUN_CG14	22	/* Sun cgfourteen		 */
+#define FB_ACCEL_SUN_BWTWO	23	/* Sun bwtwo			*/
+#define FB_ACCEL_SUN_CGTHREE	24	/* Sun cgthree			*/
+#define FB_ACCEL_SUN_TCX	25	/* Sun tcx			*/
+#define FB_ACCEL_MATROX_MGAG400	26	/* Matrox G400			*/
+#define FB_ACCEL_NV3		27	/* nVidia RIVA 128              */
+#define FB_ACCEL_NV4		28	/* nVidia RIVA TNT		*/
+#define FB_ACCEL_NV5		29	/* nVidia RIVA TNT2		*/
+#define FB_ACCEL_CT_6555x	30	/* C&T 6555x			*/
+#define FB_ACCEL_3DFX_BANSHEE	31	/* 3Dfx Banshee			*/
+#define FB_ACCEL_ATI_RAGE128	32	/* ATI Rage128 family		*/
+
+struct fb_fix_screeninfo {
+	char id[16];			/* identification string eg "TT Builtin" */
+	unsigned long smem_start;	/* Start of frame buffer mem */
+					/* (physical address) */
+	__u32 smem_len;			/* Length of frame buffer mem */
+	__u32 type;			/* see FB_TYPE_*		*/
+	__u32 type_aux;			/* Interleave for interleaved Planes */
+	__u32 visual;			/* see FB_VISUAL_*		*/ 
+	__u16 xpanstep;			/* zero if no hardware panning  */
+	__u16 ypanstep;			/* zero if no hardware panning  */
+	__u16 ywrapstep;		/* zero if no hardware ywrap    */
+	__u32 line_length;		/* length of a line in bytes    */
+	unsigned long mmio_start;	/* Start of Memory Mapped I/O   */
+					/* (physical address) */
+	__u32 mmio_len;			/* Length of Memory Mapped I/O  */
+	__u32 accel;			/* Type of acceleration available */
+	__u16 reserved[3];		/* Reserved for future compatibility */
+};
+
+/* Interpretation of offset for color fields: All offsets are from the right,
+ * inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you
+ * can use the offset as right argument to <<). A pixel afterwards is a bit
+ * stream and is written to video memory as that unmodified. This implies
+ * big-endian byte order if bits_per_pixel is greater than 8.
+ */
+struct fb_bitfield {
+	__u32 offset;			/* beginning of bitfield	*/
+	__u32 length;			/* length of bitfield		*/
+	__u32 msb_right;		/* != 0 : Most significant bit is */ 
+					/* right */ 
+};
+
+#define FB_NONSTD_HAM		1	/* Hold-And-Modify (HAM)        */
+
+#define FB_ACTIVATE_NOW		0	/* set values immediately (or vbl)*/
+#define FB_ACTIVATE_NXTOPEN	1	/* activate on next open	*/
+#define FB_ACTIVATE_TEST	2	/* don't set, round up impossible */
+#define FB_ACTIVATE_MASK       15
+					/* values			*/
+#define FB_ACTIVATE_VBL	       16	/* activate values on next vbl  */
+#define FB_CHANGE_CMAP_VBL     32	/* change colormap on vbl	*/
+#define FB_ACTIVATE_ALL	       64	/* change all VCs on this fb	*/
+
+#define FB_ACCELF_TEXT		1	/* text mode acceleration */
+
+#define FB_SYNC_HOR_HIGH_ACT	1	/* horizontal sync high active	*/
+#define FB_SYNC_VERT_HIGH_ACT	2	/* vertical sync high active	*/
+#define FB_SYNC_EXT		4	/* external sync		*/
+#define FB_SYNC_COMP_HIGH_ACT	8	/* composite sync high active   */
+#define FB_SYNC_BROADCAST	16	/* broadcast video timings      */
+					/* vtotal = 144d/288n/576i => PAL  */
+					/* vtotal = 121d/242n/484i => NTSC */
+#define FB_SYNC_ON_GREEN	32	/* sync on green */
+
+#define FB_VMODE_NONINTERLACED  0	/* non interlaced */
+#define FB_VMODE_INTERLACED	1	/* interlaced	*/
+#define FB_VMODE_DOUBLE		2	/* double scan */
+#define FB_VMODE_MASK		255
+
+#define FB_VMODE_YWRAP		256	/* ywrap instead of panning     */
+#define FB_VMODE_SMOOTH_XPAN	512	/* smooth xpan possible (internally used) */
+#define FB_VMODE_CONUPDATE	512	/* don't update x/yoffset	*/
+
+struct fb_var_screeninfo {
+	__u32 xres;			/* visible resolution		*/
+	__u32 yres;
+	__u32 xres_virtual;		/* virtual resolution		*/
+	__u32 yres_virtual;
+	__u32 xoffset;			/* offset from virtual to visible */
+	__u32 yoffset;			/* resolution			*/
+
+	__u32 bits_per_pixel;		/* guess what			*/
+	__u32 grayscale;		/* != 0 Graylevels instead of colors */
+
+	struct fb_bitfield red;		/* bitfield in fb mem if true color, */
+	struct fb_bitfield green;	/* else only length is significant */
+	struct fb_bitfield blue;
+	struct fb_bitfield transp;	/* transparency			*/	
+
+	__u32 nonstd;			/* != 0 Non standard pixel format */
+
+	__u32 activate;			/* see FB_ACTIVATE_*		*/
+
+	__u32 height;			/* height of picture in mm    */
+	__u32 width;			/* width of picture in mm     */
+
+	__u32 accel_flags;		/* acceleration flags (hints)	*/
+
+	/* Timing: All values in pixclocks, except pixclock (of course) */
+	__u32 pixclock;			/* pixel clock in ps (pico seconds) */
+	__u32 left_margin;		/* time from sync to picture	*/
+	__u32 right_margin;		/* time from picture to sync	*/
+	__u32 upper_margin;		/* time from sync to picture	*/
+	__u32 lower_margin;
+	__u32 hsync_len;		/* length of horizontal sync	*/
+	__u32 vsync_len;		/* length of vertical sync	*/
+	__u32 sync;			/* see FB_SYNC_*		*/
+	__u32 vmode;			/* see FB_VMODE_*		*/
+	__u32 reserved[6];		/* Reserved for future compatibility */
+};
+
+struct fb_cmap {
+	__u32 start;			/* First entry	*/
+	__u32 len;			/* Number of entries */
+	__u16 *red;			/* Red values	*/
+	__u16 *green;
+	__u16 *blue;
+	__u16 *transp;			/* transparency, can be NULL */
+};
+
+struct fb_con2fbmap {
+	__u32 console;
+	__u32 framebuffer;
+};
+
+/* VESA Blanking Levels */
+#define VESA_NO_BLANKING        0
+#define VESA_VSYNC_SUSPEND      1
+#define VESA_HSYNC_SUSPEND      2
+#define VESA_POWERDOWN          3
+
+struct fb_monspecs {
+	__u32 hfmin;			/* hfreq lower limit (Hz) */
+	__u32 hfmax; 			/* hfreq upper limit (Hz) */
+	__u16 vfmin;			/* vfreq lower limit (Hz) */
+	__u16 vfmax;			/* vfreq upper limit (Hz) */
+	unsigned dpms : 1;		/* supports DPMS */
+};
+
+/* next structure is only 2.2 temporary hack, 2.3 solution will be different */
+struct fb_vt_info {
+	__u32 console;
+	struct fb_var_screeninfo *info;
+};
+
+#define FB_VBLANK_VBLANKING     1       /* currently in a vertical blank */
+#define FB_VBLANK_HBLANKING     2       /* currently in a horizontal blank */
+#define FB_VBLANK_HAVE_VBLANK   4       /* vertical blanks can be detected */
+#define FB_VBLANK_HAVE_HBLANK   8       /* horizontal blanks can be detected */
+#define FB_VBLANK_HAVE_COUNT    16      /* global retrace counter is available */
+#define FB_VBLANK_HAVE_VCOUNT   32      /* the vcount field is valid */
+#define FB_VBLANK_HAVE_HCOUNT   64      /* the hcount field is valid */
+
+struct fb_vblank {
+	__u32 flags;                    /* FB_VBLANK flags */
+	__u32 count;                    /* counter of retraces since boot */
+	__s32 vcount;                   /* current scanline position */
+	__s32 hcount;                   /* current scandot position */
+	__u32 reserved[4];              /* reserved for future compatibility */
+};
+
+#ifdef __KERNEL__
+
+#if 1 /* to go away in 2.4.0 */
+extern int GET_FB_IDX(kdev_t rdev);
+#else
+#define GET_FB_IDX(node)	(MINOR(node))
+#endif
+
+#include <linux/fs.h>
+#include <linux/init.h>
+
+
+struct fb_info;
+struct fb_info_gen;
+struct vm_area_struct;
+struct file;
+
+    /*
+     *  Frame buffer operations
+     */
+
+struct fb_ops {
+    /* open/release and usage marking */
+    int (*fb_open)(struct fb_info *info, int user);
+    int (*fb_release)(struct fb_info *info, int user);
+    /* get non settable parameters */
+    int (*fb_get_fix)(struct fb_fix_screeninfo *fix, int con,
+		      struct fb_info *info); 
+    /* get settable parameters */
+    int (*fb_get_var)(struct fb_var_screeninfo *var, int con,
+		      struct fb_info *info);		
+    /* set settable parameters */
+    int (*fb_set_var)(struct fb_var_screeninfo *var, int con,
+		      struct fb_info *info);		
+    /* get colormap */
+    int (*fb_get_cmap)(struct fb_cmap *cmap, int kspc, int con,
+		       struct fb_info *info);
+    /* set colormap */
+    int (*fb_set_cmap)(struct fb_cmap *cmap, int kspc, int con,
+		       struct fb_info *info);
+    /* pan display */
+    int (*fb_pan_display)(struct fb_var_screeninfo *var, int con,
+			  struct fb_info *info);
+    /* perform fb specific ioctl */
+    int (*fb_ioctl)(struct inode *inode, struct file *file, unsigned int cmd,
+		    unsigned long arg, int con, struct fb_info *info);
+    /* perform fb specific mmap */
+    int (*fb_mmap)(struct fb_info *info, struct file *file, struct vm_area_struct *vma);
+    /* switch to/from raster image mode */
+    int (*fb_rasterimg)(struct fb_info *info, int start);
+};
+
+struct fb_info {
+   char modename[40];			/* default video mode */
+   kdev_t node;
+   int flags;
+   int open;                            /* Has this been open already ? */
+#define FBINFO_FLAG_MODULE	1	/* Low-level driver is a module */
+   struct fb_fix_screeninfo fix;        /* Current fix */
+   struct fb_monspecs monspecs;         /* Current Monitor specs */
+   struct fb_ops *fbops;
+   char *screen_base;                   /* Virtual address */
+   struct display *disp;		/* initial display variable */
+   struct display *currcon;
+   struct vc_data *display_fg;		/* Console visible on this display */
+   char fontname[40];			/* default font name */
+   int (*changevar)(int);		/* tell console var has changed */
+   int (*switch_con)(int, struct fb_info*);
+					/* tell fb to switch consoles */
+   int (*updatevar)(int, struct fb_info*);
+					/* tell fb to update the vars */
+   void (*blank)(int, struct fb_info*);	/* tell fb to (un)blank the screen */
+					/* arg = 0: unblank */
+					/* arg > 0: VESA level (arg-1) */
+   void *pseudo_palette;                /* Fake palette of 16 colors and 
+					   the cursor's color for non
+                                           palette mode */
+   /* From here on everything is device dependent */
+   void *par;	
+};
+
+#ifdef MODULE
+#define FBINFO_FLAG_DEFAULT	FBINFO_FLAG_MODULE
+#else
+#define FBINFO_FLAG_DEFAULT	0
+#endif
+
+    /*
+     *  This structure abstracts from the underlying hardware. It is not
+     *  mandatory but used by the `generic' frame buffer operations.
+     *  Read drivers/video/skeletonfb.c for more information.
+     */
+
+struct fbgen_hwswitch {
+    void (*detect)(void);
+    int (*encode_fix)(struct fb_fix_screeninfo *fix, const void *par,
+		      struct fb_info_gen *info);
+    int (*decode_var)(const struct fb_var_screeninfo *var, void *par,
+		      struct fb_info_gen *info);
+    int (*encode_var)(struct fb_var_screeninfo *var, const void *par,
+		      struct fb_info_gen *info);
+    void (*get_par)(void *par, struct fb_info_gen *info);
+    void (*set_par)(const void *par, struct fb_info_gen *info);
+    int (*getcolreg)(unsigned regno, unsigned *red, unsigned *green,
+		     unsigned *blue, unsigned *transp, struct fb_info *info);
+    int (*setcolreg)(unsigned regno, unsigned red, unsigned green,
+		     unsigned blue, unsigned transp, struct fb_info *info);
+    int (*pan_display)(const struct fb_var_screeninfo *var,
+		       struct fb_info_gen *info);
+    int (*blank)(int blank_mode, struct fb_info_gen *info);
+    void (*set_disp)(const void *par, struct display *disp,
+		     struct fb_info_gen *info);
+};
+
+struct fb_info_gen {
+    struct fb_info info;
+
+    /* Entries for a generic frame buffer device */
+    /* Yes, this starts looking like C++ */
+    u_int parsize;
+    struct fbgen_hwswitch *fbhw;
+
+   /* From here on everything is device dependent */
+};
+
+    /*
+     *  `Generic' versions of the frame buffer device operations
+     */
+
+extern int fbgen_get_fix(struct fb_fix_screeninfo *fix, int con,
+			 struct fb_info *info);
+extern int fbgen_get_var(struct fb_var_screeninfo *var, int con,
+			 struct fb_info *info);
+extern int fbgen_set_var(struct fb_var_screeninfo *var, int con,
+			 struct fb_info *info);
+extern int fbgen_get_cmap(struct fb_cmap *cmap, int kspc, int con,
+			  struct fb_info *info);
+extern int fbgen_set_cmap(struct fb_cmap *cmap, int kspc, int con,
+			  struct fb_info *info);
+extern int fbgen_pan_display(struct fb_var_screeninfo *var, int con,
+			     struct fb_info *info);
+extern int fbgen_ioctl(struct inode *inode, struct file *file,
+		       unsigned int cmd, unsigned long arg, int con,
+		       struct fb_info *info);
+
+    /*
+     *  Helper functions
+     */
+
+extern int fbgen_do_set_var(struct fb_var_screeninfo *var, int isactive,
+			    struct fb_info_gen *info);
+extern void fbgen_set_disp(int con, struct fb_info_gen *info);
+extern void fbgen_install_cmap(int con, struct fb_info_gen *info);
+extern int fbgen_update_var(int con, struct fb_info *info);
+extern int fbgen_switch(int con, struct fb_info *info);
+extern void fbgen_blank(int blank, struct fb_info *info);
+
+
+/* drivers/video/fbmem.c */
+extern int register_framebuffer(struct fb_info *fb_info);
+extern int unregister_framebuffer(const struct fb_info *fb_info);
+
+extern int num_registered_fb;
+extern struct fb_info *registered_fb[FB_MAX];
+
+/* drivers/video/fbmon.c */
+extern int fbmon_valid_timings(u_int pixclock, u_int htotal, u_int vtotal,
+			       const struct fb_info *fb_info);
+extern int fbmon_dpms(const struct fb_info *fb_info);
+
+/* drivers/video/fbcmap.c */
+extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp);
+extern void fb_copy_cmap(struct fb_cmap *from, struct fb_cmap *to,
+			 int fsfromto);
+extern int fb_get_cmap(struct fb_cmap *cmap, int kspc,
+		       int (*getcolreg)(u_int, u_int *, u_int *, u_int *,
+					u_int *, struct fb_info *),
+		       struct fb_info *fb_info);
+extern int fb_set_cmap(struct fb_cmap *cmap, int kspc,
+		       int (*setcolreg)(u_int, u_int, u_int, u_int, u_int,
+					struct fb_info *),
+		       struct fb_info *fb_info);
+extern struct fb_cmap *fb_default_cmap(int len);
+extern void fb_invert_cmaps(void);
+
+struct fb_videomode {
+    const char *name;	/* optional */
+    u32 refresh;	/* optional */
+    u32 xres;
+    u32 yres;
+    u32 pixclock;
+    u32 left_margin;
+    u32 right_margin;
+    u32 upper_margin;
+    u32 lower_margin;
+    u32 hsync_len;
+    u32 vsync_len;
+    u32 sync;
+    u32 vmode;
+};
+
+extern int __init fb_find_mode(struct fb_var_screeninfo *var,
+			       struct fb_info *info, const char *mode_option,
+			       const struct fb_videomode *db,
+			       unsigned int dbsize,
+			       const struct fb_videomode *default_mode,
+			       unsigned int default_bpp);
+
+#endif /* __KERNEL__ */
+
+#if 1
+
+#define FBCMD_GET_CURRENTPAR	0xDEAD0005
+#define FBCMD_SET_CURRENTPAR	0xDEAD8005
+
+#endif
+
+
+#if 1 /* Preliminary */
+
+   /*
+    *    Hardware Cursor
+    */
+
+#define FBIOGET_FCURSORINFO     0x4607
+#define FBIOGET_VCURSORINFO     0x4608
+#define FBIOPUT_VCURSORINFO     0x4609
+#define FBIOGET_CURSORSTATE     0x460A
+#define FBIOPUT_CURSORSTATE     0x460B
+
+
+struct fb_fix_cursorinfo {
+	__u16 crsr_width;		/* width and height of the cursor in */
+	__u16 crsr_height;		/* pixels (zero if no cursor)	*/
+	__u16 crsr_xsize;		/* cursor size in display pixels */
+	__u16 crsr_ysize;
+	__u16 crsr_color1;		/* colormap entry for cursor color1 */
+	__u16 crsr_color2;		/* colormap entry for cursor color2 */
+};
+
+struct fb_var_cursorinfo {
+	__u16 width;
+	__u16 height;
+	__u16 xspot;
+	__u16 yspot;
+	__u8 data[1];			/* field with [height][width]        */
+};
+
+struct fb_cursorstate {
+	__s16 xoffset;
+	__s16 yoffset;
+	__u16 mode;
+};
+
+#define FB_CURSOR_OFF		0
+#define FB_CURSOR_ON		1
+#define FB_CURSOR_FLASH		2
+
+#endif /* Preliminary */
+
+#endif /* _LINUX_FB_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/matroxset/matroxfb.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,32 @@
+#ifndef __LINUX_MATROXFB_H__
+#define __LINUX_MATROXFB_H__
+
+#include <asm/ioctl.h>
+#include <asm/types.h>
+
+struct matroxioc_output_mode {
+	__u32	output;		/* which output */
+#define MATROXFB_OUTPUT_PRIMARY		0x0000
+#define MATROXFB_OUTPUT_SECONDARY	0x0001
+	__u32	mode;		/* which mode */
+#define MATROXFB_OUTPUT_MODE_PAL	0x0001
+#define MATROXFB_OUTPUT_MODE_NTSC	0x0002
+#define MATROXFB_OUTPUT_MODE_MONITOR	0x0080
+};
+#define MATROXFB_SET_OUTPUT_MODE	_IOW('n',0xFA,sizeof(struct matroxioc_output_mode))
+#define MATROXFB_GET_OUTPUT_MODE	_IOWR('n',0xFA,sizeof(struct matroxioc_output_mode))
+
+/* bitfield */
+#define MATROXFB_OUTPUT_CONN_PRIMARY	(1 << MATROXFB_OUTPUT_PRIMARY)
+#define MATROXFB_OUTPUT_CONN_SECONDARY	(1 << MATROXFB_OUTPUT_SECONDARY)
+/* connect these outputs to this framebuffer */
+#define MATROXFB_SET_OUTPUT_CONNECTION	_IOW('n',0xF8,sizeof(__u32))
+/* which outputs are connected to this framebuffer */
+#define MATROXFB_GET_OUTPUT_CONNECTION	_IOR('n',0xF8,sizeof(__u32))
+/* which outputs are available for this framebuffer */
+#define MATROXFB_GET_AVAILABLE_OUTPUTS	_IOR('n',0xF9,sizeof(__u32))
+/* which outputs exist on this framebuffer */
+#define MATROXFB_GET_ALL_OUTPUTS	_IOR('n',0xFB,sizeof(__u32))
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/matroxset/matroxset.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,162 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include "fb.h"
+#include "matroxfb.h"
+
+static int help(void) {
+	fprintf(stderr, "usage: matroxset [-f fbdev] [-o output] [-m] [value]\n"
+	                "\n"
+	                "where -f fbdev  is fbdev device (default /dev/fb1)\n"
+	                "      -o output is output number to investigate (0=primary, 1=secondary=default)\n"
+	                "      -m        says that CRTC->output mapping should be changed/retrieved\n"
+			"      -p        print information about blanking\n"
+	                "      value     if present, value is set, if missing, value is retrieved\n"
+			"\n"
+			"For output mode, 128 means monitor, 1 = PAL TV, 2 = NTSC TV\n");
+	return 98;
+}
+
+int main(int argc, char* argv[]) {
+	char* fb = "/dev/fb1";
+	int fd;
+	struct matroxioc_output_mode mom;
+	struct fb_vblank vbl;
+	int rtn;
+	int output = MATROXFB_OUTPUT_SECONDARY;
+	int o_present = 0;
+	int m_present = 0;
+	int p_present = 0;
+	int act;
+	u_int32_t conns;
+	
+	while ((rtn = getopt(argc, argv, "o:f:mhp")) != -1) {
+		switch (rtn) {
+			case 'o':
+				output = strtoul(optarg, NULL, 0);
+				o_present = 1;
+				break;
+			case 'm':
+				m_present = 1;
+				break;
+			case 'f':
+				fb = optarg;
+				break;
+			case 'p':
+				p_present = 1;
+				break;
+			case 'h':
+				return help();
+			default:
+				fprintf(stderr, "Bad commandline\n");
+				return 99;
+		}
+	}
+	act = 0;
+	if (p_present) {
+		if (m_present || o_present) {
+			fprintf(stderr, "You cannot use -p together with -m or -o\n");
+			return 95;
+		}
+		act = 4;
+	} else if (optind >= argc) {
+		if (m_present) {
+			if (o_present) {
+				fprintf(stderr, "You cannot use -m and -o together\n");
+				return 96;
+			}
+			act = 2;
+		} else {
+			mom.output = output;
+			mom.mode = 0;
+		}
+	} else {
+		if (m_present) {
+			conns = strtoul(argv[optind], NULL, 0);
+			act = 3;
+		} else {
+			mom.output = output;
+			mom.mode = strtoul(argv[optind], NULL, 0);
+			act = 1;
+		}
+	}
+	fd = open(fb, O_RDWR);
+	if (fd == -1) {
+		fprintf(stderr, "Cannot open %s: %s\n", fb, strerror(errno));
+		return 122;
+	}
+	switch (act) {
+		case 0:
+			rtn = ioctl(fd, MATROXFB_GET_OUTPUT_MODE, &mom);
+			if (rtn)
+				break;
+			printf("Output mode is %u\n", mom.mode);
+			break;
+		case 1:
+			rtn = ioctl(fd, MATROXFB_SET_OUTPUT_MODE, &mom);
+			break;
+		case 2:
+			rtn = ioctl(fd, MATROXFB_GET_OUTPUT_CONNECTION, &conns);
+			if (rtn)
+				break;
+			printf("This framebuffer is connected to outputs %08X\n", conns);
+			break;
+		case 3:
+			rtn = ioctl(fd, MATROXFB_SET_OUTPUT_CONNECTION, &conns);
+			break;
+		case 4:
+#if 0
+			{ int i; for (i = 0; i < 1000000; i++) {
+			rtn = ioctl(fd, FBIOGET_VBLANK, &vbl);
+			if (rtn)
+				break;
+			}}
+#else
+			rtn = ioctl(fd, FBIOGET_VBLANK, &vbl);
+			if (rtn)
+				break;
+#endif
+			printf("VBlank flags:          %08X\n", vbl.flags);
+			printf("  Symbolic: ");
+			{
+				static const struct { u_int32_t mask; const char* msg; } *ptr, vals[] = {
+					{ FB_VBLANK_HAVE_VBLANK, "vblank" },
+					{ FB_VBLANK_HAVE_HBLANK, "hblank" },
+					{ FB_VBLANK_HAVE_COUNT, "field no." },
+					{ FB_VBLANK_HAVE_VCOUNT, "line no." },
+					{ FB_VBLANK_HAVE_HCOUNT, "column no." },
+					{ FB_VBLANK_VBLANKING, "vblanking" },
+					{ FB_VBLANK_HBLANKING, "hblanking" },
+					{ 0, NULL }};
+				int ap = 0;
+				for (ptr = vals; ptr->msg; ptr++) {
+					if (vbl.flags & ptr->mask) {
+						if (ap) printf(", ");
+						printf(ptr->msg);
+						ap = 1;
+					}
+				}
+				if (!ap)
+					printf("none");
+				printf("\n");
+			}
+			printf("Field count:       %12u\n", vbl.count);
+			printf("Vertical line:     %12u\n", vbl.vcount);
+			printf("Horizontal column: %12u\n", vbl.hcount);
+			break;
+		default:
+			rtn = -1; errno = EINVAL;
+			break;
+	}
+	if (rtn) {
+		fprintf(stderr, "ioctl failed: %s\n", strerror(errno));
+	}
+	close(fd);
+	return 0;
+}
+	
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/matroxset/normal	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,12 @@
+#! /bin/sh
+
+if [ -c /dev/fb0 ]; then
+  HEAD0=/dev/fb0
+  HEAD1=/dev/fb1
+else
+  HEAD0=/dev/fb/0
+  HEAD1=/dev/fb/1
+fi
+matroxset -f ${HEAD1} -m 0
+matroxset -f ${HEAD0} -m 1
+matroxset -f ${HEAD1} -m 2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/matroxset/swapit	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,5 @@
+#! /bin/sh
+~/mga/con2fb /dev/fb0 /dev/tty4
+rmmod matroxfb_maven
+modprobe matroxfb_maven
+~/mga/con2fb /dev/fb1 /dev/tty4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/matroxset/swapped	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,12 @@
+#! /bin/sh
+
+if [ -c /dev/fb0 ]; then
+  HEAD0=/dev/fb0
+  HEAD1=/dev/fb1
+else
+  HEAD0=/dev/fb/0
+  HEAD1=/dev/fb/1
+fi
+matroxset -f ${HEAD1} -m 0
+matroxset -f ${HEAD0} -m 2
+matroxset -f ${HEAD1} -m 1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TVout/modules	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,8 @@
+
+# Load kernel modules...
+# (you must have 2.3/2.4 kernel with matroxfb enabled!)
+
+modprobe i2c-matroxfb
+modprobe matroxfb_Ti3026
+modprobe matroxfb_crtc2
+modprobe matroxfb_maven
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/alaw.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,29 @@
+// code from xanim sources...
+// (I hope that not hurt copyright :o)
+
+#define xaLONG long
+#define xaULONG unsigned long
+#define xaBYTE char
+#define xaUBYTE unsigned char
+
+xaULONG long xa_alaw_2_sign[256];
+
+void Gen_aLaw_2_Signed()
+{ xaULONG i;
+  for(i=0;i<256;i++)
+  { xaUBYTE data = (xaUBYTE)(i);
+    xaLONG d, t, seg;
+
+    data ^= 0x55;
+
+    t = (data & 0xf) << 4;
+    seg = (data & 0x70) >> 4;
+    if (seg == 0)	t += 8;
+    else if (seg == 1)	t += 0x108;
+    else	{ t += 108; t <<= seg - 1; }
+
+    d =  (data & 0x80)?(t):(-t);
+    xa_alaw_2_sign[i] = (xaULONG)((xaULONG)(d) & 0xffff);
+  }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/asfheader.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,183 @@
+// .asf fileformat docs from http://divx.euro.ru
+
+typedef struct __attribute__((packed)) {
+  unsigned char guid[16];
+  unsigned long long size;
+} ASF_obj_header_t;
+
+typedef struct __attribute__((packed)) {
+  ASF_obj_header_t objh;
+  unsigned int cno; // number of subchunks
+  unsigned char v1; // unknown (0x01)
+  unsigned char v2; // unknown (0x02)
+} ASF_header_t;
+
+typedef struct __attribute__((packed)) {
+  unsigned char client[16]; // Client GUID
+  unsigned long long file_size;
+  unsigned long long creat_time; //File creation time FILETIME 8
+  unsigned long long packets;    //Number of packets UINT64 8
+  unsigned long long end_timestamp; //Timestamp of the end position UINT64 8
+  unsigned long long duration;  //Duration of the playback UINT64 8
+  unsigned long start_timestamp; //Timestamp of the start position UINT32 4
+  unsigned long unk1; //Unknown, maybe reserved ( usually contains 0 ) UINT32 4
+  unsigned long flags; //Unknown, maybe flags ( usually contains 2 ) UINT32 4
+  unsigned long packetsize; //Size of packet, in bytes UINT32 4
+  unsigned long packetsize2; //Size of packet ( confirm ) UINT32 4
+  unsigned long frame_size; //Size of uncompressed video frame UINT32 4
+} ASF_file_header_t;
+
+typedef struct __attribute__((packed)) {
+  unsigned char type[16]; // Stream type (audio/video) GUID 16
+  unsigned char concealment[16]; // Audio error concealment type GUID 16
+  unsigned long long unk1; // Unknown, maybe reserved ( usually contains 0 ) UINT64 8
+  unsigned long type_size; //Total size of type-specific data UINT32 4
+  unsigned long stream_size; //Size of stream-specific data UINT32 4
+  unsigned short stream_no; //Stream number UINT16 2
+  unsigned long unk2; //Unknown UINT32 4
+} ASF_stream_header_t;
+
+
+ASF_header_t asfh;
+ASF_obj_header_t objh;
+ASF_file_header_t fileh;
+ASF_stream_header_t streamh;
+unsigned char* asf_packet=NULL;
+//int asf_video_id=-1;
+int asf_scrambling_h=1;
+int asf_scrambling_w=1;
+int asf_scrambling_b=1;
+
+int i;
+
+void asf_descrambling(unsigned char *src,int len){
+  unsigned char *dst=malloc(len);
+  unsigned char *s2=src;
+  int i=0,x,y;
+  while(len-i>=asf_scrambling_h*asf_scrambling_w*asf_scrambling_b){
+//    printf("descrambling! (w=%d  b=%d)\n",w,asf_scrambling_b);
+	//i+=asf_scrambling_h*asf_scrambling_w;
+	for(x=0;x<asf_scrambling_w;x++)
+	  for(y=0;y<asf_scrambling_h;y++){
+	    memcpy(dst+i,s2+(y*asf_scrambling_w+x)*asf_scrambling_b,asf_scrambling_b);
+		i+=asf_scrambling_b;
+	  }
+	s2+=asf_scrambling_h*asf_scrambling_w*asf_scrambling_b;
+  }
+  //if(i<len) memcpy(dst+i,src+i,len-i);
+  memcpy(src,dst,i);
+  free(dst);
+}
+
+char* asf_chunk_type(unsigned char* guid){
+  switch(*((unsigned int*)guid)){
+    case 0xF8699E40: return "guid_audio_stream";
+    case 0xBC19EFC0: return "guid_video_stream";
+    case 0x49f1a440: return "guid_audio_conceal_none";
+    case 0xbfc3cd50: return "guid_audio_conceal_interleave";
+    case 0x75B22630: return "guid_header";
+    case 0x75b22636: return "guid_data_chunk";
+    case 0x33000890: return "guid_index_chunk";
+    case 0xB7DC0791: return "guid_stream_header";
+    case 0xD6E229D1: return "guid_header_2_0";
+    case 0x8CABDCA1: return "guid_file_header";
+  }
+  return NULL;
+}
+
+int asf_check_header(){
+  unsigned char asfhdrguid[16]={0x30,0x26,0xB2,0x75,0x8E,0x66,0xCF,0x11,0xA6,0xD9,0x00,0xAA,0x00,0x62,0xCE,0x6C};
+  int i;
+  stream_read(demuxer->stream,(char*) &asfh,sizeof(asfh)); // header obj
+//  for(i=0;i<16;i++) printf(" %02X",temp[i]);printf("\n");
+//  for(i=0;i<16;i++) printf(" %02X",asfhdrguid[i]);printf("\n");
+  if(memcmp(asfhdrguid,asfh.objh.guid,16)){
+    if(verbose) printf("ASF_check: not ASF guid!\n");
+    return 0; // not ASF guid
+  }
+  if(asfh.cno>256){
+    if(verbose) printf("ASF_check: invalid subchunks_no %d\n",(int) asfh.cno);
+    return 0; // invalid header???
+  }
+  return 1;
+}
+
+int read_asf_header(){
+  unsigned char buffer[512];
+  
+#if 1
+  printf("ASF file! (subchunks: %d)\n",asfh.cno);
+while(!stream_eof(demuxer->stream)){
+  int pos,endpos;
+  pos=stream_tell(demuxer->stream);
+  stream_read(demuxer->stream,(char*) &objh,sizeof(objh));
+  if(stream_eof(demuxer->stream)) break; // EOF
+  endpos=pos+objh.size;
+//  for(i=0;i<16;i++) printf("%02X ",objh.guid[i]);
+  printf("0x%08X  [%s] %d\n",pos, asf_chunk_type(objh.guid),(int) objh.size);
+  switch(*((unsigned int*)&objh.guid)){
+    case 0xB7DC0791: // guid_stream_header
+      stream_read(demuxer->stream,(char*) &streamh,sizeof(streamh));
+      printf("stream type: %s\n",asf_chunk_type(streamh.type));
+      printf("stream concealment: %s\n",asf_chunk_type(streamh.concealment));
+      printf("type: %d bytes,  stream: %d bytes  ID: %d\n",(int)streamh.type_size,(int)streamh.stream_size,(int)streamh.stream_no);
+      printf("unk1: %lX  unk2: %X\n",streamh.unk1,streamh.unk2);
+      printf("FILEPOS=0x%X\n",stream_tell(demuxer->stream));
+      // type-specific data:
+      stream_read(demuxer->stream,(char*) buffer,streamh.type_size);
+      switch(*((unsigned int*)&streamh.type)){
+      case 0xF8699E40:  // guid_audio_stream
+        memcpy(avi_header.wf_ext,buffer,streamh.type_size<64?streamh.type_size:64);
+        if(verbose>=1) print_wave_header((WAVEFORMATEX*)buffer);
+	if((*((unsigned int*)&streamh.concealment))==0xbfc3cd50){
+          stream_read(demuxer->stream,(char*) buffer,streamh.stream_size);
+          asf_scrambling_h=buffer[0];
+          asf_scrambling_w=(buffer[2]<<8)|buffer[1];
+          asf_scrambling_b=(buffer[4]<<8)|buffer[3];
+  	  asf_scrambling_w/=asf_scrambling_b;
+	} else {
+	  asf_scrambling_b=asf_scrambling_h=asf_scrambling_w=1;
+	}
+	printf("ASF audio scrambling: %d x %d x %d\n",asf_scrambling_h,asf_scrambling_w,asf_scrambling_b);
+	if(demuxer->audio->id==-1) demuxer->audio->id=streamh.stream_no & 0x7F;
+        break;
+      case 0xBC19EFC0:  // guid_video_stream
+        memcpy(&avi_header.bih,&buffer[4+4+1+2],sizeof(BITMAPINFOHEADER));
+        if(verbose>=1) print_video_header((BITMAPINFOHEADER*)&buffer[4+4+1+2]);
+        //asf_video_id=streamh.stream_no & 0x7F;
+		if(demuxer->video->id==-1) demuxer->video->id=streamh.stream_no & 0x7F;
+        break;
+      }
+      // stream-specific data:
+      // stream_read(demuxer->stream,(char*) buffer,streamh.stream_size);
+      break;
+//    case 0xD6E229D1: return "guid_header_2_0";
+    case 0x8CABDCA1: // guid_file_header
+      stream_read(demuxer->stream,(char*) &fileh,sizeof(fileh));
+      printf("packets: %d  flags: %d  pack_size: %d  frame_size: %d\n",(int)fileh.packets,(int)fileh.flags,(int)fileh.packetsize,(int)fileh.frame_size);
+      asf_packet=malloc(fileh.packetsize); // !!!
+      break;
+    case 0x75b22636: // guid_data_chunk
+      avi_header.movi_start=stream_tell(demuxer->stream)+26;
+      avi_header.movi_end=endpos;
+      if(verbose>=1) printf("Found movie at 0x%X - 0x%X\n",avi_header.movi_start,avi_header.movi_end);
+      break;
+
+//    case 0x33000890: return "guid_index_chunk";
+
+  } // switch GUID
+  if(!stream_seek(demuxer->stream,endpos)) break;
+} // while EOF
+
+#if 0
+if(verbose){
+    printf("ASF duration: %d\n",(int)fileh.duration);
+    printf("ASF start pts: %d\n",(int)fileh.start_timestamp);
+    printf("ASF end pts: %d\n",(int)fileh.end_timestamp);
+}
+#endif
+
+#endif
+return 1;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aviheader.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,89 @@
+
+#define MIN(a,b) (((a)<(b))?(a):(b))
+
+void read_avi_header(int no_index){
+
+int stream_id=-1;
+
+//---- AVI header:
+avi_header.idx_size=0;
+while(1){
+  int id=stream_read_dword_le(demuxer->stream);
+  int chunksize,size2;
+  static int last_fccType=0;
+  //
+  if(stream_eof(demuxer->stream)) break;
+  //
+  if(id==mmioFOURCC('L','I','S','T')){
+    int len=stream_read_dword_le(demuxer->stream)-4; // list size
+    id=stream_read_dword_le(demuxer->stream);        // list type
+    if(verbose>=2) printf("LIST %.4s  len=%d\n",&id,len);
+    if(id==listtypeAVIMOVIE){
+      // found MOVI header
+      avi_header.movi_start=stream_tell(demuxer->stream);
+      avi_header.movi_end=avi_header.movi_start+len;
+      if(verbose>=1) printf("Found movie at 0x%X - 0x%X\n",avi_header.movi_start,avi_header.movi_end);
+      len=(len+1)&(~1);
+      stream_skip(demuxer->stream,len);
+    }
+    continue;
+  }
+  size2=stream_read_dword_le(demuxer->stream);
+  if(verbose>=2) printf("CHUNK %.4s  len=%d\n",&id,size2);
+  chunksize=(size2+1)&(~1);
+  switch(id){
+    case ckidAVIMAINHDR:          // read 'avih'
+      stream_read(demuxer->stream,(char*) &avi_header.avih,MIN(size2,sizeof(avi_header.avih)));
+      chunksize-=MIN(size2,sizeof(avi_header.avih));
+      if(verbose) print_avih(&avi_header.avih);
+      break;
+    case ckidSTREAMHEADER: {      // read 'strh'
+      AVIStreamHeader h;
+      stream_read(demuxer->stream,(char*) &h,MIN(size2,sizeof(h)));
+      chunksize-=MIN(size2,sizeof(h));
+      if(h.fccType==streamtypeVIDEO) memcpy(&avi_header.video,&h,sizeof(h));else
+      if(h.fccType==streamtypeAUDIO) memcpy(&avi_header.audio,&h,sizeof(h));
+      last_fccType=h.fccType;
+      if(verbose>=1) print_strh(&h);
+	  ++stream_id;
+      break; }
+    case ckidSTREAMFORMAT: {      // read 'strf'
+      if(last_fccType==streamtypeVIDEO){
+        stream_read(demuxer->stream,(char*) &avi_header.bih,MIN(size2,sizeof(avi_header.bih)));
+        chunksize-=MIN(size2,sizeof(avi_header.bih));
+//        init_video_codec();
+//        init_video_out();
+        if(demuxer->video->id==-1) demuxer->video->id=stream_id;
+      } else
+      if(last_fccType==streamtypeAUDIO){
+        int z=(chunksize<64)?chunksize:64;
+        if(verbose>=2) printf("found 'wf', %d bytes of %d\n",chunksize,sizeof(WAVEFORMATEX));
+        stream_read(demuxer->stream,(char*) &avi_header.wf_ext,z);
+        chunksize-=z;
+        if(verbose>=1) print_wave_header((WAVEFORMATEX*)&avi_header.wf_ext);
+//        init_audio_codec();
+//        init_audio_out();
+        if(demuxer->audio->id==-1) demuxer->audio->id=stream_id;
+      }
+      break;
+    }
+    case ckidAVINEWINDEX: if(!no_index){
+      avi_header.idx_size=size2>>4;
+      if(verbose>=1) printf("Reading INDEX block, %d chunks for %d frames\n",
+        avi_header.idx_size,avi_header.avih.dwTotalFrames);
+      avi_header.idx=malloc(avi_header.idx_size<<4);
+      stream_read(demuxer->stream,(char*)avi_header.idx,avi_header.idx_size<<4);
+      chunksize-=avi_header.idx_size<<4;
+      if(verbose>=2) print_index();
+      break;
+    }
+  }
+  if(chunksize>0) stream_skip(demuxer->stream,chunksize); else
+  if(chunksize<0) printf("WARNING!!! chunksize=%d  (id=%.4s)\n",chunksize,&id);
+  
+}
+
+}
+
+#undef MIN
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aviparse.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,336 @@
+// AVI Parser tool   v0.1   (C) 2000. by A'rpi/ESP-team
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <signal.h>
+
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <linux/cdrom.h>
+
+#include "config.h"
+
+#include "loader.h"
+#include "wine/avifmt.h"
+//#include "libvo/video_out.h"
+
+#include "linux/timer.h"
+#include "linux/shmem.h"
+
+#include "help_avp.h"
+
+#define DEBUG if(0)
+
+//static int show_packets=0;
+
+typedef struct {
+  // file:
+  MainAVIHeader avih;
+  unsigned int movi_start;
+  unsigned int movi_end;
+  // index:
+  AVIINDEXENTRY* idx;
+  int idx_size;
+  int idx_pos;
+//  int a_idx;
+//  int v_idx;
+  // video:
+  AVIStreamHeader video;
+  char *video_codec;
+  BITMAPINFOHEADER bih;   // in format
+  BITMAPINFOHEADER o_bih; // out format
+  HIC hic;
+  void *our_out_buffer;
+  char yuv_supported;   // 1 if codec support YUY2 output format
+  char yuv_hack_needed; // requires for divx & mpeg4
+  // audio:
+  AVIStreamHeader audio;
+  char *audio_codec;
+  char wf_ext[64];     // in format
+  WAVEFORMATEX wf;     // out format
+  HACMSTREAM srcstream;
+  int audio_minsize;
+} avi_header_t;
+
+avi_header_t avi_header;
+
+#include "aviprint.c"
+//#include "codecs.c"
+
+//**************************************************************************//
+#include "stream.c"
+//#include "demuxer.c"
+//#include "demux_avi.c"
+
+static stream_t* stream=NULL;
+
+//**************************************************************************//
+
+extern int errno;
+static int play_in_bg=0;
+
+void exit_player(){
+//  int tmp;
+  // restore terminal:
+  getch2_disable();
+  printf("\n\n");
+  if(play_in_bg) system("xsetroot -solid \\#000000");
+  exit(1);
+}
+
+void exit_sighandler(int x){
+  printf("\nmpgplay2 interrupted by signal %d\n",x);
+  exit_player();
+}
+
+
+int main(int argc,char* argv[]){
+char* filename=NULL; //"MI2-Trailer.avi";
+int i;
+//int seek_to_sec=0;
+int seek_to_byte=0;
+int f; // filedes
+int has_audio=1;
+//int audio_format=0;
+//int alsa=0;
+//int audio_buffer_size=-1;
+int audio_id=-1;
+//int video_id=-1;
+//float default_max_pts_correction=0.01f;
+//int delay_corrected=0;
+//float force_fps=0;
+//float default_fps=25;
+//float audio_delay=0;
+int stream_type;
+//int elementary_stream=0;
+int vcd_track=0;
+#ifdef VCD_CACHE
+int vcd_cache_size=128;
+#endif
+//char* video_driver="mga"; // default
+//int out_fmt=0;
+int idx_filepos=0;
+FILE *audiofile=NULL;
+FILE *videofile=NULL;
+char *audiofile_name=NULL;
+char *videofile_name=NULL;
+
+  printf("%s",banner_text);
+
+for(i=1;i<argc;i++){
+  if(strcmp(argv[i],"-afile")==0)  audiofile_name=argv[++i]; else
+  if(strcmp(argv[i],"-vfile")==0)  videofile_name=argv[++i]; else
+//  if(strcmp(argv[i],"-sb")==0) seek_to_byte=strtol(argv[++i],NULL,0); else
+  if(strcmp(argv[i],"-aid")==0) audio_id=strtol(argv[++i],NULL,0); else
+//  if(strcmp(argv[i],"-vid")==0) video_id=strtol(argv[++i],NULL,0); else
+//  if(strcmp(argv[i],"-afm")==0) audio_format=strtol(argv[++i],NULL,0); else
+//  if(strcmp(argv[i],"-vcd")==0) vcd_track=strtol(argv[++i],NULL,0); else
+  if(strcmp(argv[i],"-h")==0) break; else
+  if(strcmp(argv[i],"--help")==0) break; else
+  { if(filename){ printf("invalid option: %s\n",filename);exit(1);}
+    filename=argv[i];
+  }
+}
+
+if(!filename){
+  if(vcd_track) filename="/dev/cdrom"; 
+//  else
+//  filename="/4/Film/Joan of Arc [Hun DivX]/Joan of Arc - CD2.avi";
+  { printf("%s",help_text); exit(0);}
+}
+
+
+if(vcd_track){
+//============ Open VideoCD track ==============
+  f=open(filename,O_RDONLY);
+  if(f<0){ printf("Device not found!\n");return 1; }
+  vcd_read_toc(f);
+  if(!vcd_seek_to_track(f,vcd_track)){ printf("Error selecting VCD track!\n");return 1;}
+  seek_to_byte+=VCD_SECTOR_DATA*vcd_get_msf();
+  stream_type=STREAMTYPE_VCD;
+#ifdef VCD_CACHE
+  vcd_cache_init(vcd_cache_size);
+#endif
+} else {
+//============ Open plain FILE ============
+  f=open(filename,O_RDONLY);
+  if(f<0){ printf("File not found!\n");return 1; }
+  stream_type=STREAMTYPE_FILE;
+}
+
+//============ Open & Sync stream and detect file format ===============
+
+stream=new_stream(f,stream_type);
+//=============== Read AVI header:
+{ //---- RIFF header:
+  int id=stream_read_dword_le(stream); // "RIFF"
+  if(id!=mmioFOURCC('R','I','F','F')){ printf("Not RIFF format file!\n");return 1; }
+  stream_read_dword_le(stream); //filesize
+  id=stream_read_dword_le(stream); // "AVI "
+  if(id!=formtypeAVI){ printf("Not AVI file!\n");return 1; }
+}
+//---- AVI header:
+avi_header.idx_size=0;
+while(1){
+  int id=stream_read_dword_le(stream);
+  int chunksize,size2;
+  static int last_fccType=0;
+  //
+  if(stream_eof(stream)) break;
+  //
+  if(id==mmioFOURCC('L','I','S','T')){
+    int len=stream_read_dword_le(stream)-4; // list size
+    id=stream_read_dword_le(stream);        // list type
+    printf("LIST %.4s  len=%d\n",&id,len);
+    if(id==listtypeAVIMOVIE){
+      // found MOVI header
+      avi_header.movi_start=stream_tell(stream);
+      avi_header.movi_end=avi_header.movi_start+len;
+//      printf("Found movie at 0x%X - 0x%X\n",avi_header.movi_start,avi_header.movi_end);
+      len=(len+1)&(~1);
+      stream_skip(stream,len);
+    }
+    continue;
+  }
+  size2=stream_read_dword_le(stream);
+  printf("CHUNK %.4s  len=%d\n",&id,size2);
+  chunksize=(size2+1)&(~1);
+  switch(id){
+    case ckidAVIMAINHDR:          // read 'avih'
+      stream_read(stream,(char*) &avi_header.avih,sizeof(avi_header.avih));
+      chunksize-=sizeof(avi_header.avih);
+      print_avih(&avi_header.avih);
+      break;
+    case ckidSTREAMHEADER: {      // read 'strh'
+      AVIStreamHeader h;
+      stream_read(stream,(char*) &h,sizeof(h));
+      chunksize-=sizeof(h);
+      if(h.fccType==streamtypeVIDEO) memcpy(&avi_header.video,&h,sizeof(h));else
+      if(h.fccType==streamtypeAUDIO) memcpy(&avi_header.audio,&h,sizeof(h));
+      last_fccType=h.fccType;
+      print_strh(&h);
+      break; }
+    case ckidSTREAMFORMAT: {      // read 'strf'
+      if(last_fccType==streamtypeVIDEO){
+        stream_read(stream,(char*) &avi_header.bih,sizeof(avi_header.bih));
+        chunksize-=sizeof(avi_header.bih);
+//        init_video_codec();
+//        init_video_out();
+      } else
+      if(last_fccType==streamtypeAUDIO){
+        int z=(chunksize<64)?chunksize:64;
+        printf("found 'wf', %d bytes of %d\n",chunksize,sizeof(WAVEFORMATEX));
+        stream_read(stream,(char*) &avi_header.wf_ext,z);
+        chunksize-=z;
+        print_wave_header((WAVEFORMATEX*)&avi_header.wf_ext);
+//        init_audio_codec();
+//        init_audio_out();
+      }
+      break;
+    }
+    case ckidAVINEWINDEX: {
+      avi_header.idx_size=size2>>4;
+//      printf("Reading INDEX block, %d chunks for %d frames\n",
+//        avi_header.idx_size,avi_header.avih.dwTotalFrames);
+      avi_header.idx=malloc(avi_header.idx_size<<4);
+      idx_filepos=stream_tell(stream);
+      stream_read(stream,(char*)avi_header.idx,avi_header.idx_size<<4);
+      chunksize-=avi_header.idx_size<<4;
+      print_index();
+      break;
+    }
+  }
+  if(chunksize>0) stream_skip(stream,chunksize); else
+  if(chunksize<0) printf("WARNING!!! chunksize=%d  (id=%.4s)\n",chunksize,&id);
+  
+}
+
+printf("----------------------------------------------------------------------\n");
+printf("Found movie at 0x%X - 0x%X\n",avi_header.movi_start,avi_header.movi_end);
+if(avi_header.idx_size<=0){ printf("No index block found!\n");return 0;}
+printf("Index block at 0x%X, %d entries for %d frames\n",idx_filepos,
+  avi_header.idx_size,avi_header.avih.dwTotalFrames  );
+
+stream_reset(stream);
+stream_seek(stream,avi_header.movi_start);
+avi_header.idx_pos=0;
+
+if(audiofile_name) audiofile=fopen(audiofile_name,"wb");
+if(videofile_name) videofile=fopen(videofile_name,"wb");
+
+for(i=0;i<avi_header.idx_size;i++){
+#if 0
+    printf("%.4s  %4X  %08X  %d  ",
+      &avi_header.idx[i].ckid,
+      avi_header.idx[i].dwFlags,
+      avi_header.idx[i].dwChunkOffset,
+      avi_header.idx[i].dwChunkLength
+    );fflush(stdout);
+#endif
+    if(avi_header.idx[i].ckid&AVIIF_LIST){
+//      printf("LIST\n");
+    } else {
+      int id,size;
+      stream_seek(stream,avi_header.movi_start+avi_header.idx[i].dwChunkOffset-4);
+      id=stream_read_dword_le(stream);
+      size=stream_read_dword_le(stream);
+      if(id!=avi_header.idx[i].ckid){
+        printf("ChunkID mismatch! raw=%.4s (0x%X) idx=%.4s (0x%X)\n",
+          &id,avi_header.movi_start+avi_header.idx[i].dwChunkOffset-4,
+          &avi_header.idx[i].ckid,idx_filepos+16*i
+        );
+        continue;
+      }
+      if(size!=avi_header.idx[i].dwChunkLength){
+        printf("ChunkSize mismatch! raw=%d (0x%X) idx=%d (0x%X)\n",
+          size,avi_header.movi_start+avi_header.idx[i].dwChunkOffset-4,
+          avi_header.idx[i].dwChunkLength,idx_filepos+16*i
+        );
+        continue;
+      }
+
+      if(id!=mmioFOURCC('J','U','N','K'))
+      if(TWOCCFromFOURCC(id)==cktypeWAVEbytes){
+          // audio
+          int aid=StreamFromFOURCC(id);
+          if(audio_id==-1) audio_id=aid;
+          if(audio_id==aid){
+            if(audiofile){
+              void* mem=malloc(size);
+              stream_read(stream,mem,size);
+              fwrite(mem,size,1,audiofile);
+              free(mem);
+            }
+          } else {
+            printf("Invalid audio stream id: %d (%.4s)\n",aid,&id);
+          }
+      } else 
+      if(LOWORD(id)==aviTWOCC('0','0')){
+         // video
+            if(videofile){
+              void* mem=malloc(size);
+              stream_read(stream,mem,size);
+              fwrite(&size,4,1,videofile);
+              fwrite(mem,size,1,videofile);
+              free(mem);
+            }
+      } else {
+         // unknown
+         printf("Unknown chunk: %.4s (%X)\n",&id,id);
+      }
+
+    } // LIST or CHUNK
+
+}
+
+return 0;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aviprint.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,88 @@
+void print_avih(MainAVIHeader *h){
+  printf("======= AVI Header =======\n");
+  printf("us/frame: %d  (fps=%5.3f)\n",h->dwMicroSecPerFrame,1000000.0f/(float)h->dwMicroSecPerFrame);
+  printf("max bytes/sec: %d\n",h->dwMaxBytesPerSec);
+  printf("padding: %d\n",h->dwPaddingGranularity);
+  printf("flags: (%d)%s%s%s%s%s%s\n",h->dwFlags,
+    (h->dwFlags&AVIF_HASINDEX)?" HAS_INDEX":"",
+    (h->dwFlags&AVIF_MUSTUSEINDEX)?" MUST_USE_INDEX":"",
+    (h->dwFlags&AVIF_ISINTERLEAVED)?" IS_INTERLEAVED":"",
+    (h->dwFlags&AVIF_TRUSTCKTYPE)?" TRUST_CKTYPE":"",
+    (h->dwFlags&AVIF_WASCAPTUREFILE)?" WAS_CAPTUREFILE":"",
+    (h->dwFlags&AVIF_COPYRIGHTED)?" COPYRIGHTED":""
+  );
+  printf("frames  total: %d   initial: %d\n",h->dwTotalFrames,h->dwInitialFrames);
+  printf("streams: %d\n",h->dwStreams);
+  printf("Suggested BufferSize: %d\n",h->dwSuggestedBufferSize);
+  printf("Size:  %d x %d\n",h->dwWidth,h->dwHeight);
+}
+
+void print_strh(AVIStreamHeader *h){
+  printf("======= STREAM Header =======\n");
+  printf("Type: %.4s   FCC: %.4s (%X)\n",&h->fccType,&h->fccHandler,h->fccHandler);
+  printf("Flags: %d\n",h->dwFlags);
+  printf("Priority: %d   Language: %d\n",h->wPriority,h->wLanguage);
+  printf("InitialFrames: %d\n",h->dwInitialFrames);
+  printf("Rate: %d/%d = %5.3f\n",h->dwRate,h->dwScale,(float)h->dwRate/(float)h->dwScale);
+  printf("Start: %d   Len: %d\n",h->dwStart,h->dwLength);
+  printf("Suggested BufferSize: %d\n",h->dwSuggestedBufferSize);
+  printf("Quality %d\n",h->dwQuality);
+  printf("Sample size: %d\n",h->dwSampleSize);
+}
+
+void print_wave_header(WAVEFORMATEX *h){
+
+  printf("======= WAVE Format =======\n");
+  
+  printf("Format Tag: %d (0x%X)\n",h->wFormatTag,h->wFormatTag);
+  printf("Channels: %d\n",h->nChannels);
+  printf("Samplerate: %d\n",h->nSamplesPerSec);
+  printf("avg byte/sec: %d\n",h->nAvgBytesPerSec);
+  printf("Block align: %d\n",h->nBlockAlign);
+  printf("bits/sample: %d\n",h->wBitsPerSample);
+  printf("cbSize: %d\n",h->cbSize);
+  
+  switch(h->wFormatTag){
+      case 0x01:        printf("Audio in PCM format\n");break;
+      case 0x50:        printf("Audio in MPEG Layer 1/2 format\n");break;
+      case 0x55:        printf("Audio in MPEG Layer-3 format\n");break; // ACM
+      case 0x02:        printf("Audio in MS ADPCM format\n");break;  // ACM
+      case 0x11:        printf("Audio in IMA ADPCM format\n");break; // ACM
+      case 0x31:
+      case 0x32:        printf("Audio in MS GSM 6.10 format\n");break; // ACM
+      case 0x75:        printf("Audio in VoxWare format\n");break; // DShow
+      case 0x160:
+      case 0x161:       printf("Audio in DivX WMA format\n");break; // ACM
+      default:          printf("Audio in UNKNOWN (id=0x%X) format\n",h->wFormatTag);
+  }
+
+}
+
+
+void print_video_header(BITMAPINFOHEADER *h){
+  printf("======= VIDEO Format ======\n");
+	printf("  biSize %d\n", h->biSize);
+	printf("  biWidth %d\n", h->biWidth);
+	printf("  biHeight %d\n", h->biHeight);
+	printf("  biPlanes %d\n", h->biPlanes);
+	printf("  biBitCount %d\n", h->biBitCount);
+	printf("  biCompression %d='%.4s'\n", h->biCompression, &h->biCompression);
+	printf("  biSizeImage %d\n", h->biSizeImage);
+  printf("===========================\n");
+}
+
+
+void print_index(){
+  int i;
+  for(i=0;i<avi_header.idx_size;i++){
+    printf("%5d:  %.4s  %4X  %08X (%08X)  %d\n",i,
+      &avi_header.idx[i].ckid,
+      avi_header.idx[i].dwFlags,
+      avi_header.idx[i].dwChunkOffset,
+      avi_header.idx[i].dwChunkOffset+avi_header.movi_start,
+      avi_header.idx[i].dwChunkLength
+    );
+  }
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aviwrite.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,161 @@
+
+void write_avi_chunk(FILE *f,unsigned int id,int len,void* data){
+
+fwrite(&id,4,1,f);
+fwrite(&len,4,1,f);
+if(len>0){
+  if(data){
+    // DATA
+    fwrite(data,len,1,f);
+    if(len&1){  // padding
+      unsigned char zerobyte=0;
+      fwrite(&zerobyte,1,1,f);
+    }
+  } else {
+    // JUNK
+    char *avi_junk_data="[= MPlayer junk data! =]";
+    if(len&1) ++len; // padding
+    while(len>0){
+      int l=strlen(avi_junk_data);
+      if(l>len) l=len;
+      fwrite(avi_junk_data,l,1,f);
+      len-=l;
+    }
+  }
+}
+
+}
+
+
+void write_avi_list(FILE *f,unsigned int id,int len){
+  unsigned int list_id=FOURCC_LIST;
+  len+=4; // list fix
+  fwrite(&list_id,4,1,f);
+  fwrite(&len,4,1,f);
+  fwrite(&id,4,1,f);
+}
+
+struct {
+  MainAVIHeader avih;
+  AVIStreamHeader video;
+  BITMAPINFOHEADER bih;
+  unsigned int movi_start;
+  unsigned int movi_end;
+  unsigned int file_end;
+} wah;
+
+void write_avi_header(FILE *f){
+  unsigned int riff[3];
+  // RIFF header:
+  riff[0]=mmioFOURCC('R','I','F','F');
+  riff[1]=wah.file_end;  // filesize
+  riff[2]=formtypeAVI; // 'AVI '
+  fwrite(&riff,12,1,f);
+  // AVI header:
+  write_avi_list(f,listtypeAVIHEADER,sizeof(wah.avih)+8+12+sizeof(wah.video)+8+sizeof(wah.bih)+8);
+  write_avi_chunk(f,ckidAVIMAINHDR,sizeof(wah.avih),&wah.avih);
+  // stream header:
+  write_avi_list(f,listtypeSTREAMHEADER,sizeof(wah.video)+8+sizeof(wah.bih)+8);
+  write_avi_chunk(f,ckidSTREAMHEADER,sizeof(wah.video),&wah.video);
+  write_avi_chunk(f,ckidSTREAMFORMAT,sizeof(wah.bih),&wah.bih);
+  // JUNK:  
+  write_avi_chunk(f,ckidAVIPADDING,2048-(ftell(f)&2047)-8,NULL);
+  // 'movi' header:
+  write_avi_list(f,listtypeAVIMOVIE,wah.movi_end-ftell(f)-12);
+  wah.movi_start=ftell(f);
+}
+
+// called _before_ encoding:  (write placeholders and video info)
+void write_avi_header_1(FILE *f,int fcc,float fps,int width,int height){
+  int frames=8*3600*fps; // 8 hours
+  
+  wah.file_end=
+  wah.movi_end=0x7f000000;
+
+  wah.avih.dwMicroSecPerFrame=1000000.0f/fps;
+  wah.avih.dwMaxBytesPerSec=fps*500000; // ?????
+  wah.avih.dwPaddingGranularity=1; // padding
+  wah.avih.dwFlags=AVIF_ISINTERLEAVED;
+  wah.avih.dwTotalFrames=frames;
+  wah.avih.dwInitialFrames=0;
+  wah.avih.dwStreams=1;
+  wah.avih.dwSuggestedBufferSize=0x10000; // 1MB
+  wah.avih.dwWidth=width;
+  wah.avih.dwHeight=height;
+  wah.avih.dwReserved[0]=
+  wah.avih.dwReserved[1]=
+  wah.avih.dwReserved[2]=
+  wah.avih.dwReserved[3]=0;
+  
+  wah.video.fccType=streamtypeVIDEO;
+  wah.video.fccHandler=fcc;
+  wah.video.dwFlags=0;
+  wah.video.wPriority=0;
+  wah.video.wLanguage=0;
+  wah.video.dwInitialFrames=0;
+  wah.video.dwScale=10000;
+  wah.video.dwRate=fps*10000;
+  wah.video.dwStart=0;
+  wah.video.dwLength=frames;
+  wah.video.dwSuggestedBufferSize=0x100000; // 1MB ????
+  wah.video.dwQuality=10000;
+  wah.video.dwSampleSize=width*height*3;
+  
+  wah.bih.biSize=sizeof(wah.bih); // 40 ?
+  wah.bih.biWidth=width;
+  wah.bih.biHeight=height;
+  wah.bih.biPlanes=1;
+  wah.bih.biBitCount=24;
+  wah.bih.biCompression=fcc;
+  wah.bih.biSizeImage=3*width*height;
+  wah.bih.biXPelsPerMeter=
+  wah.bih.biYPelsPerMeter=
+  wah.bih.biClrUsed=
+  wah.bih.biClrImportant=0;
+
+  write_avi_header(f);  
+}
+
+void avi_fixate(){
+  // append index and fix avi headers:
+  FILE *f1=fopen(encode_name,"r+");
+  FILE *f2;
+
+  if(!f1) return; // error
+  
+  fseek(f1,0,SEEK_END);
+  wah.file_end=wah.movi_end=ftell(f1);
+
+  // index:
+  if(encode_index_name && (f2=fopen(encode_index_name,"rb"))){
+    AVIINDEXENTRY idx;
+    unsigned int pos=0;
+    int frames=0;
+    write_avi_chunk(f1,ckidAVINEWINDEX,0,NULL);
+    while(fread(&idx,sizeof(idx),1,f2)>0){
+      idx.dwChunkOffset-=wah.movi_start-4;
+      fwrite(&idx,sizeof(idx),1,f1);
+      ++frames;
+    }
+    fclose(f2);
+    unlink(encode_index_name);
+    wah.file_end=ftell(f1);
+    // re-write idx1 length:
+    pos=wah.file_end-wah.movi_end-8;
+    fseek(f1,wah.movi_end+4,SEEK_SET);
+    fwrite(&pos,4,1,f1);
+    // fixup frames:
+    wah.avih.dwTotalFrames=frames;
+    wah.video.dwLength=frames;
+  }
+
+  // re-write avi header:
+  fseek(f1,0,SEEK_SET);
+  write_avi_header(f1);
+
+  fclose(f1);
+  
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/codecctrl.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,198 @@
+
+//#define DEBUG_SIGNALS
+#define DEBUG_SIGNALS_SLEEP ;
+//#define DEBUG_SIGNALS_SLEEP sleep(2);
+
+#ifdef DEBUG_SIGNALS
+#define DEBUG_SIG if(1)
+#else
+#define DEBUG_SIG if(0)
+#endif
+
+//======= Interprocess Comminication (IPC) between player & codec =========
+
+static int child_pid=0;
+static int codec_pid=0;
+
+// player:
+static int data_fifo=-1;
+static int control_fifo=-1;
+// codec:
+static int data_fifo2=-1;
+static int control_fifo2=-1;
+// keyboard:
+static int keyb_fifo_put=-1;
+static int keyb_fifo_get=-1;
+
+
+// SIGTERM handler of codec controller (2nd process):
+static void codec_ctrl_sighandler(int x){
+DEBUG_SIG  printf("\nCTRL: received signal %d, terminating child first:\n",x);
+  // first terminate the codec:
+  //kill(child_pid,SIGTERM);
+  kill(child_pid,x);
+  usleep(50000); // 50ms must be enough
+DEBUG_SIG  printf("CTRL: Sending KILL signal to child:\n");
+  kill(child_pid,SIGKILL); // worst case
+  usleep(10000);
+  // and exit
+  if(x!=SIGHUP){
+DEBUG_SIG    printf("CTRL: Exiting...\n");
+    exit(0);
+  }
+}
+
+static vo_functions_t *codec_video_out_ptr=NULL;
+
+// SIGTERM handler of the codec (3nd process):
+static void codec_sighandler(int x){
+DEBUG_SIG  printf("\nCHILD: received signal %d, exiting...\n",x);
+  if(x==SIGTERM){
+    //mpeg2_close(codec_video_out_ptr);
+    codec_video_out_ptr->uninit();  // closing video_out
+  }
+  exit(0);
+}
+
+
+static void make_pipe(int* pr,int* pw){
+  int temp[2];
+  if(pipe(temp)!=0) printf("Cannot make PIPE!\n");
+  *pr=temp[0];
+  *pw=temp[1];
+}
+
+static inline int my_write(int fd,unsigned char* mem,int len){
+  int total=0;
+  int len2;
+  while(len>0){
+    len2=write(fd,mem+total,len); if(len2<=0) break;
+    total+=len2;len-=len2;
+//    printf("%d bytes received, %d left\n",len2,len);
+  }
+  return total;
+}
+
+static inline int my_read(int fd,unsigned char* mem,int len){
+  int total=0;
+  int len2;
+  while(len>0){
+    len2=read(fd,mem+total,len); if(len2<=0) break;
+    total+=len2;len-=len2;
+//    printf("%d bytes received, %d left\n",len2,len);
+  }
+  return total;
+}
+
+
+void send_cmd(int fd,int cmd){
+  int fifo_cmd=cmd;
+  write(fd,&fifo_cmd,4);
+//  fflush(control_fifo);
+}
+
+void mpeg_codec_controller(vo_functions_t *video_out){
+//================== CODEC Controller: ==========================
+    signal(SIGTERM,codec_ctrl_sighandler); // set our SIGTERM handler
+    signal(SIGHUP,codec_ctrl_sighandler);  // set our SIGHUP handler
+    printf("starting video codec...\n");
+    while(1){
+      int status;
+      if((child_pid=fork())==0){
+        // child:
+        unsigned int t=0;
+        codec_video_out_ptr=video_out;
+#if 0
+        signal(SIGTERM,codec_sighandler); // set our SIGTERM handler
+        signal(SIGHUP,codec_sighandler);  // set our SIGHUP handler
+#else
+  // terminate requests:
+  signal(SIGTERM,codec_sighandler); // kill
+  signal(SIGHUP,codec_sighandler);  // kill -HUP  /  xterm closed
+  signal(SIGINT,codec_sighandler);  // Interrupt from keyboard
+  signal(SIGQUIT,codec_sighandler); // Quit from keyboard
+  // fatal errors:
+  signal(SIGBUS,codec_sighandler);  // bus error
+  signal(SIGSEGV,codec_sighandler); // segfault
+  signal(SIGILL,codec_sighandler);  // illegal instruction
+  signal(SIGFPE,codec_sighandler);  // floating point exc.
+  signal(SIGABRT,codec_sighandler); // abort()
+#endif
+
+        send_cmd(control_fifo2,0x22222222); // Send WE_ARE_READY command
+        send_cmd(control_fifo2,getpid());   // Send out PID
+        while(1){
+          unsigned int syncword=0;
+          read(data_fifo2,&syncword,4);
+          if(syncword==0x22222222) break;
+          printf("codec: drop bad frame (%X)\n",syncword);
+        }
+        //printf("codec: connection synced\n");
+        
+        while(1){
+          int num_frames;
+          int len=0;
+          int len2;
+          send_cmd(control_fifo2,0x3030303);
+          len2=my_read(data_fifo2,(unsigned char*) &len,4);
+          if(len2!=4){
+            printf("FATAL: cannot read packet len from data fifo (ret=%d, errno=%d)\n",len2,errno);
+            break;
+          }
+          if(len==0){ printf("mpeg2dec: EOF, exiting...\n");break; }
+//          printf("mpeg2dec: frame (%d bytes) read\n",len);
+          t-=GetTimer();
+          mpeg2_decode_data(video_out, videobuffer, videobuffer+len);
+          t+=GetTimer();
+          send_cmd(control_fifo2,0); // FRAME_COMPLETED command
+          send_cmd(control_fifo2,picture->frame_rate); // fps
+          send_cmd(control_fifo2,100+picture->repeat_count);picture->repeat_count=0;
+          send_cmd(control_fifo2,t);t=0;
+        }
+		video_out->uninit();
+        exit(0); // leave process
+      }
+      wait(&status); // Waiting for the child!
+//      printf("restarting video codec...\n");
+    }
+    exit(0);
+}
+
+void mplayer_put_key(int code){
+           fd_set rfds;
+           struct timeval tv;
+
+           /* Watch stdin (fd 0) to see when it has input. */
+           FD_ZERO(&rfds);
+           FD_SET(keyb_fifo_put, &rfds);
+           tv.tv_sec = 0;
+           tv.tv_usec = 0;
+
+           //retval = select(keyb_fifo_put+1, &rfds, NULL, NULL, &tv);
+           if(select(keyb_fifo_put+1, NULL, &rfds, NULL, &tv)){
+             write(keyb_fifo_put,&code,4);
+//             printf("*** key event %d sent ***\n",code);
+           } else {
+//             printf("*** key event dropped (FIFO is full) ***\n");
+           }
+}
+
+int mplayer_get_key(){
+           fd_set rfds;
+           struct timeval tv;
+           int code=-1;
+
+           /* Watch stdin (fd 0) to see when it has input. */
+           FD_ZERO(&rfds);
+           FD_SET(keyb_fifo_get, &rfds);
+           tv.tv_sec = 0;
+           tv.tv_usec = 0;
+
+           //retval = select(keyb_fifo_put+1, &rfds, NULL, NULL, &tv);
+           if(select(keyb_fifo_put+1, &rfds, NULL, NULL, &tv)){
+             read(keyb_fifo_get,&code,4);
+//             printf("*** key event %d read ***\n",code);
+           }
+           return code;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/codecs.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,150 @@
+//#define ANGELPOTION
+
+char* get_vids_codec_name(){
+//  unsigned long fccHandler=avi_header.video.fccHandler;
+  unsigned long fccHandler=avi_header.bih.biCompression;
+  avi_header.yuv_supported=0;
+  avi_header.yuv_hack_needed=0;
+  avi_header.flipped=0;
+  switch(fccHandler){
+	case mmioFOURCC('M', 'P', 'G', '4'):
+	case mmioFOURCC('m', 'p', 'g', '4'):
+	case mmioFOURCC('M', 'P', '4', '2'):
+	case mmioFOURCC('m', 'p', '4', '2'):
+//	case mmioFOURCC('M', 'P', '4', '3'):
+//      case mmioFOURCC('m', 'p', '4', '3'):
+	  printf("Video in Microsoft MPEG-4 format\n");
+          avi_header.yuv_supported=1;
+          avi_header.yuv_hack_needed=1;
+#ifdef ANGELPOTION
+          return "APmpg4v1.dll";
+#endif
+          return "mpg4c32.dll";
+	case mmioFOURCC('M', 'P', '4', '3'):
+	case mmioFOURCC('m', 'p', '4', '3'):
+	  printf("Video in MPEG-4 v3 (really DivX) format\n");
+          avi_header.bih.biCompression=mmioFOURCC('d', 'i', 'v', '3'); // hack
+          avi_header.yuv_supported=1;
+          avi_header.yuv_hack_needed=1;
+#ifdef ANGELPOTION
+          return "APmpg4v1.dll";
+#endif
+          return "divxc32.dll";
+
+	case mmioFOURCC('D', 'I', 'V', 'X'):
+	case mmioFOURCC('d', 'i', 'v', 'x'):
+          return "DivX.dll";
+
+	case mmioFOURCC('D', 'I', 'V', '3'):
+	case mmioFOURCC('d', 'i', 'v', '3'):
+	case mmioFOURCC('D', 'I', 'V', '4'):
+        case mmioFOURCC('d', 'i', 'v', '4'):
+	case mmioFOURCC('M', 'P', '4', '1'):
+	case mmioFOURCC('m', 'p', '4', '1'):
+	  printf("Video in DivX ;-) format\n");
+          avi_header.yuv_supported=1;
+          avi_header.yuv_hack_needed=1;
+#ifdef ANGELPOTION
+          return "APmpg4v1.dll";
+#endif
+          return "divxc32.dll";
+
+	case mmioFOURCC('I', 'V', '5', '0'):	    
+	case mmioFOURCC('i', 'v', '5', '0'):	 
+	  printf("Video in Indeo Video 5 format\n");
+          avi_header.yuv_supported=1;   // YUV pic is upside-down :(
+          return "ir50_32.dll";
+
+	case mmioFOURCC('I', 'V', '4', '1'):	    
+	case mmioFOURCC('i', 'v', '4', '1'):	    
+	  printf("Video in Indeo Video 4.1 format\n");   
+          avi_header.flipped=1;
+		  avi_header.no_32bpp_support=1;
+          return "ir41_32.dll";
+
+	case mmioFOURCC('I', 'V', '3', '2'):	    
+	case mmioFOURCC('i', 'v', '3', '2'):
+	  printf("Video in Indeo Video 3.2 format\n");   
+          avi_header.flipped=1;
+		  avi_header.no_32bpp_support=1;
+          return "ir32_32.dll";
+
+	case mmioFOURCC('c', 'v', 'i', 'd'):
+	  printf("Video in Cinepak format\n");
+          avi_header.yuv_supported=1;
+          return "iccvid.dll";
+
+//*** Only 16bit .DLL available (can't load under linux) ***
+//	case mmioFOURCC('V', 'C', 'R', '1'):
+//	  printf("Video in ATI VCR1 format\n");
+//          return "ativcr1.dll";
+
+	case mmioFOURCC('V', 'C', 'R', '2'):
+	  printf("Video in ATI VCR2 format\n");
+          avi_header.yuv_supported=1;
+          return "ativcr2.dll";
+
+	case mmioFOURCC('A', 'S', 'V', '1'):
+	  printf("Asus ASV-1 format\n");
+//          avi_header.yuv_supported=1;
+          return "asusasvd.dll";
+
+	case mmioFOURCC('A', 'S', 'V', '2'):
+	  printf("Asus ASV-2 format\n");
+//          avi_header.yuv_supported=1;
+          avi_header.flipped=1;
+//          avi_header.bih.biCompression=mmioFOURCC('A', 'S', 'V', '1');
+//          return "asusasvd.dll";
+          return "asusasv2.dll";
+
+	case mmioFOURCC('I', '2', '6', '3'):
+	case mmioFOURCC('i', '2', '6', '3'):
+	  printf("Video in I263 format\n");
+          return "i263_32.drv";
+
+	case mmioFOURCC('M', 'J', 'P', 'G'):
+	  printf("Video in MJPEG format\n");
+          avi_header.yuv_supported=1;
+		    return "M3JPEG32.dll";
+//          return "mcmjpg32.dll";
+//          return "m3jpeg32.dll";
+//          return "libavi_mjpeg.so";
+  }
+  printf("UNKNOWN video codec: %.4s (0x%0X)\n",&fccHandler,fccHandler);
+  printf("If you know this video format and codec, you can edit codecs.c in the source!\n");
+  printf("Please contact the author, send this movie to be supported by future version.\n");
+  return NULL;
+}
+
+char* get_auds_codec_name(){
+  int id=((WAVEFORMATEX*)avi_header.wf_ext)->wFormatTag;
+  switch (id){
+    	case 0x161://DivX audio
+//            ((WAVEFORMATEX*)avi_header.wf_ext)->wFormatTag=0x160; //hack
+    	case 0x160://DivX audio
+            avi_header.audio_seekable=0;
+            return "divxa32.acm";   // tested, OK.
+	case 0x2://MS ADPCM
+            avi_header.audio_seekable=0;
+            return "msadp32.acm";   // tested, OK.
+	case 0x55://MPEG l3
+            avi_header.audio_seekable=1;
+            return "l3codeca.acm";  // tested, OK. faster than mp3lib on intel
+	case 0x11://IMA ADPCM
+            return "imaadp32.acm";  // segfault :(
+	case 0x31://MS GSM
+	case 0x32://MS GSM
+            return "msgsm32.acm";   // segfault :( - not req. has internal now!
+        case 0x75://VoxWare
+            return "voxmsdec.ax";   // directshow, not yet supported just a try
+//	case 0x06://???
+//            return "lhacm.acm";
+//            return "msg711.acm";
+//            return "tssoft32.acm";
+  }
+  printf("UNKNOWN audio codec: 0x%0X\n",id);
+  printf("If you know this audio format and codec, you can edit codecs.c in the source!\n");
+  printf("Please contact the author, send this movie to be supported by future version.\n");
+  return NULL;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,70 @@
+
+/* -------- Generated by ./configure ----------- */
+
+/* Define this to enable avg. byte/sec-based AVI sync method by default:
+   (use -bps or -nobps commandline option for run-time method selection)    */
+#undef AVI_SYNC_BPS
+
+/* Undefine this if you want soundcard-only timing by default:
+   You can still change this with the -alsa or -noalsa command-line option!
+   (This function was originally impemented to solve ALSA driver's big
+   buffer problems, but it seems to be useful for every soundcard drivers) */
+#define ALSA_TIMER
+
+/* Undefine this if your soundcard driver has no working select().
+   If you have kernel Oops, player hangups, or just no audio, you should
+   try to recompile MPlayer with this option disabled! */
+#define HAVE_AUDIO_SELECT
+
+/* You have a choice for MP3 decoding: mp3lib(mpg123) or Win32(l3codeca.acm)
+   #define this if you prefer mpg123 (with 3Dnow! support) than l3codeca.acm
+   (with mmx/sse optimizations)
+   You can still change it runtime using -afm 1 (mpg123) or -afm 4 (l3codeca)*/
+#undef DEFAULT_MPG123
+
+/* XMMP support: (test code) */
+#undef USE_XMMP_AUDIO
+#define LIBDIR "/usr/local/lib"
+#define PLUGINDIR LIBDIR "/xmmp/Plugins"
+#define XMMP_AUDIO_DRIVER PLUGINDIR "/Sound/oss.so"
+
+/* LIRC (remote control, see www.lirc.org) support: */
+#undef HAVE_LIRC
+
+/* Define if your processor stores words with the most significant
+   byte first (like Motorola and SPARC, unlike Intel and VAX).  */
+/* #define WORDS_BIGENDIAN */
+
+#define ARCH_X86
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// NOTE: Instead of modifying these here, use the --enable/--disable options
+//       of the ./configure script! See ./configure --help for details.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/* termcap flag for getch2.c */
+#define USE_TERMCAP
+
+/* Extension defines */
+#undef HAVE_MLIB     // available only on solaris
+#undef HAVE_3DNOW   // only define if you have 3DNOW (AMD k6-2, AMD Athlon, iDT WinChip, etc.)
+#define HAVE_MMX      // only define if you have MMX
+#define HAVE_SSE     // only define if you have SSE (Intel Pentium III or Celeron II)
+
+/* libvo options */
+#define SCREEN_SIZE_X 1
+#define SCREEN_SIZE_Y 1
+#define HAVE_X11
+#undef HAVE_XV
+#define HAVE_GL
+#undef HAVE_SDL
+#undef HAVE_3DFX
+#define HAVE_MGA
+#define HAVE_SYNCFB
+
+#if defined(HAVE_GL)||defined(HAVE_X11)|defined(HAVE_XV)
+#define X11_FULLSCREEN
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config.mak	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,14 @@
+
+# -------- Generated by ./configure -----------
+
+AR=ar
+CC=gcc
+# OPTFLAGS=-O4 -march=i686 -mcpu=i686 -pipe -fomit-frame-pointer -ffast-math
+OPTFLAGS=-O4 -march=i686 -mcpu=i686 -pipe -ffast-math
+# LIBS=-L/usr/lib -L/usr/local/lib -L/usr/X11R6/lib -lGL  -lX11 -lXext 
+X_LIBS=-L/usr/X11R6/lib -lGL  -lX11 -lXext 
+TERMCAP_LIB=-ltermcap
+XMM_LIBS = 
+LIRC_LIBS = 
+WIN32_PATH=-DWIN32_PATH=\"/usr/lib/win32\"
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/configure	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,783 @@
+#!/bin/sh
+
+#
+# MPlayer configurator.   (C) 2000 Pontscho/fresh!mindworkz
+#				   pontscho@makacs.poliod.hu
+#
+# some changes by A'rpi/ESP-team:
+#  - some english bugfix :)
+#  - removed _??exists flags, _?? is enough...
+#  - creating only config.mak files instead of whole Makefiles
+#
+# some changes by LGB (Gábor Lénárt):
+#  - SOME gcc may support 'k7', so I added tests for ALL CPU type optimization
+#    switches with the ability to find out the best optimization for your CPU.
+#  - Help moved to the begining to avoid tests if user only wants help.
+#  - A one lined help to indicate detailed help for users
+#  - Fixed /tmp race (PIDs can be predicted, I added random numbers as well)
+#
+# some changes by A'rpi/ESP-team:
+#  - the --win32libdir patch by Aaron Hope applied
+#  - some english bugfix again :)
+#  - cpu type selection changed:
+#    ( k7->k6->k5-> ) || (i686->pentiumpro-> ) pentium-> i486 -> i386 -> error!
+#  - cpu type for AMD/family=5 changed k6->k5
+#
+# some changes by LGB:
+#  - Ehhh, AMD K6-2 returns with cpuid 5 ;-) Changing back Arpi's last change :)
+#    More info: AMD K6-2 reports with family 5, duron with 6, so I attached
+#    much finer CPU type detection based on Linux kernel's one :)
+#    (k5: 5, model<6, k6: 5, model>=6, k7: 6, model=any)
+#  - On some exit point (error) temporary files were not deleted. Fixed.
+#  - $TMP and $TMP2 are renamed to $TMPC and $TMPO ;-)
+#  - Some useless { ... } are removed
+#
+# some changes by A'rpi/ESP-team:
+#  - added 'athlon' target for the new athlongcc [Ian Kumlien]
+#  - applied _win32libdir=-L patch by Magnus Pfeffer
+#
+# --
+
+
+# LGB: Help moved here.
+
+if [ "$1" = "--help" -o "$1" = "-help" -o "$1" = "-h" ]; then
+cat << EOF
+
+usage: $0 [options]
+
+params:
+        --enable-mmx            build with mmx support [autodetect]
+        --enable-3dnow          build with 3dnow! support [autodetect]
+        --enable-sse            build with sse support [autodetect]
+        --enable-gl             build with OpenGL render support [autodetect]
+        --enable-sdl            build with SDL render support [def.: disabled!]
+        --enable-mga            build with mga_vid support [autodetect, if /dev/mga_vid
+                                is available]
+	--enable-xmga           build with mga_vid X Window support [autodetect,
+				if both /dev/mga_vid and x11 are available]
+        --enable-xv             build with Xv render support for X 4.x [autodetect]
+        --enable-x11            build with X11 render support [autodetect]
+	--enable-mlib		build with MLIB support ( only Solaris )
+
+	--enable-termcap	use termcap database for key codes
+	--enable-xmmp	        use XMMP audio drivers
+	--enable-lirc	        enable LIRC (remote control) support
+
+        --with-x11libdir=DIR    X library files are in DIR
+        --with-win32libdir=DIR  windows codec files
+
+	--size-x=SIZE		default screen width
+	--size-y=SIZE		default screen height
+EOF
+exit 0
+fi
+
+# LGB: Some inital help
+
+echo "You can get detailed help on configure with: $0 --help"
+echo "Please wait while ./configure discovers your software and hardware environment!"
+
+# LGB: temporary files
+
+TMPC="/tmp/mplayer-conf-${RANDOM}-$$-${RANDOM}.c"
+TMPO="/tmp/mplayer-conf-${RANDOM}-$$-${RANDOM}.o"
+
+
+# ---
+
+# config files
+CCONF='config.h'
+MCONF='config.mak'
+
+# ---
+
+TAB=`echo -n -e "\t"`
+pname=`cat /proc/cpuinfo | grep 'model name' | cut -d ':' -f 2`
+pparam=`cat /proc/cpuinfo | grep 'features' | cut -d ':' -f 2`
+if [ -z "$pparam" ]; then
+  pparam=`cat /proc/cpuinfo | grep 'flags' | cut -d ':' -f 2`
+fi
+pvendor=`cat /proc/cpuinfo | grep 'vendor_id' | cut -d ':' -f 2  | cut -d ' ' -f 2`
+pfamily=`cat /proc/cpuinfo | grep 'cpu family' | cut -d ':' -f 2 | cut -d ' ' -f 2`
+pmodel=`cat /proc/cpuinfo | grep "model$TAB" | cut -d ':' -f 2 | cut -d ' ' -f 2`
+pstepping=`cat /proc/cpuinfo | grep 'stepping' | cut -d ':' -f 2 | cut -d ' ' -f 2`
+
+_mmx=no
+_3dnow=no
+_mtrr=no
+_sse=no
+_mga=no
+_gl=no
+_sdl=no
+_xv=no
+_x11=no
+_3dfx=no
+_syncfb=no
+_mlib=no
+_mpg123=no
+_xmga=no
+_lirc=no
+
+_x=1
+_y=1
+
+_gllib=
+_sdllib=
+_x11lib=
+_xvlib=
+_xlibdir=
+
+for i in `echo $pparam`; do
+
+ case "$i" in
+  3dnow)
+        _3dnow=yes
+        _mpg123=yes
+        ;;
+  mmx)
+        _mmx=yes
+        ;;
+  mtrr)
+        _mtrr=yes
+        ;;
+  k6_mtrr)
+        _mtrr=yes
+        ;;
+  xmm)
+        _sse=yes
+        ;;
+  sse)
+        _sse=yes
+        ;;
+  kni)
+        _sse=yes
+        ;;
+ esac
+
+done
+
+if [ -e /usr/X11R6 ]; then
+ _x11libdir=-L/usr/X11R6/lib
+else
+ if [ -e /usr/X11 ]; then
+  _x11libdir=-L/usr/X11/lib
+ fi
+fi
+
+_win32libdirnotify=no
+if [ -e /usr/lib/win32 ]; then
+ _win32libdir=/usr/lib/win32
+else
+ if [ -e /usr/local/lib/win32 ]; then
+  _win32libdir=/usr/local/lib/win32
+ else
+# This is our default:
+  _win32libdir=/usr/lib/win32
+  _win32libdirnotify=yes
+ fi
+fi
+
+
+if [ -e /dev/mga_vid ]; then
+ _mga=yes
+ _syncfb=yes
+fi
+
+proc=pentium
+
+case "$pvendor" in
+ AuthenticAMD)
+   case "$pfamily" in
+    3)
+      proc=i386
+      ;;
+    4)
+      proc=i486
+      ;;
+    5)
+      if [ $pmodel -ge 6 ]; then	# LGB: models are: K5/SSA5 K5 K5 K5 ? ? K6 K6 K6-2 K6-3 
+    	    proc=k6
+      else
+    	    proc=k5
+      fi
+      ;;
+    6|7)				# LGB: Though it seems Athlon CPUs returns with "6"
+      proc=k7
+      ;;
+    *)
+      proc=pentium
+      ;;
+   esac
+   ;;
+ GenuineIntel)
+   case "$pfamily" in
+    3)
+      proc=i386
+      ;;
+    4)
+      proc=i486
+      ;;
+    5)
+      proc=pentium
+      ;;
+    6)
+      proc=i686
+      ;;
+    *)
+      proc=pentium
+      ;;
+   esac
+   ;;
+ unknown)              # added by Gabucino - upon Tibcu's request
+   case "$pfamily" in
+    3)
+      proc=i386
+      ;;
+    4)
+      proc=i486
+      ;;
+    *)
+      proc=pentium
+      ;;
+   esac
+   ;;
+ *)
+   proc=pentium
+   ;;
+esac
+
+# ---
+
+cat > $TMPC << EOF
+int main( void ) { return 0; }
+EOF
+
+# check that gcc supports our cpu, if not, fallback to pentium
+# LGB: check -mcpu and -march swithing step by step with enabling
+# to fall back till 386.
+
+#echo -n "Checking your GCC CPU optimalization abilities: "
+if [ "$proc" = "k7" ]; then
+#	echo -n "trying k7  "
+	gcc $TMPC -o $TMPO -march=$proc -mcpu=$proc &> /dev/null || proc=athlon
+fi
+if [ "$proc" = "athlon" ]; then
+#	echo -n "trying athlon  "
+	gcc $TMPC -o $TMPO -march=$proc -mcpu=$proc &> /dev/null || proc=k6
+fi
+if [ "$proc" = "k6" ]; then
+#	echo -n "trying k6  "
+	gcc $TMPC -o $TMPO -march=$proc -mcpu=$proc &> /dev/null || proc=k5
+fi
+if [ "$proc" = "k5" ]; then
+#	echo -n "trying k5  "
+	gcc $TMPC -o $TMPO -march=$proc -mcpu=$proc &> /dev/null || proc=pentium
+fi
+if [ "$proc" = "i686" ]; then
+#	echo -n "trying i686  "
+	gcc $TMPC -o $TMPO -march=$proc -mcpu=$proc &> /dev/null || proc=pentiumpro
+fi
+if [ "$proc" = "pentiumpro" ]; then
+#	echo -n "trying pentiumpro  "
+	gcc $TMPC -o $TMPO -march=$proc -mcpu=$proc &> /dev/null || proc=pentium
+fi
+if [ "$proc" = "pentium" ]; then
+#	echo -n "trying pentium  "
+	gcc $TMPC -o $TMPO -march=$proc -mcpu=$proc &> /dev/null || proc=i486
+fi
+if [ "$proc" = "i486" ]; then
+#	echo -n "trying i486  "
+	gcc $TMPC -o $TMPO -march=$proc -mcpu=$proc &> /dev/null || proc=i386
+fi
+if [ "$proc" = "i386" ]; then
+#	echo -n "trying i386  "
+	gcc $TMPC -o $TMPO -march=$proc -mcpu=$proc &> /dev/null || proc=error
+fi
+if [ "$proc" = "error" ]; then
+	echo
+	echo "Your gcc does not support even \"i386\" for '-march' and '-mcpu'." >&2
+	rm -f $TMPC $TMPO
+	exit
+fi
+#echo "DONE (${proc})."
+
+
+# check GL & X11 & Xext & Xv & SDL & termcap libs
+
+gcc $TMPC -o $TMPO $_x11libdir/ -lGL &> /dev/null && _gl=yes
+gcc $TMPC -o $TMPO $_x11libdir -lX11 -lXext &> /dev/null && _x11=yes
+gcc $TMPC -o $TMPO $_x11libdir -lXv &> /dev/null && _xv=yes
+gcc $TMPC -o $TMPO $_x11libdir -L/usr/local/lib/ -lpthread &> /dev/null || \
+ { echo "Lib pthread not found."; rm -f $TMPC $TMPO ; exit 1; }
+
+# SDL disabled by default (0.11pre22-) because of the compilation problems
+# this is very buggy & experimental code, use it only if you really need it!!
+_have_sdl=no
+gcc $TMPC -o $TMPO $_x11libdir -L/usr/local/lib/ -lSDL -lpthread &> /dev/null && _have_sdl=yes
+
+_termcap=no
+gcc $TMPC -o $TMPO -ltermcap &> /dev/null && _termcap=yes
+
+_binutils=no
+as libac3/downmix/downmix_i386.S -o $TMPO &> /dev/null && _binutils=yes
+
+cat > $TMPC << EOF
+#include <GL/gl.h>
+int main( void ) { return 0; }
+EOF
+
+gcc $TMPC -o $TMPO $_x11libdir/ -lGL &> /dev/null || \
+ { _gl=no; echo "GL includes not found!";}
+
+rm -f $TMPC $TMPO
+
+
+if [ $_x11 = 'yes' ]; then
+ if [ $_mga = 'yes' ]; then
+  _xmga=yes
+ fi
+fi
+
+# ---
+
+# check for the parameters.
+
+for ac_option
+do
+ case "$ac_option" in
+  --enable-sse)
+        _sse=yes
+        ;;
+  --enable-3dnow)
+        _3dnow=yes
+        ;;
+  --enable-mmx)
+        _mmx=yes
+        ;;
+  --enable-gl)
+        _gl=yes
+        ;;
+  --enable-sdl)
+        _sdl=yes
+        ;;
+  --enable-mga)
+        _mga=yes
+        ;;
+  --enable-xmga)
+        _xmga=yes
+        ;;	
+  --enable-xv)
+        _xv=yes
+        ;;
+  --enable-x11)
+        _x11=yes
+        ;;
+  --enable-3dfx)
+        _3dfx=yes
+        ;;
+  --enable-syncfb)
+        _syncfb=yes
+        ;;
+  --enable-mlib)
+	_mlib=yes
+	;;
+  --enable-termcap)
+	_termcap=yes
+	;;
+  --enable-xmmp)
+	_xmmp=yes
+	;;
+  --enable-lirc)
+	_lirc=yes
+	;;
+  --disable-sse)
+        _sse=no
+        ;;
+  --disable-3dnow)
+        _3dnow=no
+        ;;
+  --disable-mmx)
+        _mmx=no
+        ;;
+  --disable-gl)
+        _gl=no
+        ;;
+  --disable-sdl)
+        _sdl=no
+        ;;
+  --disable-mga)
+        _mga=no
+        ;;
+  --disable-xmga)
+        _xmga=no
+        ;;
+  --disable-xv)
+        _xv=no
+        ;;
+  --disable-x11)
+        _x11=no
+        ;;
+  --disable-mlib)
+	_mlib=no
+	;;
+  --disable-termcap)
+	_termcap=no
+	;;
+  --with-x11libdir=*)
+        _x11libdir=-L`echo $ac_option | cut -d '=' -f 2`
+        ;;
+  --with-win32libdir=*)
+        _win32libdir=`echo $ac_option | cut -d '=' -f 2`
+        ;;
+  --size-x=*)
+	_x=`echo $ac_option | cut -d '=' -f 2`
+	;;
+  --size-y=*)
+	_y=`echo $ac_option | cut -d '=' -f 2`
+	;;
+ esac
+done
+
+# to screen.
+
+echo "Checking for cpu vendor ... $pvendor ( $pfamily:$pmodel:$pstepping )"
+echo "Checking for cpu type ... $pname"
+echo "Optimizing to ... $proc"
+echo "Checking for mmx support ... $_mmx"
+echo "Checking for 3dnow support ... $_3dnow"
+echo "Checking for sse support ... $_sse"
+echo "Checking for mtrr support ... $_mtrr"
+echo "Screen size ... ${_x}x${_y}"
+echo "Checking for X11 libs ... $_x11libdir"
+echo "Checking mga_vid device ... $_mga"
+echo "Checking for xmga ... $_xmga" 
+echo "Checking for SDL ... $_sdl"
+echo "Checking for OpenGL ... $_gl"
+echo "Checking for Xv ... $_xv"
+echo "Checking for X11 ... $_x11"
+
+# write conf files.
+
+if [ $_gl = yes ]; then
+   _gllib='-lGL'
+fi
+
+if [ $_x11 = yes ]; then
+  _x11lib='-lX11 -lXext'
+fi
+
+if [ $_xv = yes ]; then
+  _xvlib='-lXv'
+fi
+
+if [ $_sdl = yes ]; then
+  _sdllib='-lSDL -lpthread' 
+fi
+
+if [ "$_termcap" = "yes" ]; then
+ _termcap='#define USE_TERMCAP'
+ _libtermcap='-ltermcap'
+else
+ _termcap='#undef USE_TERMCAP'
+ _libtermcap=''
+fi
+
+if [ "$_xmmp" = "yes" ]; then
+ _xmmpaudio='#define USE_XMMP_AUDIO'
+ _xmmplibs='-Llibxmm -lxmm'
+else
+ _xmmpaudio='#undef USE_XMMP_AUDIO'
+fi
+
+if [ "$_lirc" = "yes" ]; then
+ _lircdefs='#define HAVE_LIRC'
+ _lirclibs='-llirc_client'
+else
+ _lircdefs='#undef HAVE_LIRC'
+ _lirclibs=''
+fi
+
+
+echo
+echo "Creating $MCONF"
+cat > $MCONF << EOF
+
+# -------- Generated by ./configure -----------
+
+AR=ar
+CC=gcc
+# OPTFLAGS=-O4 -march=$proc -mcpu=$proc -pipe -fomit-frame-pointer -ffast-math
+OPTFLAGS=-O4 -march=$proc -mcpu=$proc -pipe -ffast-math
+# LIBS=-L/usr/lib -L/usr/local/lib $_x11libdir $_gllib $_sdllib $_x11lib $_xvlib
+X_LIBS=$_x11libdir $_gllib $_sdllib $_x11lib $_xvlib
+TERMCAP_LIB=$_libtermcap
+XMM_LIBS = $_xmmplibs
+LIRC_LIBS = $_lirclibs
+WIN32_PATH=-DWIN32_PATH=\"$_win32libdir\"
+
+EOF
+# echo 'CFLAGS=$(OPTFLAGS) -Wall -DMPG12PLAY' >> config.mak
+
+echo "Creating $CCONF"
+
+if [ "$_mmx" = "yes" ]; then
+ _mmx='#define HAVE_MMX'
+else
+ _mmx='#undef HAVE_MMX'
+fi
+
+if [ $_3dnow = yes ]; then
+ _3dnowm='#define HAVE_3DNOW'
+else
+ _3dnowm='#undef HAVE_3DNOW'
+fi
+
+if [ $_sse = yes ]; then
+ _ssem='#define HAVE_SSE'
+else
+ _ssem='#undef HAVE_SSE'
+fi
+
+# ---
+
+_vosrc=''
+
+if [ $_mlib = yes ]; then
+ _mlib='#define HAVE_MLIB'
+ _vosrc=$_vosrc' yuv2rgb_mlib.c'
+else
+ _mlib='#undef HAVE_MLIB'
+fi
+
+# ---
+
+if [ $_gl = yes ]; then
+ _gl='#define HAVE_GL'
+ _vosrc=$_vosrc' vo_gl.c'
+else
+ _gl='#undef HAVE_GL'
+fi
+
+if [ $_sdl = yes ]; then
+ _sdldef='#define HAVE_SDL'
+ _vosrc=$_vosrc' vo_sdl.c'
+else
+ _sdldef='#undef HAVE_SDL'
+fi
+
+if [ $_x11 = yes ]; then
+ _x11='#define HAVE_X11'
+ _vosrc=$_vosrc' vo_x11.c'
+else
+ _x11='#undef HAVE_X11'
+fi
+
+if [ $_xv = yes ]; then
+ _xv='#define HAVE_XV'
+ _vosrc=$_vosrc' vo_xv.c'
+else
+ _xv='#undef HAVE_XV'
+fi
+
+# ---
+
+if [ $_mga = yes ]; then
+ _mga='#define HAVE_MGA'
+ _vosrc=$_vosrc' vo_mga.c'
+else
+ _mga='#undef HAVE_MGA'
+fi
+if [ $_xmga = yes ]; then
+ _vosrc=$_vosrc' vo_xmga.c'
+fi
+
+if [ $_syncfb = yes ]; then
+ _syncfb='#define HAVE_SYNCFB'
+ _vosrc=$_vosrc' vo_syncfb.c'
+else
+ _syncfb='#undef HAVE_SYNCFB'
+fi
+
+if [ $_3dfx = yes ]; then
+ _3dfx='#define HAVE_3DFX'
+ _vosrc=$_vosrc' vo_3dfx.c'
+else
+ _3dfx='#undef HAVE_3DFX'
+fi
+
+if [ $_mpg123 = yes ]; then
+ _mpg123='#define DEFAULT_MPG123'
+else
+ _mpg123='#undef DEFAULT_MPG123'
+fi
+
+cat > $CCONF << EOF
+
+/* -------- Generated by ./configure ----------- */
+
+/* Define this to enable avg. byte/sec-based AVI sync method by default:
+   (use -bps or -nobps commandline option for run-time method selection)    */
+#undef AVI_SYNC_BPS
+
+/* Undefine this if you want soundcard-only timing by default:
+   You can still change this with the -alsa or -noalsa command-line option!
+   (This function was originally impemented to solve ALSA driver's big
+   buffer problems, but it seems to be useful for every soundcard drivers) */
+#define ALSA_TIMER
+
+/* Undefine this if your soundcard driver has no working select().
+   If you have kernel Oops, player hangups, or just no audio, you should
+   try to recompile MPlayer with this option disabled! */
+#define HAVE_AUDIO_SELECT
+
+/* You have a choice for MP3 decoding: mp3lib(mpg123) or Win32(l3codeca.acm)
+   #define this if you prefer mpg123 (with 3Dnow! support) than l3codeca.acm
+   (with mmx/sse optimizations)
+   You can still change it runtime using -afm 1 (mpg123) or -afm 4 (l3codeca)*/
+$_mpg123
+
+/* XMMP support: (test code) */
+$_xmmpaudio
+#define LIBDIR "/usr/local/lib"
+#define PLUGINDIR LIBDIR "/xmmp/Plugins"
+#define XMMP_AUDIO_DRIVER PLUGINDIR "/Sound/oss.so"
+
+/* LIRC (remote control, see www.lirc.org) support: */
+$_lircdefs
+
+/* Define if your processor stores words with the most significant
+   byte first (like Motorola and SPARC, unlike Intel and VAX).  */
+/* #define WORDS_BIGENDIAN */
+
+#define ARCH_X86
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// NOTE: Instead of modifying these here, use the --enable/--disable options
+//       of the ./configure script! See ./configure --help for details.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+/* termcap flag for getch2.c */
+$_termcap
+
+/* Extension defines */
+$_mlib     // available only on solaris
+$_3dnowm   // only define if you have 3DNOW (AMD k6-2, AMD Athlon, iDT WinChip, etc.)
+$_mmx      // only define if you have MMX
+$_ssem     // only define if you have SSE (Intel Pentium III or Celeron II)
+
+/* libvo options */
+#define SCREEN_SIZE_X $_x
+#define SCREEN_SIZE_Y $_y
+$_x11
+$_xv
+$_gl
+$_sdldef
+$_3dfx
+$_mga
+$_syncfb
+
+#if defined(HAVE_GL)||defined(HAVE_X11)|defined(HAVE_XV)
+#define X11_FULLSCREEN
+#endif
+
+EOF
+
+echo "Creating libvo/config.mak"
+
+_voobj=`echo $_vosrc | sed -e 's/\.c/\.o/g'`
+
+cat > libvo/config.mak << EOF
+
+include ../config.mak
+
+OPTIONAL_SRCS=$_vosrc
+OPTIONAL_OBJS=$_voobj
+
+EOF
+
+echo "Creating libac3/config.mak"
+
+if [ $_sse = yes ]; then
+ _downmixc='downmix/downmix_kni.S'
+ _downmixo='downmix/downmix_kni.o'
+else
+if [ $_binutils = yes ]; then
+ _downmixc='downmix/downmix_i386.S'
+ _downmixo='downmix/downmix_i386.o'
+else
+_downmixc='downmix/downmix.c'
+_downmixo='downmix/downmix.o'
+cat << EOF
+
+!!! Warning! fallback to slow downmix.c due the old binutils.
+!!! Upgrade for better audio decoding performance.
+
+EOF
+fi
+fi
+
+cat > libac3/config.mak << EOF
+
+include ../config.mak
+
+OPTIONAL_SRCS    = $_downmixc
+OPTIONAL_OBJS    = $_downmixo
+
+EOF
+
+echo "Creating mp3lib/config.mak"
+
+if [ $_3dnow = yes ]; then
+ _3dnowobjectsrcs='dct36_3dnow.s dct64_3dnow.s decode_3dnow.s'
+ _3dnowobjectobjs='dct36_3dnow.o dct64_3dnow.o decode_3dnow.o'
+else
+ _3dnowobjectsrcs=
+ _3dnowobjectobjs=
+fi
+
+cat > mp3lib/config.mak << EOF
+
+include ../config.mak
+
+OPTIONAL_SRCS = $_3dnowobjectsrcs
+OPTIONAL_OBJS = $_3dnowobjectobjs
+
+EOF
+
+cat << EOF
+
+Config files successfully generated by ./configure !
+Please check config.h and config.mak files, tune CPU
+and optimization flags if you don't like these defaults.
+You can compile the program with 'make dep;make' and
+install with  'make install'. Good luck!
+
+EOF
+
+if [ $_mtrr = yes ]; then
+ echo "Please check mtrr settings at /proc/mtrr (see DOCS/MTRR)"
+ echo
+fi
+
+if [ $_sdl = no ]; then
+if [ $_have_sdl = yes ]; then
+ echo "You have libSDL installed, but SDL support is disabled by default."
+ echo "If you want to compile MPlayer with SDL support, re-run ./configure"
+ echo "with --enable-sdl. But it's very buggy & experimental code, use it"
+ echo "only if you really need it! And it works(?) *ONLY* with SDL v1.1.7 !"
+ echo "(SDL driver is NOT supported, so do NOT report bugs relating to SDL!)"
+ echo
+fi
+fi
+
+if [ $_win32libdirnotify = yes ]; then
+ echo "Missing WIN32 codecs dir at $_win32libdir !"
+ echo "Make it and copy DLL files to there! (You can get them from your windows"
+ echo "directory or download ftp://thot.banki.hu/esp-team/linux/MPlayer/w32codec.zip"
+else
+ echo "Ok, Win32 codecs directory at $_win32libdir already exists."
+fi
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demux_asf.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,268 @@
+//  ASF file parser for DEMUXER v0.3  by A'rpi/ESP-team
+
+// based on asf file-format doc by Eugene [http://divx.euro.ru]
+
+//static float avi_pts_frametime=1.0f/25.0f;
+//static float avi_audio_pts=0;
+//static float avi_video_pts=0;
+
+//static int skip_video_frames=0;
+
+typedef struct __attribute__((packed)) {
+  unsigned char streamno;
+  unsigned char seq;
+  unsigned long x;
+  unsigned char flag;
+} ASF_segmhdr_t;
+
+
+static int demux_asf_read_packet(demuxer_t *demux,unsigned char *data,int len,int id,int seq,unsigned long time,unsigned short dur,int offs){
+  int d;
+//  int len;
+  int skip;
+  float pts=0;
+  unsigned char c=0;
+  demux_stream_t *ds=NULL;
+  
+  if(verbose>=4) printf("demux_asf.read_packet: id=%d seq=%d len=%d\n",id,seq,len);
+  
+#if 0
+  if(demux->video->id==-1) {
+    demux->video->id=asf_video_id;
+    if(verbose) printf("ASF video ID = %d\n",demux->video->id);
+  }
+  if(demux->audio->id==-1)
+    if(id!=asf_video_id && id!=demux->video->id){
+      demux->audio->id=id;
+      if(verbose) printf("ASF audio ID = %d\n",demux->audio->id);
+    }
+#endif
+
+  if(id==demux->audio->id){
+      // audio
+      ds=demux->audio;
+  } else 
+  if(id==demux->video->id){
+      // video
+      ds=demux->video;
+  }
+  
+  if(ds){
+    if(ds->asf_packet){
+      if(ds->asf_seq!=seq){
+        // closed segment, finalize packet:
+		if(ds==demux->audio)
+		  if(asf_scrambling_h>1 && asf_scrambling_w>1)
+		    asf_descrambling(ds->asf_packet->buffer,ds->asf_packet->len);
+        ds_add_packet(ds,ds->asf_packet);
+        ds->asf_packet=NULL;
+      } else {
+        // append data to it!
+        demux_packet_t* dp=ds->asf_packet;
+        if(dp->len!=offs && offs!=-1) printf("warning! fragment.len=%d BUT next fragment offset=%d  \n",dp->len,offs);
+        dp->buffer=realloc(dp->buffer,dp->len+len);
+        memcpy(dp->buffer+dp->len,data,len);
+        if(verbose>=4) printf("data appended! %d+%d\n",dp->len,len);
+        dp->len+=len;
+        // we are ready now.
+        return 1;
+      }
+    }
+    // create new packet:
+    { demux_packet_t* dp;
+      if(offs>0){
+        printf("warning!  broken fragment, %d bytes missing  \n",offs);
+        return 0;
+      }
+      dp=new_demux_packet(len);
+      memcpy(dp->buffer,data,len);
+      dp->pts=time*0.001f;
+//      if(ds==demux->video) printf("ASF time: %8d  dur: %5d  \n",time,dur);
+      dp->pos=demux->filepos;
+      ds->asf_packet=dp;
+      ds->asf_seq=seq;
+      // we are ready now.
+      return 1;
+    }
+  }
+
+  return 0;
+}
+
+//static int num_elementary_packets100=0;
+//static int num_elementary_packets101=0;
+
+// return value:
+//     0 = EOF or no stream found
+//     1 = successfully read a packet
+int demux_asf_fill_buffer(demuxer_t *demux){
+unsigned int id=0;
+unsigned int len;
+int skipped=0;
+int max_packs=128;
+int ret=0;
+
+  demux->filepos=stream_tell(demux->stream);
+  if(demux->filepos>=demux->endpos){
+          demux->stream->eof=1;
+          return 0;
+  }
+
+    stream_read(demux->stream,asf_packet,(int)fileh.packetsize);
+    if(demux->stream->eof) return 0; // EOF
+    
+    if(asf_packet[0]==0x82){
+            unsigned char flags=asf_packet[3];
+            unsigned char segtype=asf_packet[4];
+            unsigned char* p=&asf_packet[5];
+            unsigned char* p_end=p+(int)fileh.packetsize;
+            unsigned long time;
+            unsigned short duration;
+            int segs=1;
+            unsigned char segsizetype=0x80;
+            int seg;
+            int padding=0;
+            int plen;
+            
+            if(verbose>1){
+                int i;
+                for(i=0;i<16;i++) printf(" %02X",asf_packet[i]);
+                printf("\n");
+            }
+            
+            //if(segtype!=0x5d) printf("Warning! packet[4] != 0x5d  \n");
+
+            // Calculate packet size (plen):
+            if(flags&0x40){
+              // Explicit (absoulte) packet size
+              plen=p[0]|(p[1]<<8); p+=2;
+              if(verbose>1)printf("Explicit packet size specified: %d  \n",plen);
+              if(plen>fileh.packetsize) printf("Warning! plen>packetsize! (%d>%d)  \n",plen,(int)fileh.packetsize);
+              if(flags&(8|16)){
+                padding=p[0];p++;
+                if(flags&16){ padding|=p[0]<<8; p++;}
+                if(verbose)printf("Warning! explicit=%d  padding=%d  \n",plen,fileh.packetsize-padding);
+              }
+            } else {
+              // Padding (relative) size
+              if(flags&8){
+                padding=p[0];++p;
+              } else
+              if(flags&16){
+                padding=p[0]|(p[1]<<8);p+=2;
+              }
+              plen=fileh.packetsize-padding;
+            }
+
+            time=*((unsigned long*)p);p+=4;
+            duration=*((unsigned short*)p);p+=2;
+            if(flags&1){
+              segsizetype=p[0] & 0xC0;
+              segs=p[0] & 0x3F;
+              ++p;
+            }
+            if(verbose>=4) printf("%08X:  flag=%02X  segs=%d  pad=%d  time=%d  dur=%d\n",
+              demux->filepos,flags,segs,padding,time,duration);
+            for(seg=0;seg<segs;seg++){
+              //ASF_segmhdr_t* sh;
+              unsigned char streamno;
+              unsigned char seq;
+              int len;
+              unsigned long x;
+              unsigned char type;
+              unsigned long time2;
+
+              if(p>=p_end) printf("Warning! invalid packet 1, sig11 coming soon...\n");
+
+              if(verbose>1){
+                int i;
+                printf("seg %d:",seg);
+                for(i=0;i<16;i++) printf(" %02X",p[i]);
+                printf("\n");
+              }
+              
+              streamno=p[0]&0x7F;
+              seq=p[1];
+              p+=2;
+
+              switch(segtype){
+              case 0x55:
+                 x=*((unsigned char*)p);
+                 p++;
+                 break;
+              case 0x59:
+                 x=*((unsigned short*)p);
+                 p+=2;
+                 break;
+              case 0x5D:
+                 x=*((unsigned long*)p);
+                 p+=4;
+                 break;
+              default:
+                 printf("Warning! unknown segtype == 0x%2X  \n",segtype);
+              }
+
+              type=p[0]; p++;        // 0x01: grouping  0x08: single
+              
+              switch(type){
+              case 0x01:
+	        //printf("grouping: %02X  \n",p[0]);
+                ++p; // skip unknown byte
+                break;
+              case 0x08:
+                //printf("!!! obj_length = %d\n",*((unsigned long*)p));
+                p+=4;
+                time2=*((unsigned long*)p);p+=4;
+                break;
+              default:
+                printf("unknown segment type: 0x%02X  \n",type);
+              }
+
+              if(flags&1){
+                // multiple segments
+                if(segsizetype==0x40){
+                  len=*((unsigned char*)p);p++;        // 1 byte
+                } else {
+                  len=*((unsigned short*)p);p+=2;      // 2 byte
+                }
+              } else {
+                // single segment
+                len=plen-(p-asf_packet);
+              }
+              if(len<0 || (p+len)>=p_end){
+                printf("ASF_parser: warning! segment len=%d\n",len);
+              }
+              if(verbose>=4) printf("  seg #%d: streamno=%d  seq=%d  type=%02X  len=%d\n",seg,streamno,seq,type,len);
+
+              switch(type){
+              case 0x01:
+                // GROUPING:
+                //printf("ASF_parser: warning! grouping (flag=1) not yet supported!\n",len);
+                //printf("  total: %d  \n",len);
+		while(len>0){
+		  int len2=p[0];
+		  p++;
+                  //printf("  group part: %d bytes\n",len2);
+                  demux_asf_read_packet(demux,p,len2,streamno,seq,x,duration,-1);
+                  p+=len2;
+		  len-=len2+1;
+		}
+                if(len!=0){
+                  printf("ASF_parser: warning! groups total != len\n");
+                }
+                break;
+              case 0x08:
+                // NO GROUPING:
+                //printf("fragment offset: %d  \n",sh->x);
+                demux_asf_read_packet(demux,p,len,streamno,seq,time2,duration,x);
+                p+=len;
+                break;
+	      }
+              
+            } // for segs
+            return 1; // success
+    }
+    
+    printf("%08X:  UNKNOWN TYPE  %02X %02X %02X %02X %02X...\n",demux->filepos,asf_packet[0],asf_packet[1],asf_packet[2],asf_packet[3],asf_packet[4]);
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demux_avi.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,276 @@
+//  AVI file parser for DEMUXER v2.6  by A'rpi/ESP-team
+
+//static float avi_pts_frametime=1.0f/25.0f;
+static float avi_audio_pts=0;
+static float avi_video_pts=0;
+
+static int skip_video_frames=0;
+
+static inline int avi_stream_id(unsigned int id){
+  unsigned char *p=(unsigned char *)&id;
+  unsigned char a,b;
+  a=p[0]-'0'; b=p[1]-'0';
+  if(a>9 || b>9) return 100; // invalid ID
+  return a*10+b;
+}
+
+// Select ds from ID
+static inline demux_stream_t* demux_avi_select_stream(demuxer_t *demux,unsigned int id){
+  int stream_id=avi_stream_id(id);
+  if(stream_id==demux->audio->id) return demux->audio;
+  if(stream_id==demux->video->id) return demux->video;
+  if(id!=mmioFOURCC('J','U','N','K')){
+     // unknown
+     if(verbose>=2) printf("Unknown chunk: %.4s (%X)\n",&id,id);
+  }
+  return NULL;
+}
+
+static int demux_avi_read_packet(demuxer_t *demux,unsigned int id,unsigned int len,int idxpos){
+  int d;
+//  int len;
+  int skip;
+  float pts=0;
+  unsigned char c=0;
+  demux_stream_t *ds=demux_avi_select_stream(demux,id);
+  
+  if(verbose>=3) printf("demux_avi.read_packet: %X\n",id);
+
+  if(ds==demux->audio){
+            pts=avi_audio_pts;
+            avi_audio_pts=0;
+  } else 
+  if(ds==demux->video){
+     // video
+     if(skip_video_frames>0){
+       // drop frame (seeking)
+       --skip_video_frames;
+       ds=NULL;
+     } else {
+       pts=avi_video_pts;
+     }
+     // ezt a 2 sort lehet hogy fell kell majd cserelni:
+     //avi_video_pts+=avi_pts_frametime;
+     avi_video_pts+=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
+     avi_audio_pts=avi_video_pts;
+  }
+  
+//  len=stream_read_dword_le(demux->stream);
+  skip=(len+1)&(~1); // total bytes in this chunk
+  
+  if(ds){
+    if(verbose>=2) printf("DEMUX_AVI: Read %d data bytes from packet %04X\n",len,id);
+    ds_read_packet(ds,demux->stream,len,pts,idxpos);
+    skip-=len;
+  }
+  if(skip){
+    if(verbose>=2) printf("DEMUX_AVI: Skipping %d bytes from packet %04X\n",skip,id);
+    stream_skip(demux->stream,skip);
+  }
+  return ds?1:0;
+}
+
+//static int num_elementary_packets100=0;
+//static int num_elementary_packets101=0;
+
+// return value:
+//     0 = EOF or no stream found
+//     1 = successfully read a packet
+int demux_avi_fill_buffer(demuxer_t *demux){
+unsigned int id=0;
+unsigned int len;
+int skipped=0;
+int max_packs=128;
+int ret=0;
+
+do{
+  AVIINDEXENTRY *idx=NULL;
+  demux->filepos=stream_tell(demux->stream);
+  if(demux->filepos>=demux->endpos){
+          demux->stream->eof=1;
+          return 0;
+  }
+  if(stream_eof(demux->stream)) return 0;
+  if(avi_header.idx_size>0 && avi_header.idx_pos<avi_header.idx_size){
+    unsigned int pos;
+    
+    //if(avi_header.idx_pos<0) printf("Fatal! idx_pos=%d\n",avi_header.idx_pos);
+    
+    idx=&avi_header.idx[avi_header.idx_pos++];
+    
+    //printf("[%d]",avi_header.idx_pos);fflush(stdout);
+    
+    //stream_seek(demux->stream,idx.dwChunkOffset);
+    //printf("IDX  pos=%X  idx.pos=%X  idx.size=%X  idx.flags=%X\n",demux->filepos,
+    //  pos-4,idx->dwChunkLength,idx->dwFlags);
+    if(idx->dwFlags&AVIIF_LIST){
+      // LIST
+      continue;
+    }
+    if(!demux_avi_select_stream(demux,idx->ckid)){
+      if(verbose>2) printf("Skip chunk %.4s (0x%X)  \n",&idx->ckid,idx->ckid);
+      continue; // skip this chunk
+    }
+
+    pos=idx->dwChunkOffset+avi_header.idx_offset;
+    if(pos<avi_header.movi_start || pos>=avi_header.movi_end){
+      printf("ChunkOffset out of range!  current=0x%X  idx=0x%X  \n",demux->filepos,pos);
+      continue;
+    }
+#if 0
+    if(pos!=demux->filepos){
+      printf("Warning! pos=0x%X  idx.pos=0x%X  diff=%d   \n",demux->filepos,pos,pos-demux->filepos);
+    }
+#endif
+    stream_seek(demux->stream,pos);
+    id=stream_read_dword_le(demux->stream);
+    if(id!=idx->ckid){
+      printf("ChunkID mismatch! raw=%.4s idx=%.4s  \n",&id,&idx->ckid);
+      continue;
+    }
+    len=stream_read_dword_le(demux->stream);
+//    if((len&(~1))!=(idx->dwChunkLength&(~1))){
+//    if((len)!=(idx->dwChunkLength)){
+    if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){
+      printf("ChunkSize mismatch! raw=%d idx=%d  \n",len,idx->dwChunkLength);
+      continue;
+    }
+  } else {
+    id=stream_read_dword_le(demux->stream);
+    len=stream_read_dword_le(demux->stream);
+    if(id==mmioFOURCC('L','I','S','T')){
+      id=stream_read_dword_le(demux->stream);      // list type
+      continue;
+    }
+  }
+  ret=demux_avi_read_packet(demux,id,len,avi_header.idx_pos-1);
+      if(!ret && skip_video_frames<=0)
+        if(--max_packs==0){
+          demux->stream->eof=1;
+          printf("demux: file doesn't contain the selected audio or video stream\n");
+          return 0;
+        }
+} while(ret!=1);
+  return 1;
+}
+
+
+// return value:
+//     0 = EOF or no stream found
+//     1 = successfully read a packet
+int demux_avi_fill_buffer_ni(demuxer_t *demux,demux_stream_t* ds){
+unsigned int id=0;
+unsigned int len;
+int skipped=0;
+int max_packs=128;
+int ret=0;
+
+do{
+  AVIINDEXENTRY *idx=NULL;
+  int idx_pos=0;
+  demux->filepos=stream_tell(demux->stream);
+  
+  if(ds==demux->video) idx_pos=avi_header.idx_pos_a++; else
+  if(ds==demux->audio) idx_pos=avi_header.idx_pos_v++; else
+                       idx_pos=avi_header.idx_pos++;
+  
+  if(avi_header.idx_size>0 && idx_pos<avi_header.idx_size){
+    unsigned int pos;
+    idx=&avi_header.idx[idx_pos];
+    
+    if(idx->dwFlags&AVIIF_LIST){
+      // LIST
+      continue;
+    }
+    if(ds && demux_avi_select_stream(demux,idx->ckid)!=ds){
+      if(verbose>2) printf("Skip chunk %.4s (0x%X)  \n",&idx->ckid,idx->ckid);
+      continue; // skip this chunk
+    }
+
+    pos=idx->dwChunkOffset+avi_header.idx_offset;
+    if(pos<avi_header.movi_start || pos>=avi_header.movi_end){
+      printf("ChunkOffset out of range!  current=0x%X  idx=0x%X  \n",demux->filepos,pos);
+      continue;
+    }
+#if 0
+    if(pos!=demux->filepos){
+      printf("Warning! pos=0x%X  idx.pos=0x%X  diff=%d   \n",demux->filepos,pos,pos-demux->filepos);
+    }
+#endif
+    stream_seek(demux->stream,pos);
+
+    id=stream_read_dword_le(demux->stream);
+
+    if(stream_eof(demux->stream)) return 0;
+
+    if(id!=idx->ckid){
+      printf("ChunkID mismatch! raw=%.4s idx=%.4s  \n",&id,&idx->ckid);
+      continue;
+    }
+    len=stream_read_dword_le(demux->stream);
+//    if((len&(~1))!=(idx->dwChunkLength&(~1))){
+//    if((len)!=(idx->dwChunkLength)){
+    if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){
+      printf("ChunkSize mismatch! raw=%d idx=%d  \n",len,idx->dwChunkLength);
+      continue;
+    }
+  } else return 0;
+  ret=demux_avi_read_packet(demux,id,len,idx_pos);
+      if(!ret && skip_video_frames<=0)
+        if(--max_packs==0){
+          demux->stream->eof=1;
+          printf("demux: file doesn't contain the selected audio or video stream\n");
+          return 0;
+        }
+} while(ret!=1);
+  return 1;
+}
+
+
+// return value:
+//     0 = EOF or no stream found
+//     1 = successfully read a packet
+int demux_avi_fill_buffer_nini(demuxer_t *demux,demux_stream_t* ds){
+unsigned int id=0;
+unsigned int len;
+int skipped=0;
+int ret=0;
+int *fpos=NULL;
+
+  if(ds==demux->video) fpos=&avi_header.idx_pos_a; else
+  if(ds==demux->audio) fpos=&avi_header.idx_pos_v; else
+  return 0;
+
+  stream_seek(demux->stream,fpos[0]);
+
+do{
+
+  demux->filepos=stream_tell(demux->stream);
+  if(demux->filepos>=demux->endpos){
+          demux->stream->eof=1;
+          return 0;
+  }
+  if(stream_eof(demux->stream)) return 0;
+
+  id=stream_read_dword_le(demux->stream);
+  len=stream_read_dword_le(demux->stream);
+  if(id==mmioFOURCC('L','I','S','T')){
+      id=stream_read_dword_le(demux->stream);      // list type
+      continue;
+  }
+  
+  if(ds==demux_avi_select_stream(demux,id)){
+    // read it!
+    ret=demux_avi_read_packet(demux,id,len,avi_header.idx_pos-1);
+  } else {
+    // skip it!
+    int skip=(len+1)&(~1); // total bytes in this chunk
+    stream_skip(demux->stream,skip);
+  }
+  
+} while(ret!=1);
+  fpos[0]=stream_tell(demux->stream);
+  return 1;
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demux_mpg.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,228 @@
+//  MPG/VOB file parser for DEMUXER v2.5  by A'rpi/ESP-team
+
+static unsigned int read_mpeg_timestamp(stream_t *s,int c){
+  int d,e;
+  unsigned int pts;
+  d=stream_read_word(s);
+  e=stream_read_word(s);
+  if( ((c&1)!=1) || ((d&1)!=1) || ((e&1)!=1) ) return 0; // invalid pts
+  pts=(((c>>1)&7)<<30)|((d>>1)<<15)|(e>>1);
+  if(verbose>=3) printf("{%d}",pts);
+  return pts;
+}
+
+static char dvdaudio_table[256];
+//static unsigned int packet_start_pos=0;
+
+static int demux_mpg_read_packet(demuxer_t *demux,int id){
+  int d;
+  int len;
+  unsigned char c=0;
+  unsigned int pts=0;
+  unsigned int dts=0;
+  demux_stream_t *ds=NULL;
+  
+  if(verbose>=3) printf("demux_read_packet: %X\n",id);
+
+//  if(id==0x1BA) packet_start_pos=stream_tell(demux->stream);
+  if(id<0x1BC || id>0x1FF) return -1;
+  if(id==0x1BE) return -1; // padding stream
+  if(id==0x1BF) return -1; // private2
+
+  len=stream_read_word(demux->stream);
+  if(verbose>=3)  printf("PACKET len=%d",len);
+  if(len==0 || len>4096) return -2;  // invalid packet !!!!!!
+
+  while(len>0){   // Skip stuFFing bytes
+    c=stream_read_char(demux->stream);--len;
+    if(c!=0xFF)break;
+  }
+  if((c>>6)==1){  // Read (skip) STD scale & size value
+//    printf("  STD_scale=%d",(c>>5)&1);
+    d=((c&0x1F)<<8)|stream_read_char(demux->stream);
+    len-=2;
+//    printf("  STD_size=%d",d);
+    c=stream_read_char(demux->stream);
+  }
+  // Read System-1 stream timestamps:
+  if((c>>4)==2){
+    pts=read_mpeg_timestamp(demux->stream,c);
+    len-=4;
+  } else
+  if((c>>4)==3){
+    pts=read_mpeg_timestamp(demux->stream,c);
+    c=stream_read_char(demux->stream);
+    if((c>>4)!=1) pts=0; //printf("{ERROR4}");
+    dts=read_mpeg_timestamp(demux->stream,c);
+    len-=4+1+4;
+  } else
+  if((c>>6)==2){
+    int pts_flags;
+    int hdrlen;
+    // System-2 (.VOB) stream:
+    if((c>>4)&3) printf("Warning! Encrypted VOB file! (DeCSS not (yet) supported)\n");
+    c=stream_read_char(demux->stream); pts_flags=c>>6;
+    c=stream_read_char(demux->stream); hdrlen=c;
+    len-=2;
+    if(verbose>=3) printf("  hdrlen=%d  (len=%d)",hdrlen,len);
+    if(hdrlen>len) return -1; // invalid header length
+    if(pts_flags==2){
+      c=stream_read_char(demux->stream);
+      pts=read_mpeg_timestamp(demux->stream,c);
+      len-=5;hdrlen-=5;
+    } else
+    if(pts_flags==3){
+      c=stream_read_char(demux->stream);
+      pts=read_mpeg_timestamp(demux->stream,c);
+      c=stream_read_char(demux->stream);
+      dts=read_mpeg_timestamp(demux->stream,c);
+      len-=10;hdrlen-=10;
+    }
+    len-=hdrlen;
+    if(hdrlen>0) stream_skip(demux->stream,hdrlen); // skip header bytes
+    
+    //============== DVD Audio sub-stream ======================
+    if(id==0x1BD){
+      int aid=stream_read_char(demux->stream)&0x7F;--len;
+      ds=demux->audio;
+      if(ds->id==-1) ds->id=aid;
+      if(!dvdaudio_table[aid]){
+        dvdaudio_table[aid]=1;
+        printf("DVD Audio format: %s  ID=%d%s\n",
+          ((aid&0x70)==0x20)?"PCM":"AC3",aid,(ds->id==aid)?"  CURRENT":"");
+      }
+      if(len<3) return -1; // invalid audio packet
+      if(ds->id!=aid){
+        // drop packet (not selected channel)
+        ds=NULL;
+      } else {
+        // READ Packet: Skip additional audio header data:
+        c=stream_read_char(demux->stream);
+        c=stream_read_char(demux->stream);
+        c=stream_read_char(demux->stream);
+        len-=3;
+        if(ds->type==-1){
+          // autodetect type
+          ds->type=((aid&0x70)==0x20)?2:3;
+        }
+        if(ds->type==2 && len>=2){
+          // read PCM header
+          int head;
+          head=stream_read_char(demux->stream); head=c<<8;
+          c=stream_read_char(demux->stream);    head|=c;  len-=2;
+          while(len>0 && head!=0x180){
+            head=c<<8;
+            c=stream_read_char(demux->stream);
+            head|=c;--len;
+          }
+          if(!len) printf("End of packet while searching for PCM header\n");
+        }
+      }
+    }
+
+  } else {
+    //if(c!=0x0f) printf("  {ERROR5,c=%d}  \n",c);
+  }
+  if(verbose>=3) printf("\n");
+
+  if(len<=0 || len>4096) return -1;  // Invalid packet size
+  
+  if(id>=0x1C0 && id<=0x1DF){
+    // mpeg audio
+    int aid=id-0x1C0;
+    if(demux->audio->id==-1) demux->audio->id=aid;
+    if(demux->audio->id==aid){
+      ds=demux->audio;
+      if(ds->type==-1) ds->type=1;
+    }
+  } else
+  if(id>=0x1E0 && id<=0x1EF){
+    // mpeg video
+    int aid=id-0x1E0;
+    if(demux->video->id==-1) demux->video->id=aid;
+    if(demux->video->id==aid) ds=demux->video;
+  }
+
+  if(ds){
+    if(verbose>=2) printf("DEMUX_MPG: Read %d data bytes from packet %04X\n",len,id);
+//    printf("packet start = 0x%X  \n",stream_tell(demux->stream)-packet_start_pos);
+    ds_read_packet(ds,demux->stream,len,pts/90000.0f,0);
+    return 1;
+  }
+  if(verbose>=2) printf("DEMUX_MPG: Skipping %d data bytes from packet %04X\n",len,id);
+  stream_skip(demux->stream,len);
+  return 0;
+}
+
+static int num_elementary_packets100=0;
+static int num_elementary_packets101=0;
+
+int demux_mpg_es_fill_buffer(demuxer_t *demux){
+//if(demux->type==DEMUXER_TYPE_MPEG_ES)
+  // Elementary video stream
+  if(demux->stream->eof) return 0;
+  demux->filepos=stream_tell(demux->stream);
+  ds_read_packet(demux->video,demux->stream,4096,0,0);
+  return 1;
+}
+
+int demux_mpg_fill_buffer(demuxer_t *demux){
+unsigned int head=0;
+int skipped=0;
+int max_packs=128;
+int ret=0;
+
+// System stream
+do{
+  demux->filepos=stream_tell(demux->stream);
+  head=stream_read_dword(demux->stream);
+  while((head&0xffffff00)!=0x00000100){
+    if(stream_eof(demux->stream)) break;
+    head=(head<<8)|stream_read_char(demux->stream);
+    ++skipped; ++demux->filepos;
+  }
+  if(stream_eof(demux->stream)) break;
+  // sure: head=0x000001XX
+  if(demux->synced==0){
+    if(head==0x1BA) demux->synced=1;
+  } else
+  if(demux->synced==1){
+    if(head==0x1BB || (head>=0x1C0 && head<=0x1EF)){
+      demux->synced=2;
+      if(verbose) printf("system stream synced at 0x%X (%d)!\n",demux->filepos,demux->filepos);
+    } else demux->synced=0;
+  } // else
+  if(demux->synced==2){
+      ret=demux_mpg_read_packet(demux,head);
+      if(!ret)
+        if(--max_packs==0){
+          demux->stream->eof=1;
+          printf("demux: file doesn't contain the selected audio or video stream\n");
+          return 0;
+        }
+  } else {
+    if(head>=0x100 && head<0x1B0){
+      if(head==0x100)
+        ++num_elementary_packets100;
+      else
+        if(head==0x101) ++num_elementary_packets101;
+      if(verbose>=3) printf("Opps... elementary video packet found: %03X\n",head);
+    }
+#if 1
+    if(num_elementary_packets100>50 && num_elementary_packets101>50
+       && skipped>4000000){
+        if(verbose) printf("sync_mpeg_ps: seems to be ES stream...\n");
+        demux->stream->eof=1;
+        break;
+    }
+#endif
+  }
+} while(ret!=1);
+  if(verbose>=2) printf("demux: %d bad bytes skipped\n",skipped);
+  if(demux->stream->eof){
+    if(verbose>=2) printf("MPEG Stream reached EOF\n");
+    return 0;
+  }
+  return 1;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/demuxer.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,285 @@
+//=================== DEMUXER v2.5 =========================
+
+#define MAX_PACKS 2048
+#define MAX_PACK_BYTES 0x400000
+
+typedef struct demux_packet_st {
+  int len;
+  float pts;
+  int pos;  // pozicio indexben (AVI) ill. fileban (MPG)
+  unsigned char* buffer;
+  struct demux_packet_st* next;
+} demux_packet_t;
+
+inline demux_packet_t* new_demux_packet(int len){
+  demux_packet_t* dp=malloc(sizeof(demux_packet_t));
+  dp->len=len;
+  dp->buffer=malloc(len);
+  dp->next=NULL;
+  dp->pts=0;
+  dp->pos=0;
+  return dp;
+}
+
+inline void free_demux_packet(demux_packet_t* dp){
+  free(dp->buffer);
+  free(dp);
+}
+
+typedef struct {
+  int buffer_pos;          // current buffer position
+  int buffer_size;         // current buffer size
+  unsigned char* buffer;   // current buffer
+  float pts;               // current buffer's pts
+  int eof;                 // end of demuxed stream? (true if all buffer empty)
+  int pos;                 // position in the input stream (file)
+  int dpos;                // position in the demuxed stream
+//---------------
+  int packs;              // number of packets in buffer
+  int bytes;              // total bytes of packets in buffer
+  demux_packet_t *first;  // read to current buffer from here
+  demux_packet_t *last;   // append new packets from input stream to here
+  int id;                 // stream ID  (for multiple audio/video streams)
+  int type;               // stream type (currently used only for audio)
+  struct demuxer_st *demuxer; // parent demuxer structure (stream handler)
+// ---- asf -----
+  demux_packet_t *asf_packet;  // read asf fragments here
+  int asf_seq;
+} demux_stream_t;
+
+demux_stream_t* new_demuxer_stream(struct demuxer_st *demuxer,int id){
+  demux_stream_t* ds=malloc(sizeof(demux_stream_t));
+  ds->buffer_pos=ds->buffer_size=0;
+  ds->buffer=NULL;
+  ds->pts=0;
+  ds->eof=0;
+  ds->pos=0;
+  ds->dpos=0;
+//---------------
+  ds->packs=0;
+  ds->bytes=0;
+  ds->first=ds->last=NULL;
+  ds->id=id;
+  ds->type=-1;
+  ds->demuxer=demuxer;
+//----------------
+  ds->asf_seq=-1;
+  ds->asf_packet=NULL;
+  return ds;
+}
+
+#define DEMUXER_TYPE_UNKNOWN 0
+#define DEMUXER_TYPE_MPEG_ES 1
+#define DEMUXER_TYPE_MPEG_PS 2
+#define DEMUXER_TYPE_AVI 3
+#define DEMUXER_TYPE_AVI_NI 4
+#define DEMUXER_TYPE_AVI_NINI 5
+#define DEMUXER_TYPE_ASF 6
+
+#define DEMUXER_TIME_NONE 0
+#define DEMUXER_TIME_PTS 1
+#define DEMUXER_TIME_FILE 2
+#define DEMUXER_TIME_BPS 3
+
+typedef struct demuxer_st {
+  stream_t *stream;
+  int synced;  // stream synced (used by mpeg)
+  int filepos; // input stream current pos.
+  int endpos;  // input stream end pos. (return EOF fi filepos>endpos)
+  int type;    // mpeg system stream, mpeg elementary s., avi raw, avi indexed
+//  int time_src;// time source (pts/file/bps)
+  demux_stream_t *audio;
+  demux_stream_t *video;
+} demuxer_t;
+
+demuxer_t* new_demuxer(stream_t *stream,int type,int a_id,int v_id){
+  demuxer_t *d=malloc(sizeof(demuxer_t));
+  d->stream=stream;
+  d->synced=0;
+  d->filepos=0;
+  d->audio=new_demuxer_stream(d,a_id);
+  d->video=new_demuxer_stream(d,v_id);
+  d->type=type;
+  return d;
+}
+
+static void ds_add_packet(demux_stream_t *ds,demux_packet_t* dp){
+//    demux_packet_t* dp=new_demux_packet(len);
+//    stream_read(stream,dp->buffer,len);
+//    dp->pts=pts; //(float)pts/90000.0f;
+//    dp->pos=pos;
+    // append packet to DS stream:
+    ++ds->packs;
+    ds->bytes+=dp->len;
+    if(ds->last){
+      // next packet in stream
+      ds->last->next=dp;
+      ds->last=dp;
+    } else {
+      // first packet in stream
+      ds->first=ds->last=dp;
+    }
+    if(verbose>=2)
+      printf("DEMUX: Append packet to %s, len=%d  pts=%5.3f  pos=%d  [packs: A=%d V=%d]\n",
+        (ds==ds->demuxer->audio)?"d_audio":"d_video",
+        dp->len,dp->pts,dp->pos,ds->demuxer->audio->packs,ds->demuxer->video->packs);
+}
+
+static void ds_read_packet(demux_stream_t *ds,stream_t *stream,int len,float pts,int pos){
+    demux_packet_t* dp=new_demux_packet(len);
+    stream_read(stream,dp->buffer,len);
+    dp->pts=pts; //(float)pts/90000.0f;
+    dp->pos=pos;
+    // append packet to DS stream:
+    ds_add_packet(ds,dp);
+}
+
+
+// return value:
+//     0 = EOF or no stream found or invalid type
+//     1 = successfully read a packet
+int demux_mpg_es_fill_buffer(demuxer_t *demux);
+int demux_mpg_fill_buffer(demuxer_t *demux);
+int demux_avi_fill_buffer(demuxer_t *demux);
+int demux_avi_fill_buffer_ni(demuxer_t *demux,demux_stream_t *ds);
+int demux_avi_fill_buffer_nini(demuxer_t *demux,demux_stream_t *ds);
+int demux_asf_fill_buffer(demuxer_t *demux);
+
+int demux_fill_buffer(demuxer_t *demux,demux_stream_t *ds){
+  // Note: parameter 'ds' can be NULL!
+  switch(demux->type){
+    case DEMUXER_TYPE_MPEG_ES: return demux_mpg_es_fill_buffer(demux);
+    case DEMUXER_TYPE_MPEG_PS: return demux_mpg_fill_buffer(demux);
+    case DEMUXER_TYPE_AVI: return demux_avi_fill_buffer(demux);
+    case DEMUXER_TYPE_AVI_NI: return demux_avi_fill_buffer_ni(demux,ds);
+    case DEMUXER_TYPE_AVI_NINI: return demux_avi_fill_buffer_nini(demux,ds);
+    case DEMUXER_TYPE_ASF: return demux_asf_fill_buffer(demux);
+  }
+  return 0;
+}
+
+// return value:
+//     0 = EOF
+//     1 = succesfull
+inline static int ds_fill_buffer(demux_stream_t *ds){
+  demuxer_t *demux=ds->demuxer;
+  if(ds->buffer) free(ds->buffer);
+  if(verbose>2){
+    if(ds==demux->audio) printf("ds_fill_buffer(d_audio) called\n");else
+    if(ds==demux->video) printf("ds_fill_buffer(d_video) called\n");else
+                         printf("ds_fill_buffer(unknown 0x%X) called\n",ds);
+  }
+  while(1){
+    if(ds->packs){
+      demux_packet_t *p=ds->first;
+      // copy useful data:
+      ds->buffer=p->buffer;
+      ds->buffer_pos=0;
+      ds->buffer_size=p->len;
+      ds->pos=p->pos;
+      ds->dpos+=p->len; // !!!
+      ds->pts=p->pts;
+      // free packet:
+      ds->bytes-=p->len;
+      ds->first=p->next;
+      if(!ds->first) ds->last=NULL;
+      free(p);
+      --ds->packs;
+      return 1; //ds->buffer_size;
+    }
+    if(demux->audio->packs>=MAX_PACKS || demux->audio->bytes>=MAX_PACK_BYTES){
+      printf("\nDEMUXER: Too many (%d in %d bytes) audio packets in the buffer!\n",demux->audio->packs,demux->audio->bytes);
+      printf("(maybe you play a non-interleaved stream/file or audio codec failed)\n");
+      break;
+    }
+    if(demux->video->packs>=MAX_PACKS || demux->video->bytes>=MAX_PACK_BYTES){
+      printf("\nDEMUXER: Too many (%d in %d bytes) video packets in the buffer!\n",demux->video->packs,demux->video->bytes);
+      printf("(maybe you play a non-interleaved stream/file or video codec failed)\n");
+      break;
+    }
+    if(!demux_fill_buffer(demux,ds)) break; // EOF
+  }
+  ds->buffer_pos=ds->buffer_size=0;
+  ds->buffer=NULL;
+  if(verbose) printf("ds_fill_buffer: EOF reached (stream: %s)  \n",ds==demux->audio?"audio":"video");
+  ds->eof=1;
+  return 0;
+}
+
+inline int ds_tell(demux_stream_t *ds){
+  return (ds->dpos-ds->buffer_size)+ds->buffer_pos;
+}
+
+int demux_read_data(demux_stream_t *ds,char* mem,int len){
+int x;
+int bytes=0;
+while(len>0){
+  x=ds->buffer_size-ds->buffer_pos;
+  if(x==0){
+    if(!ds_fill_buffer(ds)) return bytes;
+  } else {
+    if(x>len) x=len;
+    if(mem) memcpy(mem+bytes,&ds->buffer[ds->buffer_pos],x);
+    bytes+=x;len-=x;ds->buffer_pos+=x;
+  }
+}
+return bytes;
+}
+
+
+#if 1
+#define demux_getc(ds) (\
+     (ds->buffer_pos<ds->buffer_size) ? ds->buffer[ds->buffer_pos++] \
+     :((!ds_fill_buffer(ds))? (-1) : ds->buffer[ds->buffer_pos++] ) )
+#else
+inline static int demux_getc(demux_stream_t *ds){
+  if(ds->buffer_pos>=ds->buffer_size){
+    if(!ds_fill_buffer(ds)){
+//      printf("DEMUX_GETC: EOF reached!\n");
+      return -1; // EOF
+    }
+  }
+//  printf("[%02X]",ds->buffer[ds->buffer_pos]);
+  return ds->buffer[ds->buffer_pos++];
+}
+#endif
+
+void ds_free_packs(demux_stream_t *ds){
+  demux_packet_t *dp=ds->first;
+  while(dp){
+    demux_packet_t *dn=dp->next;
+    free(dp->buffer);
+    free(dp);
+    dp=dn;
+  }
+  if(ds->asf_packet){
+    // free unfinished .asf fragments:
+    free(ds->asf_packet->buffer);
+    free(ds->asf_packet);
+    ds->asf_packet=NULL;
+  }
+  ds->first=ds->last=NULL;
+  ds->packs=0; // !!!!!
+  ds->bytes=0;
+  if(ds->buffer) free(ds->buffer);
+  ds->buffer=NULL;
+  ds->buffer_pos=ds->buffer_size;
+  ds->pts=0;
+}
+
+int ds_get_packet(demux_stream_t *ds,char **start){
+    while(1){
+        int len;
+        if(ds->buffer_pos>=ds->buffer_size){
+          if(!ds_fill_buffer(ds)){
+            // EOF
+            *start = NULL;
+            return -1;
+          }
+        }
+        len=ds->buffer_size-ds->buffer_pos;
+        *start = &ds->buffer[ds->buffer_pos];
+        ds->buffer_pos+=len;
+        return len;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dll_init.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,164 @@
+// ACM audio and VfW video codecs initialization
+// based on the avifile library [http://divx.euro.ru]
+
+int init_audio_codec(){
+    HRESULT ret;
+    WAVEFORMATEX *in_fmt=(WAVEFORMATEX*)&avi_header.wf_ext;
+    unsigned long srcsize=0;
+
+  if(verbose) printf("======= Win32 (ACM) AUDIO Codec init =======\n");
+
+    avi_header.srcstream=NULL;
+
+//    if(in_fmt->nSamplesPerSec==0){  printf("Bad WAVE header!\n");exit(1);  }
+//    MSACM_RegisterAllDrivers();
+
+    avi_header.wf.nChannels=in_fmt->nChannels;
+    avi_header.wf.nSamplesPerSec=in_fmt->nSamplesPerSec;
+    avi_header.wf.nAvgBytesPerSec=2*avi_header.wf.nSamplesPerSec*avi_header.wf.nChannels;
+    avi_header.wf.wFormatTag=WAVE_FORMAT_PCM;
+    avi_header.wf.nBlockAlign=2*in_fmt->nChannels;
+    avi_header.wf.wBitsPerSample=16;
+    avi_header.wf.cbSize=0;
+
+    win32_codec_name = avi_header.audio_codec;
+    ret=acmStreamOpen(&avi_header.srcstream,(HACMDRIVER)NULL,
+                    in_fmt,&avi_header.wf,
+		    NULL,0,0,0);
+    if(ret){
+        if(ret==ACMERR_NOTPOSSIBLE)
+            printf("ACM_Decoder: Unappropriate audio format\n");
+        else
+            printf("ACM_Decoder: acmStreamOpen error %d", ret);
+        avi_header.srcstream=NULL;
+        return 0;
+    }
+    if(verbose) printf("Audio codec opened OK! ;-)\n");
+
+    srcsize=in_fmt->nBlockAlign;
+    acmStreamSize(avi_header.srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_SOURCE);
+    if(srcsize<OUTBURST) srcsize=OUTBURST;
+    avi_header.audio_out_minsize=srcsize; // audio output min. size
+    if(verbose) printf("Audio ACM output buffer min. size: %d\n",srcsize);
+
+    acmStreamSize(avi_header.srcstream, srcsize, &srcsize, ACM_STREAMSIZEF_DESTINATION);
+    avi_header.audio_in_minsize=srcsize; // audio input min. size
+    if(verbose) printf("Audio ACM input buffer min. size: %d\n",srcsize);
+
+    return 1;
+}
+
+
+int init_video_codec(int outfmt){
+  HRESULT ret;
+
+  if(verbose) printf("======= Win32 (VFW) VIDEO Codec init =======\n");
+
+  memset(&avi_header.o_bih, 0, sizeof(BITMAPINFOHEADER));
+  avi_header.o_bih.biSize = sizeof(BITMAPINFOHEADER);
+
+  win32_codec_name = avi_header.video_codec;
+  avi_header.hic = ICOpen( 0x63646976, avi_header.bih.biCompression, ICMODE_FASTDECOMPRESS);
+//  avi_header.hic = ICOpen( 0x63646976, avi_header.bih.biCompression, ICMODE_DECOMPRESS);
+  if(!avi_header.hic){
+    printf("ICOpen failed! unknown codec / wrong parameters?\n");
+    return 0;
+  }
+
+//  avi_header.bih.biBitCount=32;
+
+  ret = ICDecompressGetFormat(avi_header.hic, &avi_header.bih, &avi_header.o_bih);
+  if(ret){
+    printf("ICDecompressGetFormat failed: Error %d\n", ret);
+    return 0;
+  }
+  if(verbose) printf("ICDecompressGetFormat OK\n");
+  
+//  printf("ICM_DECOMPRESS_QUERY=0x%X",ICM_DECOMPRESS_QUERY);
+
+//  avi_header.o_bih.biWidth=avi_header.bih.biWidth;
+//  avi_header.o_bih.biCompression = 0x32315659; //  mmioFOURCC('U','Y','V','Y');
+//  ret=ICDecompressGetFormatSize(avi_header.hic,&avi_header.o_bih);
+//  avi_header.o_bih.biCompression = 3; //0x32315659;
+//  avi_header.o_bih.biCompression = mmioFOURCC('U','Y','V','Y');
+//  avi_header.o_bih.biCompression = mmioFOURCC('U','Y','V','Y');
+//  avi_header.o_bih.biCompression = mmioFOURCC('Y','U','Y','2');
+//  avi_header.o_bih.biPlanes=3;
+//  avi_header.o_bih.biBitCount=16;
+
+  if(outfmt==IMGFMT_YUY2)
+    avi_header.o_bih.biBitCount=16;
+  else
+    avi_header.o_bih.biBitCount=outfmt&0xFF;//   //24;
+
+  avi_header.o_bih.biSizeImage=avi_header.o_bih.biWidth*avi_header.o_bih.biHeight*(avi_header.o_bih.biBitCount/8);
+
+  if(!avi_header.flipped)
+    avi_header.o_bih.biHeight=-avi_header.bih.biHeight; // flip image!
+
+  if(outfmt==IMGFMT_YUY2 && !avi_header.yuv_hack_needed)
+    avi_header.o_bih.biCompression = mmioFOURCC('Y','U','Y','2');
+
+//  avi_header.o_bih.biCompression = mmioFOURCC('U','Y','V','Y');
+
+
+  if(verbose) {
+    printf("Starting decompression, format:\n");
+	printf("  biSize %d\n", avi_header.bih.biSize);
+	printf("  biWidth %d\n", avi_header.bih.biWidth);
+	printf("  biHeight %d\n", avi_header.bih.biHeight);
+	printf("  biPlanes %d\n", avi_header.bih.biPlanes);
+	printf("  biBitCount %d\n", avi_header.bih.biBitCount);
+	printf("  biCompression %d='%.4s'\n", avi_header.bih.biCompression, &avi_header.bih.biCompression);
+	printf("  biSizeImage %d\n", avi_header.bih.biSizeImage);
+    printf("Dest fmt:\n");
+	printf("  biSize %d\n", avi_header.o_bih.biSize);
+	printf("  biWidth %d\n", avi_header.o_bih.biWidth);
+	printf("  biHeight %d\n", avi_header.o_bih.biHeight);
+	printf("  biPlanes %d\n", avi_header.o_bih.biPlanes);
+	printf("  biBitCount %d\n", avi_header.o_bih.biBitCount);
+	printf("  biCompression %d='%.4s'\n", avi_header.o_bih.biCompression, &avi_header.o_bih.biCompression);
+	printf("  biSizeImage %d\n", avi_header.o_bih.biSizeImage);
+  }
+
+  ret = ICDecompressQuery(avi_header.hic, &avi_header.bih, &avi_header.o_bih);
+  if(ret){
+    printf("ICDecompressQuery failed: Error %d\n", ret);
+    return 0;
+  }
+  if(verbose) printf("ICDecompressQuery OK\n");
+
+  
+  ret = ICDecompressBegin(avi_header.hic, &avi_header.bih, &avi_header.o_bih);
+  if(ret){
+    printf("ICDecompressBegin failed: Error %d\n", ret);
+    return 0;
+  }
+
+#if 0
+
+//avi_header.hic
+//ICSendMessage(HIC hic,unsigned int msg,long lParam1,long lParam2)
+{ int i;
+  for(i=73;i<256;i++){
+    printf("Calling ICM_USER+%d function...",i);fflush(stdout);
+    ret = ICSendMessage(avi_header.hic,ICM_USER+i,NULL,NULL);
+    printf(" ret=%d\n",ret);
+  }
+}
+#endif
+
+  avi_header.our_out_buffer = malloc(avi_header.o_bih.biSizeImage);
+  if(!avi_header.our_out_buffer){
+    printf("not enough memory for decoded picture buffer (%d bytes)\n", avi_header.o_bih.biSizeImage);
+    return 0;
+  }
+
+  if(outfmt==IMGFMT_YUY2 && avi_header.yuv_hack_needed)
+    avi_header.o_bih.biCompression = mmioFOURCC('Y','U','Y','2');
+
+//  avi_header.our_in_buffer=malloc(avi_header.video.dwSuggestedBufferSize); // FIXME!!!!
+  
+  if(verbose) printf("VIDEO CODEC Init OK!!! ;-)\n");
+  return 1;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/3dfx.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,154 @@
+/* 
+ *    3dfx.h
+ *
+ *	Copyright (C) Colin Cross Apr 2000
+ *	
+ *  mpeg2dec 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, or (at your option)
+ *  any later version.
+ *   
+ *  mpeg2dec 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 GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
+ *
+ */
+
+
+#define VOODOO_IO_REG_OFFSET     ((unsigned long int)0x0000000)
+#define VOODOO_YUV_REG_OFFSET    ((unsigned long int)0x0080100)
+#define VOODOO_AGP_REG_OFFSET    ((unsigned long int)0x0080000)
+#define VOODOO_2D_REG_OFFSET     ((unsigned long int)0x0100000)
+#define VOODOO_YUV_PLANE_OFFSET  ((unsigned long int)0x0C00000)
+
+#define VOODOO_BLT_FORMAT_YUYV   (8<<16)
+#define VOODOO_BLT_FORMAT_16     (3<<16)
+
+#define VOODOO_YUV_STRIDE        (1024>>2)
+
+struct voodoo_yuv_fb_t {
+  uint32_t Y[0x0040000];
+  uint32_t U[0x0040000];
+  uint32_t V[0x0040000];
+};
+
+struct voodoo_yuv_reg_t {
+  uint32_t yuvBaseAddr;
+  uint32_t yuvStride;
+};
+
+struct voodoo_2d_reg_t {
+  uint32_t status;
+  uint32_t intCtrl;
+  uint32_t clip0Min;
+  uint32_t clip0Max;
+  uint32_t dstBaseAddr;
+  uint32_t dstFormat;
+  uint32_t srcColorkeyMin;
+  uint32_t srcColorkeyMax;
+  uint32_t dstColorkeyMin;
+  uint32_t dstColorkeyMax;
+  signed long bresError0;
+  signed long bresError1;
+  uint32_t rop;
+  uint32_t srcBaseAddr;
+  uint32_t commandExtra;
+  uint32_t lineStipple;
+  uint32_t lineStyle;
+  uint32_t pattern0Alias;
+  uint32_t pattern1Alias;;
+  uint32_t clip1Min;
+  uint32_t clip1Max;
+  uint32_t srcFormat;
+  uint32_t srcSize;
+  uint32_t srcXY;
+  uint32_t colorBack;
+  uint32_t colorFore;
+  uint32_t dstSize;
+  uint32_t dstXY;
+  uint32_t command;
+  uint32_t RESERVED1;
+  uint32_t RESERVED2;
+  uint32_t RESERVED3;
+  uint8_t  launchArea[128];
+};
+
+
+struct voodoo_io_reg_t {
+  uint32_t status;
+  uint32_t pciInit0;
+  uint32_t sipMonitor;
+  uint32_t lfbMemoryConfig;
+  uint32_t miscInit0;
+  uint32_t miscInit1;
+  uint32_t dramInit0;
+  uint32_t dramInit1;
+  uint32_t agpInit;
+  uint32_t tmuGbeInit;
+  uint32_t vgaInit0;
+  uint32_t vgaInit1;
+  uint32_t dramCommand;
+  uint32_t dramData;
+  uint32_t RESERVED1;
+  uint32_t RESERVED2;
+
+  uint32_t pllCtrl0;
+  uint32_t pllCtrl1;
+  uint32_t pllCtrl2;
+  uint32_t dacMode;
+  uint32_t dacAddr;
+  uint32_t dacData;
+
+  uint32_t rgbMaxDelta;
+  uint32_t vidProcCfg;
+  uint32_t hwCurPatAddr;
+  uint32_t hwCurLoc;
+  uint32_t hwCurC0;
+  uint32_t hwCurC1;
+  uint32_t vidInFormat;
+  uint32_t vidInStatus;
+  uint32_t vidSerialParallelPort;
+  uint32_t vidInXDecimDeltas;
+  uint32_t vidInDecimInitErrs;
+  uint32_t vidInYDecimDeltas;
+  uint32_t vidPixelBufThold;
+  uint32_t vidChromaMin;
+  uint32_t vidChromaMax;
+  uint32_t vidCurrentLine;
+  uint32_t vidScreenSize;
+  uint32_t vidOverlayStartCoords;
+  uint32_t vidOverlayEndScreenCoord;
+  uint32_t vidOverlayDudx;
+  uint32_t vidOverlayDudxOffsetSrcWidth;
+  uint32_t vidOverlayDvdy;
+
+  uint32_t vga_registers_not_mem_mapped[12];
+  uint32_t vidOverlayDvdyOffset;
+  uint32_t vidDesktopStartAddr;
+  uint32_t vidDesktopOverlayStride;
+  uint32_t vidInAddr0;
+  uint32_t vidInAddr1;
+  uint32_t vidInAddr2;
+  uint32_t vidInStride;
+  uint32_t vidCurrOverlayStartAddr;
+};
+
+
+struct pioData_t {
+  short port;
+  short size;
+  int device;
+  void *value;
+};
+
+typedef struct pioData_t pioData;
+typedef struct voodoo_2d_reg_t voodoo_2d_reg;
+typedef struct voodoo_io_reg_t voodoo_io_reg;
+typedef struct voodoo_yuv_reg_t voodoo_yuv_reg;
+typedef struct voodoo_yuv_fb_t voodoo_yuv_fb;
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/Makefile	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,22 @@
+
+CC = gcc
+KERNEL_INCLUDES = /usr/src/linux/include
+INCLUDES = -I$(KERNEL_INCLUDES)
+CFLAGS = -g -O2  -Wall -D__KERNEL__  -DMODULE  	 -include $(KERNEL_INCLUDES)/linux/modversions.h
+
+all: mga_vid.o mga_vid_test sis_vid.o
+
+mga_vid.o: mga_vid.c mga_vid.h
+	$(CC) $(CFLAGS) $(INCLUDES) -c $(basename $@).c
+
+sis_vid.o: sis_vid.c sis_vid.h
+	$(CC) $(CFLAGS) $(INCLUDES) -c $(basename $@).c
+
+mga_vid_test: mga_vid_test.c
+	$(CC) -g -O -Wall $(INCLUDES) -o $@ $@.c
+
+clean: 
+	rm -f *.o *~
+
+distclean: clean
+	rm -f mga_vid_test
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/README	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,40 @@
+
+mga_vid  -  MGA G200/G400 YUV Overlay kernel module
+
+	Author:
+		Aaron Holtzman <aholtzma@ess.engr.uvic.ca>, Oct 1999
+
+	Contributions by:
+		Fredrik Vraalsen <vraalsen@cs.uiuc.edu>
+		Alan Cox <alan@lxorguk.ukuu.org.uk>
+
+                       WARNING  -----  WARNING
+
+This code messes with your video card and your xserver. It will probably
+lock up your box, format your hard drive, and cause your brand new g400 
+MAX to spout 6 inch flames. You have been warned.
+
+                       WARNING  -----  WARNING
+
+What does this code do?
+
+	 mga_vid is a kernel module that utilitizes the Matrox g200/g400 video 
+	 scaler/overlay unit to perform YUV->RGB colorspace conversion and
+	 arbitrary video scaling.
+
+	 mga_vid is also a monster hack.
+
+How does mga_vid work?
+
+	This kernel module sets up the BES (backend scaler) with approriate values
+	based on parameters supplied via ioctl. It also maps a chunk of video
+	memory into userspace via mmap. This memory is stolen from X (which may
+	decide to write to it later). The application can then write image data
+	directly to the frame buffer (if it knows the right padding, etc).
+
+
+How do I know if mga_vid works on my system?
+
+	There are test applications called mga_vid_test_g400 and mga_vid_test_g200.
+	Use the appropriate one for your card. This test code should draw some
+	nice 256x256 images for you if all is working well.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/mga_vid.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,877 @@
+// YUY2 support (see config.format) added by A'rpi/ESP-team
+
+/*
+ *
+ * mga_vid.c
+ *
+ * Copyright (C) 1999 Aaron Holtzman
+ * 
+ * Module skeleton based on gutted agpgart module by Jeff Hartmann 
+ * <slicer@ionet.net>
+ *
+ * Matrox MGA G200/G400 YUV Video Interface module Version 0.1.0
+ * 
+ * BES == Back End Scaler
+ * 
+ * This software has been released under the terms of the GNU Public
+ * license. See http://www.gnu.org/copyleft/gpl.html for details.
+ */
+
+//It's entirely possible this major conflicts with something else
+/* mknod /dev/mga_vid c 178 0 */
+
+#include <linux/config.h>
+#include <linux/version.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/malloc.h>
+#include <linux/pci.h>
+#include <linux/init.h>
+#include <linux/videodev.h>
+
+#include "mga_vid.h"
+
+#ifdef CONFIG_MTRR 
+#include <asm/mtrr.h>
+#endif
+
+#include <asm/uaccess.h>
+#include <asm/system.h>
+#include <asm/io.h>
+
+#define TRUE 1
+#define FALSE 0
+
+#define MGA_VID_MAJOR 178
+
+#define MGA_VIDMEM_SIZE mga_ram_size
+
+#ifndef PCI_DEVICE_ID_MATROX_G200_PCI 
+#define PCI_DEVICE_ID_MATROX_G200_PCI 0x0520
+#endif
+
+#ifndef PCI_DEVICE_ID_MATROX_G200_AGP 
+#define PCI_DEVICE_ID_MATROX_G200_AGP 0x0521
+#endif
+
+#ifndef PCI_DEVICE_ID_MATROX_G400 
+#define PCI_DEVICE_ID_MATROX_G400 0x0525
+#endif
+
+MODULE_AUTHOR("Aaron Holtzman <aholtzma@engr.uvic.ca>");
+
+
+typedef struct bes_registers_s
+{
+	//BES Control
+	uint32_t besctl;
+	//BES Global control
+	uint32_t besglobctl;
+	//Luma control (brightness and contrast)
+	uint32_t beslumactl;
+	//Line pitch
+	uint32_t bespitch;
+
+	//Buffer A-1 Chroma 3 plane org
+	uint32_t besa1c3org;
+	//Buffer A-1 Chroma org
+	uint32_t besa1corg;
+	//Buffer A-1 Luma org
+	uint32_t besa1org;
+
+	//Buffer A-2 Chroma 3 plane org
+	uint32_t besa2c3org;
+	//Buffer A-2 Chroma org
+	uint32_t besa2corg;
+	//Buffer A-2 Luma org
+	uint32_t besa2org;
+
+	//Buffer B-1 Chroma 3 plane org
+	uint32_t besb1c3org;
+	//Buffer B-1 Chroma org
+	uint32_t besb1corg;
+	//Buffer B-1 Luma org
+	uint32_t besb1org;
+
+	//Buffer B-2 Chroma 3 plane org
+	uint32_t besb2c3org;
+	//Buffer B-2 Chroma org
+	uint32_t besb2corg;
+	//Buffer B-2 Luma org
+	uint32_t besb2org;
+
+	//BES Horizontal coord
+	uint32_t beshcoord;
+	//BES Horizontal inverse scaling [5.14]
+	uint32_t beshiscal;
+	//BES Horizontal source start [10.14] (for scaling)
+	uint32_t beshsrcst;
+	//BES Horizontal source ending [10.14] (for scaling) 
+	uint32_t beshsrcend;
+	//BES Horizontal source last 
+	uint32_t beshsrclst;
+
+	
+	//BES Vertical coord
+	uint32_t besvcoord;
+	//BES Vertical inverse scaling [5.14]
+	uint32_t besviscal;
+	//BES Field 1 vertical source last position
+	uint32_t besv1srclst;
+	//BES Field 1 weight start
+	uint32_t besv1wght;
+	//BES Field 2 vertical source last position
+	uint32_t besv2srclst;
+	//BES Field 2 weight start
+	uint32_t besv2wght;
+
+} bes_registers_t;
+
+static bes_registers_t regs;
+static uint32_t mga_vid_in_use = 0;
+static uint32_t is_g400 = 0;
+static uint32_t vid_src_ready = 0;
+static uint32_t vid_overlay_on = 0;
+
+static uint8_t *mga_mmio_base = 0;
+static uint32_t mga_mem_base = 0; 
+static uint32_t mga_src_base = 0;
+
+static uint32_t mga_ram_size = 0;
+
+static struct pci_dev *pci_dev;
+
+static struct video_window mga_win;
+static mga_vid_config_t mga_config; 
+
+
+//All register offsets are converted to word aligned offsets (32 bit)
+//because we want all our register accesses to be 32 bits
+#define VCOUNT      0x1e20
+
+#define PALWTADD      0x3c00 // Index register for X_DATAREG port
+#define X_DATAREG     0x3c0a
+
+#define XMULCTRL      0x19
+#define BPP_8         0x00
+#define BPP_15        0x01
+#define BPP_16        0x02
+#define BPP_24        0x03
+#define BPP_32_DIR    0x04
+#define BPP_32_PAL    0x07
+
+#define XCOLMSK       0x40
+#define X_COLKEY      0x42
+#define XKEYOPMODE    0x51
+#define XCOLMSK0RED   0x52
+#define XCOLMSK0GREEN 0x53
+#define XCOLMSK0BLUE  0x54
+#define XCOLKEY0RED   0x55
+#define XCOLKEY0GREEN 0x56
+#define XCOLKEY0BLUE  0x57
+
+// Backend Scaler registers
+#define BESCTL      0x3d20
+#define BESGLOBCTL  0x3dc0
+#define BESLUMACTL  0x3d40
+#define BESPITCH    0x3d24
+#define BESA1C3ORG  0x3d60
+#define BESA1CORG   0x3d10
+#define BESA1ORG    0x3d00
+#define BESA2C3ORG  0x3d64 
+#define BESA2CORG   0x3d14
+#define BESA2ORG    0x3d04
+#define BESB1C3ORG  0x3d68
+#define BESB1CORG   0x3d18
+#define BESB1ORG    0x3d08
+#define BESB2C3ORG  0x3d6C
+#define BESB2CORG   0x3d1C
+#define BESB2ORG    0x3d0C
+#define BESHCOORD   0x3d28
+#define BESHISCAL   0x3d30
+#define BESHSRCEND  0x3d3C
+#define BESHSRCLST  0x3d50
+#define BESHSRCST   0x3d38
+#define BESV1WGHT   0x3d48
+#define BESV2WGHT   0x3d4c
+#define BESV1SRCLST 0x3d54
+#define BESV2SRCLST 0x3d58
+#define BESVISCAL   0x3d34
+#define BESVCOORD   0x3d2c
+#define BESSTATUS   0x3dc4
+
+
+static void mga_vid_frame_sel(int frame)
+{
+	//we don't need the vcount protection as we're only hitting
+	//one register (and it doesn't seem to be double buffered)
+	regs.besctl = (regs.besctl & ~0x07000000) + (frame << 25);
+	writel( regs.besctl, mga_mmio_base + BESCTL ); 
+}
+
+
+static void mga_vid_write_regs(void)
+{
+	//Make sure internal registers don't get updated until we're done
+	writel( (readl(mga_mmio_base + VCOUNT)-1)<<16,
+			mga_mmio_base + BESGLOBCTL);
+
+	// color or coordinate keying
+	writeb( XKEYOPMODE, mga_mmio_base + PALWTADD);
+	writeb( mga_config.colkey_on, mga_mmio_base + X_DATAREG);
+	if ( mga_config.colkey_on ) 
+	{
+		uint32_t r=0, g=0, b=0;
+
+		writeb( XMULCTRL, mga_mmio_base + PALWTADD);
+		switch (readb (mga_mmio_base + X_DATAREG)) 
+		{
+			case BPP_8:
+				/* Need to look up the color index, just using
+														 color 0 for now. */
+			break;
+
+			case BPP_15:
+				r = mga_config.colkey_red   >> 3;
+				g = mga_config.colkey_green >> 3;
+				b = mga_config.colkey_blue  >> 3;
+			break;
+
+			case BPP_16:
+				r = mga_config.colkey_red   >> 3;
+				g = mga_config.colkey_green >> 2;
+				b = mga_config.colkey_blue  >> 3;
+			break;
+
+			case BPP_24:
+			case BPP_32_DIR:
+			case BPP_32_PAL:
+				r = mga_config.colkey_red;
+				g = mga_config.colkey_green;
+				b = mga_config.colkey_blue;
+			break;
+		}
+
+		// Disable color keying on alpha channel 
+		writeb( XCOLMSK, mga_mmio_base + PALWTADD);
+		writeb( 0x00, mga_mmio_base + X_DATAREG);
+		writeb( X_COLKEY, mga_mmio_base + PALWTADD);
+		writeb( 0x00, mga_mmio_base + X_DATAREG);
+
+		// Set up color key registers
+		writeb( XCOLKEY0RED, mga_mmio_base + PALWTADD);
+		writeb( r, mga_mmio_base + X_DATAREG);
+		writeb( XCOLKEY0GREEN, mga_mmio_base + PALWTADD);
+		writeb( g, mga_mmio_base + X_DATAREG);
+		writeb( XCOLKEY0BLUE, mga_mmio_base + PALWTADD);
+		writeb( b, mga_mmio_base + X_DATAREG);
+
+		// Set up color key mask registers
+		writeb( XCOLMSK0RED, mga_mmio_base + PALWTADD);
+		writeb( 0xff, mga_mmio_base + X_DATAREG);
+		writeb( XCOLMSK0GREEN, mga_mmio_base + PALWTADD);
+		writeb( 0xff, mga_mmio_base + X_DATAREG);
+		writeb( XCOLMSK0BLUE, mga_mmio_base + PALWTADD);
+		writeb( 0xff, mga_mmio_base + X_DATAREG);
+	}
+
+	// Backend Scaler
+	writel( regs.besctl,      mga_mmio_base + BESCTL); 
+	if(is_g400)
+		writel( regs.beslumactl,  mga_mmio_base + BESLUMACTL); 
+	writel( regs.bespitch,    mga_mmio_base + BESPITCH); 
+
+	writel( regs.besa1org,    mga_mmio_base + BESA1ORG);
+	writel( regs.besa1corg,   mga_mmio_base + BESA1CORG);
+	writel( regs.besb1org,    mga_mmio_base + BESB1ORG);
+	writel( regs.besb1corg,   mga_mmio_base + BESB1CORG);
+	if(is_g400) 
+	{
+		writel( regs.besa1c3org,  mga_mmio_base + BESA1C3ORG);
+		writel( regs.besb1c3org,  mga_mmio_base + BESB1C3ORG);
+	}
+
+	writel( regs.beshcoord,   mga_mmio_base + BESHCOORD);
+	writel( regs.beshiscal,   mga_mmio_base + BESHISCAL);
+	writel( regs.beshsrcst,   mga_mmio_base + BESHSRCST);
+	writel( regs.beshsrcend,  mga_mmio_base + BESHSRCEND);
+	writel( regs.beshsrclst,  mga_mmio_base + BESHSRCLST);
+	
+	writel( regs.besvcoord,   mga_mmio_base + BESVCOORD);
+	writel( regs.besviscal,   mga_mmio_base + BESVISCAL);
+	writel( regs.besv1srclst, mga_mmio_base + BESV1SRCLST);
+	writel( regs.besv1wght,   mga_mmio_base + BESV1WGHT);
+	
+	//update the registers somewhere between 1 and 2 frames from now.
+	writel( regs.besglobctl + ((readl(mga_mmio_base + VCOUNT)+2)<<16),
+			mga_mmio_base + BESGLOBCTL);
+
+	printk("mga_vid: wrote BES registers\n");
+	printk("mga_vid: BESCTL = 0x%08x\n",
+			readl(mga_mmio_base + BESCTL));
+	printk("mga_vid: BESGLOBCTL = 0x%08x\n",
+			readl(mga_mmio_base + BESGLOBCTL));
+	printk("mga_vid: BESSTATUS= 0x%08x\n",
+			readl(mga_mmio_base + BESSTATUS));
+}
+
+static int mga_vid_set_config(mga_vid_config_t *config)
+{
+	int x, y, sw, sh, dw, dh;
+	int besleft, bestop, ifactor, ofsleft, ofstop, baseadrofs, weight, weights;
+	int frame_size;
+	x = config->x_org;
+	y = config->y_org;
+	sw = config->src_width;
+	sh = config->src_height;
+	dw = config->dest_width;
+	dh = config->dest_height;
+
+	printk("mga_vid: Setting up a %dx%d+%d+%d video window (src %dx%d) format %X\n",
+	       dw, dh, x, y, sw, sh, config->format);
+
+	//FIXME check that window is valid and inside desktop
+	
+	//FIXME figure out a better way to allocate memory on card
+	//allocate 2 megs
+	//mga_src_base = mga_mem_base + (MGA_VIDMEM_SIZE-2) * 0x100000;
+	mga_src_base = (MGA_VIDMEM_SIZE-2) * 0x100000;
+
+	
+	//Setup the BES registers for a three plane 4:2:0 video source 
+
+switch(config->format){
+    case MGA_VID_FORMAT_YV12:	
+	regs.besctl = 1         // BES enabled
+                    + (0<<6)    // even start polarity
+                    + (1<<10)   // x filtering enabled
+                    + (1<<11)   // y filtering enabled
+                    + (1<<16)   // chroma upsampling
+                    + (1<<17)   // 4:2:0 mode
+                    + (1<<18);  // dither enabled
+
+	if(is_g400)
+	{
+		//zoom disabled, zoom filter disabled, 420 3 plane format, proc amp
+		//disabled, rgb mode disabled 
+		regs.besglobctl = (1<<5);
+	}
+	else
+	{
+		//zoom disabled, zoom filter disabled, Cb samples in 0246, Cr
+		//in 1357, BES register update on besvcnt
+		regs.besglobctl = 0;
+	}
+        break;
+
+    case MGA_VID_FORMAT_YUY2:	
+	regs.besctl = 1         // BES enabled
+                    + (0<<6)    // even start polarity
+                    + (1<<10)   // x filtering enabled
+                    + (1<<11)   // y filtering enabled
+                    + (1<<16)   // chroma upsampling
+                    + (0<<17)   // 4:2:2 mode
+                    + (1<<18);  // dither enabled
+
+	regs.besglobctl = 0;        // YUY2 format selected
+        break;
+    default:
+	return -1;
+}
+
+
+	//Disable contrast and brightness control
+	regs.besglobctl = (1<<5) + (1<<7);
+	regs.beslumactl = (0x7f << 16) + (0x80<<0);
+	regs.beslumactl = 0x80<<0;
+
+	//Setup destination window boundaries
+	besleft = x > 0 ? x : 0;
+	bestop = y > 0 ? y : 0;
+	regs.beshcoord = (besleft<<16) + (x + dw-1);
+	regs.besvcoord = (bestop<<16) + (y + dh-1);
+	
+	//Setup source dimensions
+	regs.beshsrclst  = (sw - 1) << 16;
+	regs.bespitch = (sw + 31) & ~31 ; 
+	
+	//Setup horizontal scaling
+	ifactor = ((sw-1)<<14)/(dw-1);
+	ofsleft = besleft - x;
+		
+	regs.beshiscal = ifactor<<2;
+	regs.beshsrcst = (ofsleft*ifactor)<<2;
+	regs.beshsrcend = regs.beshsrcst + (((dw - ofsleft - 1) * ifactor) << 2);
+	
+	//Setup vertical scaling
+	ifactor = ((sh-1)<<14)/(dh-1);
+	ofstop = bestop - y;
+
+	regs.besviscal = ifactor<<2;
+
+	baseadrofs = ((ofstop*regs.besviscal)>>16)*regs.bespitch;
+	frame_size = ((sw + 31) & ~31) * sh + (((sw + 31) & ~31) * sh) / 2;
+	regs.besa1org = (uint32_t) mga_src_base + baseadrofs;
+	regs.besb1org = (uint32_t) mga_src_base + baseadrofs + frame_size;
+
+	if (is_g400) 
+		baseadrofs = (((ofstop*regs.besviscal)/4)>>16)*regs.bespitch;
+	else 
+		baseadrofs = (((ofstop*regs.besviscal)/2)>>16)*regs.bespitch;
+
+	regs.besa1corg = (uint32_t) mga_src_base + baseadrofs + regs.bespitch * sh ;
+	regs.besb1corg = (uint32_t) mga_src_base + baseadrofs + frame_size + regs.bespitch * sh;
+	regs.besa1c3org = regs.besa1corg + ((regs.bespitch * sh) / 4);
+	regs.besb1c3org = regs.besb1corg + ((regs.bespitch * sh) / 4);
+
+	weight = ofstop * (regs.besviscal >> 2);
+	weights = weight < 0 ? 1 : 0;
+	regs.besv1wght = (weights << 16) + ((weight & 0x3FFF) << 2);
+	regs.besv1srclst = sh - 1 - (((ofstop * regs.besviscal) >> 16) & 0x03FF);
+
+	mga_vid_write_regs();
+	return 0;
+}
+
+
+static int mga_vid_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+{
+	int frame;
+
+	switch(cmd) 
+	{
+		case MGA_VID_CONFIG:
+			//FIXME remove
+			printk("vcount = %d\n",readl(mga_mmio_base + VCOUNT));
+			printk("mga_mmio_base = %p\n",mga_mmio_base);
+			printk("mga_mem_base = %08lx\n",mga_mem_base);
+			//FIXME remove
+
+			printk("mga_vid: Received configuration\n");
+
+ 			if(copy_from_user(&mga_config,(mga_vid_config_t*) arg,sizeof(mga_vid_config_t)))
+			{
+				printk("mga_vid: failed copy from userspace\n");
+				return(-EFAULT);
+			}
+			if (is_g400) 
+			  mga_config.card_type = MGA_G400;
+			else
+			  mga_config.card_type = MGA_G200;
+		       
+			mga_config.ram_size = mga_ram_size;
+
+			if (copy_to_user((mga_vid_config_t *) arg, &mga_config, sizeof(mga_vid_config_t)))
+			{
+				printk("mga_vid: failed copy to userspace\n");
+				return(-EFAULT);
+			}
+			return mga_vid_set_config(&mga_config);	
+		break;
+
+		case MGA_VID_ON:
+			printk("mga_vid: Video ON\n");
+			vid_src_ready = 1;
+			if(vid_overlay_on)
+			{
+				regs.besctl |= 1;
+				mga_vid_write_regs();
+			}
+		break;
+
+		case MGA_VID_OFF:
+			printk("mga_vid: Video OFF\n");
+			vid_src_ready = 0;   
+			regs.besctl &= ~1;
+			mga_vid_write_regs();
+		break;
+			
+		case MGA_VID_FSEL:
+			if(copy_from_user(&frame,(int *) arg,sizeof(int)))
+			{
+				printk("mga_vid: FSEL failed copy from userspace\n");
+				return(-EFAULT);
+			}
+
+			mga_vid_frame_sel(frame);
+		break;
+
+	        default:
+			printk("mga_vid: Invalid ioctl\n");
+			return (-EINVAL);
+	}
+       
+	return 0;
+}
+
+
+static int mga_vid_find_card(void)
+{
+	struct pci_dev *dev = NULL;
+	unsigned int card_option, temp;
+
+	if((dev = pci_find_device(PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G400, NULL)))
+	{
+		is_g400 = 1;
+		printk("mga_vid: Found MGA G400\n");
+	}
+	else if((dev = pci_find_device(PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, NULL)))
+	{
+		is_g400 = 0;
+		printk("mga_vid: Found MGA G200 AGP\n");
+	}
+	else if((dev = pci_find_device(PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_PCI, NULL)))
+	{
+		is_g400 = 0;
+		printk("mga_vid: Found MGA G200 PCI\n");
+	}
+	else
+	{
+		printk("mga_vid: No supported cards found\n");
+		return FALSE;   
+	}
+
+	pci_dev = dev;
+	
+#if LINUX_VERSION_CODE >= 0x020300
+	mga_mmio_base = ioremap_nocache(dev->resource[1].start,0x4000);
+	mga_mem_base =  dev->resource[0].start;
+#else
+	mga_mmio_base = ioremap_nocache(dev->base_address[1] & PCI_BASE_ADDRESS_MEM_MASK,0x4000);
+	mga_mem_base =  dev->base_address[0] & PCI_BASE_ADDRESS_MEM_MASK;
+#endif
+	printk("mga_vid: MMIO at 0x%p\n", mga_mmio_base);
+	printk("mga_vid: Frame Buffer at 0x%08lX\n", mga_mem_base);
+
+	pci_read_config_dword(dev,  0x40, &card_option);
+	printk("OPTION word: 0x%08x\n", card_option);
+
+	temp = (card_option >> 10) & 0x17;
+
+	if (is_g400)
+	{
+		switch(temp)
+		{
+			default:
+				mga_ram_size = 16;
+		}
+	}
+	else
+	{
+		// a g200
+		switch(temp)
+		{
+			default:
+				mga_ram_size = 8;
+		}
+	}
+      
+	printk("mga_vid: RAMSIZE seems to be %d MB\n", (unsigned int) mga_ram_size);
+	
+	return TRUE;
+}
+
+
+static ssize_t mga_vid_read(struct file *file, char *buf, size_t count, loff_t *ppos)
+{
+	return -EINVAL;
+}
+
+static ssize_t mga_vid_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
+{
+	return -EINVAL;
+}
+
+static int mga_vid_mmap(struct file *file, struct vm_area_struct *vma)
+{
+
+	printk("mga_vid: mapping video memory into userspace\n");
+	if(remap_page_range(vma->vm_start, mga_mem_base + (MGA_VIDMEM_SIZE-2) * 0x100000,
+		 vma->vm_end - vma->vm_start, vma->vm_page_prot)) 
+	{
+		printk("mga_vid: error mapping video memory\n");
+		return(-EAGAIN);
+	}
+
+	return(0);
+}
+
+static int mga_vid_release(struct inode *inode, struct file *file)
+{
+	//Close the window just in case
+	vid_src_ready = 0;   
+	regs.besctl &= ~1;
+	mga_vid_write_regs();
+	mga_vid_in_use = 0;
+
+	//FIXME put back in!
+	//MOD_DEC_USE_COUNT;
+	return 0;
+}
+
+static long long mga_vid_lseek(struct file *file, long long offset, int origin)
+{
+	return -ESPIPE;
+}					 
+
+static int mga_vid_open(struct inode *inode, struct file *file)
+{
+	int minor = MINOR(inode->i_rdev);
+
+	if(minor != 0)
+	 return(-ENXIO);
+
+	if(mga_vid_in_use == 1) 
+		return(-EBUSY);
+
+	mga_vid_in_use = 1;
+	//FIXME turn me back on!
+	//MOD_INC_USE_COUNT;
+	return(0);
+}
+
+#if LINUX_VERSION_CODE >= 0x020400
+static struct file_operations mga_vid_fops =
+{
+	llseek:		mga_vid_lseek,
+	read:			mga_vid_read,
+	write:		mga_vid_write,
+	ioctl:		mga_vid_ioctl,
+	mmap:			mga_vid_mmap,
+	open:			mga_vid_open,
+	release: 	mga_vid_release
+};
+#else
+static struct file_operations mga_vid_fops =
+{
+	mga_vid_lseek,
+	mga_vid_read,
+	mga_vid_write,
+	NULL,
+	NULL,
+	mga_vid_ioctl,
+	mga_vid_mmap,
+	mga_vid_open,
+	NULL,
+	mga_vid_release
+};
+#endif
+
+static long mga_v4l_read(struct video_device *v, char *buf, unsigned long count, 
+	int noblock)
+{
+	return -EINVAL;
+}
+
+static long mga_v4l_write(struct video_device *v, const char *buf, unsigned long count, int noblock)
+{
+	return -EINVAL;
+}
+
+static int mga_v4l_open(struct video_device *dev, int mode)
+{
+	MOD_INC_USE_COUNT;
+	return 0;
+}
+
+static void mga_v4l_close(struct video_device *dev)
+{
+	regs.besctl &= ~1;
+	mga_vid_write_regs();
+	vid_overlay_on = 0;
+	MOD_DEC_USE_COUNT;
+	return;
+}
+
+static int mga_v4l_init_done(struct video_device *dev)
+{
+	return 0;
+}
+
+static int mga_v4l_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
+{
+	switch(cmd)
+	{
+		case VIDIOCGCAP:
+		{
+			struct video_capability b;
+			strcpy(b.name, "Matrox G200/400");
+			b.type = VID_TYPE_SCALES|VID_TYPE_OVERLAY|VID_TYPE_CHROMAKEY;
+			b.channels = 0;
+			b.audios = 0;
+			b.maxwidth = 1024;	/* GUESS ?? */
+			b.maxheight = 768;
+			b.minwidth = 32;
+			b.minheight = 16;	/* GUESS ?? */
+			if(copy_to_user(arg,&b,sizeof(b)))
+				return -EFAULT;
+			return 0;
+		}
+		case VIDIOCGPICT:
+		{
+			/*
+			 *	Default values.. if we can change this we
+			 *	can add the feature later
+			 */
+			struct video_picture vp;
+			vp.brightness = 0x8000;
+			vp.hue = 0x8000;
+			vp.colour = 0x8000;
+			vp.whiteness = 0x8000;
+			vp.depth = 8;
+			/* Format is a guess */
+			vp.palette = VIDEO_PALETTE_YUV420P;
+			if(copy_to_user(arg, &vp, sizeof(vp)))
+				return -EFAULT;
+			return 0;
+		}
+		case VIDIOCSPICT:
+		{
+			return -EINVAL;
+		}
+		case VIDIOCSWIN:
+		{
+			struct video_window vw;
+			if(copy_from_user(&vw, arg, sizeof(vw)))
+				return -EFAULT;
+			if(vw.x <0 || vw.y <0 || vw.width < 32 
+				|| vw.height < 16)
+				return -EINVAL;
+			memcpy(&mga_win, &vw, sizeof(mga_win));
+
+			mga_config.x_org = vw.x;
+			mga_config.y_org = vw.y;
+			mga_config.dest_width = vw.width;
+			mga_config.dest_height = vw.height;
+
+			/* 
+			 * May have to add 
+			 *
+			 * #define VIDEO_WINDOW_CHROMAKEY 16 
+			 *
+			 * to <linux/videodev.h> 
+			 */
+
+			//add it here for now
+			#define VIDEO_WINDOW_CHROMAKEY 16 
+
+			if (vw.flags & VIDEO_WINDOW_CHROMAKEY)
+				mga_config.colkey_on = 1;
+			else 
+				mga_config.colkey_on = 0;
+
+			mga_config.colkey_red   = (vw.chromakey >> 24) & 0xFF;
+			mga_config.colkey_green = (vw.chromakey >> 16) & 0xFF;
+			mga_config.colkey_blue  = (vw.chromakey >> 8)  & 0xFF;
+			mga_vid_set_config(&mga_config);
+			return 0;
+				
+		}
+		case VIDIOCGWIN:
+		{
+			if(copy_to_user(arg, &mga_win, sizeof(mga_win)))
+				return -EFAULT;
+			return 0;
+		}
+		case VIDIOCCAPTURE:
+		{
+			int v;
+			if(copy_from_user(&v, arg, sizeof(v)))
+				return -EFAULT;
+			vid_overlay_on = v;
+			if(vid_overlay_on && vid_src_ready)
+			{
+				regs.besctl |= 1;
+				mga_vid_write_regs();
+			}
+			else
+			{
+				regs.besctl &= ~1;
+				mga_vid_write_regs();
+			}
+			return 0;
+		}
+		default:
+			return -ENOIOCTLCMD;
+	}
+}
+
+static struct video_device mga_v4l_dev =
+{
+	"Matrox G200/G400",
+	VID_TYPE_CAPTURE,
+	VID_HARDWARE_BT848,		/* This is a lie for now */
+	mga_v4l_open,
+	mga_v4l_close,
+	mga_v4l_read,
+	mga_v4l_write,
+	NULL,
+	mga_v4l_ioctl,
+	NULL,
+	mga_v4l_init_done,
+	NULL,
+	0,
+	0
+};
+
+
+
+/* 
+ * Main Initialization Function 
+ */
+
+
+static int mga_vid_initialize(void)
+{
+	mga_vid_in_use = 0;
+
+	printk( "Matrox MGA G200/G400 YUV Video interface v0.01 (c) Aaron Holtzman \n");
+	if(register_chrdev(MGA_VID_MAJOR, "mga_vid", &mga_vid_fops))
+	{
+		printk("mga_vid: unable to get major: %d\n", MGA_VID_MAJOR);
+		return -EIO;
+	}
+
+	if (!mga_vid_find_card())
+	{
+		printk("mga_vid: no supported devices found\n");
+		unregister_chrdev(MGA_VID_MAJOR, "mga_vid");
+		return -EINVAL;
+	}
+	
+#if 0
+	if (video_register_device(&mga_v4l_dev, VFL_TYPE_GRABBER)<0)
+	{
+		printk("mga_vid: unable to register.\n");
+		unregister_chrdev(MGA_VID_MAJOR, "mga_vid");
+		if(mga_mmio_base)
+			iounmap(mga_mmio_base);
+		mga_mmio_base = 0;
+		return -EINVAL;
+	}
+#endif
+
+	return(0);
+}
+
+int init_module(void)
+{
+	return mga_vid_initialize();
+}
+
+void cleanup_module(void)
+{
+//	video_unregister_device(&mga_v4l_dev);
+	if(mga_mmio_base)
+		iounmap(mga_mmio_base);
+
+	//FIXME turn off BES
+	printk("mga_vid: Cleaning up module\n");
+	unregister_chrdev(MGA_VID_MAJOR, "mga_vid");
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/mga_vid.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,48 @@
+/*
+ *
+ * mga_vid.h
+ *
+ * Copyright (C) 1999 Aaron Holtzman
+ * 
+ * Matrox MGA G200/G400 YUV Video Interface module Version 0.1.0
+ * 
+ * BES == Back End Scaler
+ * 
+ * This software has been released under the terms of the GNU Public
+ * license. See http://www.gnu.org/copyleft/gpl.html for details.
+ */
+
+#ifndef __LINUX_MGAVID_H
+#define __LINUX_MGAVID_H
+
+#include <inttypes.h>
+
+typedef struct mga_vid_config_s
+{
+uint32_t card_type;
+uint32_t ram_size;
+uint32_t src_width;
+uint32_t src_height;
+uint32_t dest_width;
+uint32_t dest_height;
+uint32_t x_org;
+uint32_t y_org;
+uint8_t  colkey_on;
+uint8_t  colkey_red;
+uint8_t  colkey_green;
+uint8_t  colkey_blue;
+uint32_t format;
+} mga_vid_config_t;
+
+#define MGA_VID_FORMAT_YV12 0x32315659
+#define MGA_VID_FORMAT_YUY2 (('Y'<<24)|('U'<<16)|('Y'<<8)|'2')
+
+#define MGA_VID_CONFIG    _IOR('J', 1, mga_vid_config_t)
+#define MGA_VID_ON        _IO ('J', 2)
+#define MGA_VID_OFF       _IO ('J', 3)
+#define MGA_VID_FSEL _IOR('J', 4, int)
+
+#define MGA_G200 0x1234
+#define MGA_G400 0x5678
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/mga_vid_test.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,221 @@
+/*
+ *
+ * mga_vid_test.c
+ *
+ * Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ * Sept 1999
+ *
+ * This software has been released under the terms of the GNU Public
+ * license. See http://www.gnu.org/copyleft/gpl.html for details.
+ */
+
+//#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include "mga_vid.h"
+
+mga_vid_config_t config;
+uint8_t *mga_vid_base;
+uint32_t is_g400;
+
+#define SRC_IMAGE_WIDTH 256
+#define SRC_IMAGE_HEIGHT 256
+
+uint8_t y_image[SRC_IMAGE_WIDTH * SRC_IMAGE_HEIGHT];
+uint8_t cr_image[SRC_IMAGE_WIDTH * SRC_IMAGE_HEIGHT];
+uint8_t cb_image[SRC_IMAGE_WIDTH * SRC_IMAGE_HEIGHT];
+
+
+void
+write_frame_g200(uint8_t *y,uint8_t *cr, uint8_t *cb)
+{
+	uint8_t *dest;
+	uint32_t bespitch,h,w;
+
+	dest = mga_vid_base;
+	bespitch = (config.src_width + 31) & ~31;
+
+	for(h=0; h < config.src_height; h++) 
+	{
+		memcpy(dest, y, config.src_width);
+		y += config.src_width;
+		dest += bespitch;
+	}
+
+	for(h=0; h < config.src_height/2; h++) 
+	{
+		for(w=0; w < config.src_width/2; w++) 
+		{
+			*dest++ = *cb++;
+			*dest++ = *cr++;
+		}
+		dest += bespitch - config.src_width;
+	}
+}
+
+void
+write_frame_g400(uint8_t *y,uint8_t *cr, uint8_t *cb)
+{
+	uint8_t *dest;
+	uint32_t bespitch,h;
+
+	dest = mga_vid_base;
+	bespitch = (config.src_width + 31) & ~31;
+
+	for(h=0; h < config.src_height; h++) 
+	{
+		memcpy(dest, y, config.src_width);
+		y += config.src_width;
+		dest += bespitch;
+	}
+
+	for(h=0; h < config.src_height/2; h++) 
+	{
+		memcpy(dest, cb, config.src_width/2);
+		cb += config.src_width/2;
+		dest += bespitch/2;
+	}
+
+	for(h=0; h < config.src_height/2; h++) 
+	{
+		memcpy(dest, cr, config.src_width/2);
+		cr += config.src_width/2;
+		dest += bespitch/2;
+	}
+}
+
+void write_frame(uint8_t *y,uint8_t *cr, uint8_t *cb)
+{
+	if(is_g400)
+		write_frame_g400(y,cr,cb);
+	else
+		write_frame_g200(y,cr,cb);
+}
+
+void
+draw_cool_pattern(void)
+{
+	int i,x,y;
+
+	i = 0;
+	for (y=0; y<config.src_height; y++) {
+		for (x=0; x<config.src_width; x++) {
+			y_image[i++] = x*x/2 + y*y/2 - 128;
+		}
+	}
+
+	i = 0;
+	for (y=0; y<config.src_height/2; y++) 
+		for (x=0; x<config.src_width/2; x++) 
+		{
+				cr_image[i++] = x - 128;
+		}
+
+	i = 0;
+	for (y=0; y<config.src_height/2; y++) 
+		for (x=0; x<config.src_width/2; x++) 
+		{
+				cb_image[i++] = y - 128;
+		}
+}
+
+void
+draw_color_blend(void)
+{
+	int i,x,y;
+
+	i = 0;
+	for (y=0; y<config.src_height; y++) {
+		for (x=0; x<config.src_width; x++) {
+			y_image[i++] = 0;
+		}
+	}
+
+	i = 0;
+	for (y=0; y<config.src_height/2; y++) 
+		for (x=0; x<config.src_width/2; x++) 
+		{
+				cr_image[i++] = x - 128;
+		}
+
+	i = 0;
+	for (y=0; y<config.src_height/2; y++) 
+		for (x=0; x<config.src_width/2; x++) 
+		{
+				cb_image[i++] = y - 128;
+		}
+}
+
+
+int 
+main(int argc, char *argv[])
+{
+	int f;
+
+	f = open("/dev/mga_vid",O_RDWR);
+
+	if(f == -1)
+	{
+		fprintf(stderr,"Couldn't open driver\n");
+		exit(1);
+	}
+
+	config.src_width = SRC_IMAGE_WIDTH;
+	config.src_height= SRC_IMAGE_HEIGHT;
+	config.dest_width = SRC_IMAGE_WIDTH;
+	config.dest_height = SRC_IMAGE_HEIGHT;
+	config.x_org= 10;
+	config.y_org= 10;
+	config.colkey_on = 0;
+        config.format = MGA_VID_FORMAT_YV12;
+
+	if (ioctl(f,MGA_VID_CONFIG,&config))
+	{
+		perror("Error in config ioctl");
+	}
+
+	if (config.card_type == MGA_G200) 
+	{
+		printf("Testing MGA G200 Backend Scaler with %d MB of RAM\n", config.ram_size);
+	  is_g400 = 0;
+	}
+	else
+	{
+		printf("Testing MGA G400 Backend Scaler with %d MB of RAM\n", config.ram_size);
+	  is_g400 = 1;
+	}
+	
+	ioctl(f,MGA_VID_ON,0);
+	mga_vid_base = (uint8_t*)mmap(0,256 * 4096,PROT_WRITE,MAP_SHARED,f,0);
+	printf("mga_vid_base = %8p\n",mga_vid_base);
+
+
+	//memset(y_image,80,256 * 128);
+	//memset(cr_image,80,256/2 * 20);
+	//memset(cb_image,80,256/2 * 20);
+	write_frame(y_image,cr_image,cb_image);
+	printf("(1) There should be a green square, offset by 10 pixels from\n"
+			   "    the upper left corner displayed\n");
+	sleep(3);
+
+
+	draw_cool_pattern();
+	write_frame(y_image,cr_image,cb_image);
+	printf("(2) There should be a cool mosaic like pattern now.\n");
+	sleep(3);
+
+	draw_color_blend();
+	write_frame(y_image,cr_image,cb_image);
+	printf("(3) There should be a color blend with black, red, purple, blue\n"
+			   "    corners (starting top left going CW)\n");
+	sleep(3);
+
+	ioctl(f,MGA_VID_OFF,0);
+
+	close(f);
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/sis_vid.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,645 @@
+/*
+ *
+ * sis_vid.c
+ *
+ * Copyright (C) 2000 Aaron Holtzman
+ * 
+ * This software has been released under the terms of the GNU Public
+ * license. See http://www.gnu.org/copyleft/gpl.html for details.
+ */
+
+// video4linux interface disabled by A'rpi/ESP-team
+
+
+//It's entirely possible this major conflicts with something else
+/* mknod /dev/mga_vid c 178 0 */
+
+#include <linux/config.h>
+#include <linux/version.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/malloc.h>
+#include <linux/pci.h>
+#include <linux/init.h>
+//#include <linux/videodev.h>
+
+#include "sis_vid.h"
+
+#ifdef CONFIG_MTRR 
+#include <asm/mtrr.h>
+#endif
+
+#include <asm/uaccess.h>
+#include <asm/system.h>
+#include <asm/io.h>
+
+#define TRUE 1
+#define FALSE 0
+
+#define MGA_VID_MAJOR 178
+
+
+#ifndef PCI_DEVICE_ID_SI_6323 
+#define PCI_DEVICE_ID_SI_6323 0x6326
+#endif
+
+
+MODULE_AUTHOR("Aaron Holtzman <aholtzma@engr.uvic.ca>");
+
+
+typedef struct bes_registers_s
+{
+	//base address of yuv framebuffer
+	uint32_t yuv_base;
+	uint32_t u_base;
+	uint32_t v_base;
+	uint32_t fb_end;;
+
+	//frame buffer pitch 
+	uint32_t pitch;
+
+	//window boundaries
+	uint32_t left;
+	uint32_t right;
+	uint32_t top;
+	uint32_t bottom;
+
+	//control registers
+	uint32_t misc_0;
+	uint32_t misc_1;
+	uint32_t misc_3;
+	uint32_t misc_4;
+
+	//key overlay mode
+	uint32_t key_mode;
+
+} bes_registers_t;
+
+static bes_registers_t regs;
+static uint32_t mga_vid_in_use = 0;
+static uint32_t vid_src_ready = 0;
+static uint32_t vid_overlay_on = 0;
+
+static uint8_t *mga_mmio_base = 0;
+static uint32_t mga_mem_base = 0; 
+static uint32_t mga_src_base = 0;
+
+static uint32_t mga_ram_size = 0;
+
+static struct pci_dev *pci_dev;
+
+//static struct video_window mga_win;
+static mga_vid_config_t mga_config; 
+
+
+
+// Backend Scaler registers
+
+#define MISC_0 0x98
+#define MISC_1 0x99
+#define MISC_3 0x9d
+#define MISC_4 0xb6
+
+
+
+
+static void mga_vid_frame_sel(int frame)
+{
+	//we don't need the vcount protection as we're only hitting
+	//one register (and it doesn't seem to be double buffered)
+	//regs.besctl = (regs.besctl & ~0x07000000) + (frame << 25);
+	//writel( regs.besctl, mga_mmio_base + BESCTL ); 
+}
+
+
+#define WRITE_REG(x,y,z) {outb((y),(x));outb((z),(x+1));}
+#define READ_REG(x,y) (outb((y),(x)),inb(x+1))
+#define VIDEO_ACCEL 0x3d4
+
+static void mga_vid_write_regs(void)
+{
+	uint32_t foo;
+
+	//unlock the video accel registers
+	WRITE_REG(VIDEO_ACCEL,0x80,0x86);
+	foo = READ_REG(VIDEO_ACCEL,0x80);
+
+	if(foo != 0xa1)
+		return; //something bad happened
+
+	//setup the horizontal window bounds
+	WRITE_REG(VIDEO_ACCEL,0x81,regs.left & 0xff);
+	WRITE_REG(VIDEO_ACCEL,0x82,regs.right & 0xff);
+	WRITE_REG(VIDEO_ACCEL,0x83,(regs.left >> 8) | ((regs.right>>4) & 0x70));
+
+	//setup the vertical window bounds
+	WRITE_REG(VIDEO_ACCEL,0x84,regs.top & 0xff);
+	WRITE_REG(VIDEO_ACCEL,0x85,regs.bottom & 0xff);
+	WRITE_REG(VIDEO_ACCEL,0x86,(regs.top >> 8) | ((regs.bottom>>4) & 0x70));
+
+	//setup the framebuffer base addresses
+	WRITE_REG(VIDEO_ACCEL,0x8a,regs.yuv_base & 0xff);
+	WRITE_REG(VIDEO_ACCEL,0x8b,(regs.yuv_base >> 8) & 0xff);
+	WRITE_REG(VIDEO_ACCEL,0x89,(regs.yuv_base >> 12) & 0xf0);
+
+	WRITE_REG(VIDEO_ACCEL,0xb7,regs.u_base & 0xff);
+	WRITE_REG(VIDEO_ACCEL,0xb8,(regs.u_base >> 8) & 0xff);
+
+	WRITE_REG(VIDEO_ACCEL,0xba,regs.v_base & 0xff);
+	WRITE_REG(VIDEO_ACCEL,0xbb,(regs.v_base >> 8) & 0xff);
+	WRITE_REG(VIDEO_ACCEL,0xb9,((regs.v_base >> 12) & 0xf0) + ((regs.u_base >> 16) & 0xf));
+
+	WRITE_REG(VIDEO_ACCEL,0x8d,regs.fb_end);
+
+	//setup framebuffer pitch
+	WRITE_REG(VIDEO_ACCEL,0x8c,regs.pitch & 0xff);
+	WRITE_REG(VIDEO_ACCEL,0x8e,(regs.pitch >> 8) & 0x0f);
+	WRITE_REG(VIDEO_ACCEL,0xbc,(regs.pitch) & 0xff);
+	WRITE_REG(VIDEO_ACCEL,0xbd,((regs.pitch) >> 8) & 0x0f);
+
+
+	//write key overlay register
+	WRITE_REG(VIDEO_ACCEL,0xa9,regs.key_mode);
+
+	WRITE_REG(VIDEO_ACCEL,0x93,0x40);
+	WRITE_REG(VIDEO_ACCEL,0x94,1);
+	WRITE_REG(VIDEO_ACCEL,0x9e,0);
+	WRITE_REG(VIDEO_ACCEL,0x9f,0);
+
+	//write config registers
+	WRITE_REG(VIDEO_ACCEL,MISC_0,regs.misc_0);
+	WRITE_REG(VIDEO_ACCEL,MISC_1,regs.misc_1);
+	WRITE_REG(VIDEO_ACCEL,MISC_3,regs.misc_3);
+	WRITE_REG(VIDEO_ACCEL,MISC_4,regs.misc_4);
+
+	//setup the video line buffer
+	WRITE_REG(VIDEO_ACCEL,0xa0,(regs.right - regs.left)/ 8);
+
+}
+
+static int mga_vid_set_config(mga_vid_config_t *config)
+{
+	uint32_t x, y, frame_size;
+
+	x = config->x_org;
+	y = config->y_org;
+
+	regs.left =  x;
+	regs.right= config->src_width + x;
+	regs.top =  y;
+	regs.bottom = config->src_height + y;
+
+	printk("mga_vid: Setting up a %dx%d+%d+%d video window (src %dx%d)\n",
+	       config->dest_width, config->dest_height, config->x_org, config->y_org, 
+				 config->src_width, config->src_height);
+
+	
+	regs.pitch = ((config->src_width + 31) & ~31) / 4 ; 
+
+	//frame size in pixels
+	frame_size =  regs.pitch * config->src_height * 4;
+
+	regs.yuv_base = (mga_src_base) >> 2;
+	regs.u_base = (mga_src_base + frame_size) >> 2;
+	regs.v_base = (mga_src_base + frame_size/4) >> 2;
+	regs.fb_end = (mga_src_base + (3*frame_size)/2) >> 14;
+
+	//disable video capture, enable video display, enable graphics display,
+	//select yuv format, odd parity
+	regs.misc_0 = (1 << 1) + (1<<6) + (1<<4);
+
+	//disable dithering, no filtering, no interrupts
+	regs.misc_1 = 0;
+
+	//select 2's complement format YUV for playback
+	regs.misc_3 = (1<<1);
+
+	//select 4:2:0 video format, + yuv4:2:2 cpu writes
+	regs.misc_4 = (1<<2);
+
+	//disable keying
+	regs.key_mode = 0xf;
+
+	mga_vid_write_regs();
+	return 0;
+}
+
+
+static int mga_vid_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+{
+	int frame;
+
+	switch(cmd) 
+	{
+		case MGA_VID_CONFIG:
+			//FIXME remove
+			printk("mga_mmio_base = %p\n",mga_mmio_base);
+			printk("mga_mem_base = %08x\n",mga_mem_base);
+			//FIXME remove
+
+			printk("mga_vid: Received configuration\n");
+
+ 			if(copy_from_user(&mga_config,(mga_vid_config_t*) arg,sizeof(mga_vid_config_t)))
+			{
+				printk("mga_vid: failed copy from userspace\n");
+				return(-EFAULT);
+			}
+
+			mga_config.ram_size = mga_ram_size;
+			//XXX make it look like a g400
+			mga_config.card_type = MGA_G400;;
+
+			if (copy_to_user((mga_vid_config_t *) arg, &mga_config, sizeof(mga_vid_config_t)))
+			{
+				printk("mga_vid: failed copy to userspace\n");
+				return(-EFAULT);
+			}
+			return mga_vid_set_config(&mga_config);	
+		break;
+
+		case MGA_VID_ON:
+			printk("mga_vid: Video ON\n");
+			vid_src_ready = 1;
+			if(vid_overlay_on)
+			{
+				//regs.besctl |= 1;
+				mga_vid_write_regs();
+			}
+		break;
+
+		case MGA_VID_OFF:
+			printk("mga_vid: Video OFF\n");
+			vid_src_ready = 0;   
+			//regs.besctl &= ~1;
+			mga_vid_write_regs();
+		break;
+			
+		case MGA_VID_FSEL:
+			if(copy_from_user(&frame,(int *) arg,sizeof(int)))
+			{
+				printk("mga_vid: FSEL failed copy from userspace\n");
+				return(-EFAULT);
+			}
+
+			mga_vid_frame_sel(frame);
+		break;
+
+	        default:
+			printk("mga_vid: Invalid ioctl\n");
+			return (-EINVAL);
+	}
+       
+	return 0;
+}
+
+
+static int mga_vid_find_card(void)
+{
+	struct pci_dev *dev = NULL;
+
+	if((dev = pci_find_device(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_6323, NULL)))
+	{
+		printk("sis_vid: Found SiS 6326\n");
+	}
+	else
+	{
+		printk("sis_vid: No supported cards found\n");
+		return FALSE;   
+	}
+
+	pci_dev = dev;
+	
+#if LINUX_VERSION_CODE >= 0x020300
+	mga_mmio_base = ioremap_nocache(dev->resource[1].start,0x10000);
+	mga_mem_base =  dev->resource[0].start;
+#else
+	mga_mmio_base = ioremap_nocache(dev->base_address[1] & PCI_BASE_ADDRESS_MEM_MASK,0x10000);
+	mga_mem_base =  dev->base_address[0] & PCI_BASE_ADDRESS_MEM_MASK;
+#endif
+	printk("mga_vid: MMIO at 0x%p\n", mga_mmio_base);
+	printk("mga_vid: Frame Buffer at 0x%08x\n", mga_mem_base);
+
+	//FIXME set ram size properly
+	mga_ram_size = 4;
+	mga_src_base = (mga_ram_size - 1) * 0x100000;
+	
+	//FIXME remove
+	if(1)
+	{
+		mga_vid_config_t config ={0,0,256,256,256,256,10,10,0,0,0,0};
+
+		mga_vid_set_config(&config);
+		mga_vid_write_regs();
+		//regs.misc_0 ^= 2;
+		//mga_vid_write_regs();
+	}
+	//FIXME remove
+
+	return TRUE;
+}
+
+
+static ssize_t mga_vid_read(struct file *file, char *buf, size_t count, loff_t *ppos)
+{
+	return -EINVAL;
+}
+
+static ssize_t mga_vid_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
+{
+	return -EINVAL;
+}
+
+static int mga_vid_mmap(struct file *file, struct vm_area_struct *vma)
+{
+
+	printk("mga_vid: mapping video memory into userspace\n");
+	if(remap_page_range(vma->vm_start, mga_mem_base + mga_src_base,
+		 vma->vm_end - vma->vm_start, vma->vm_page_prot)) 
+	{
+		printk("mga_vid: error mapping video memory\n");
+		return(-EAGAIN);
+	}
+
+	return(0);
+}
+
+static int mga_vid_release(struct inode *inode, struct file *file)
+{
+	//Close the window just in case
+	vid_src_ready = 0;   
+	regs.misc_0 &= 0xed;
+	mga_vid_write_regs();
+	mga_vid_in_use = 0;
+
+	//FIXME put back in!
+	//MOD_DEC_USE_COUNT;
+	return 0;
+}
+
+static long long mga_vid_lseek(struct file *file, long long offset, int origin)
+{
+	return -ESPIPE;
+}					 
+
+static int mga_vid_open(struct inode *inode, struct file *file)
+{
+	int minor = MINOR(inode->i_rdev);
+
+	if(minor != 0)
+	 return(-ENXIO);
+
+	if(mga_vid_in_use == 1) 
+		return(-EBUSY);
+
+	mga_vid_in_use = 1;
+	//FIXME turn me back on!
+	//MOD_INC_USE_COUNT;
+	return(0);
+}
+
+#if LINUX_VERSION_CODE >= 0x020400
+static struct file_operations mga_vid_fops =
+{
+	llseek:		mga_vid_lseek,
+	read:			mga_vid_read,
+	write:		mga_vid_write,
+	ioctl:		mga_vid_ioctl,
+	mmap:			mga_vid_mmap,
+	open:			mga_vid_open,
+	release: 	mga_vid_release
+};
+#else
+static struct file_operations mga_vid_fops =
+{
+	mga_vid_lseek,
+	mga_vid_read,
+	mga_vid_write,
+	NULL,
+	NULL,
+	mga_vid_ioctl,
+	mga_vid_mmap,
+	mga_vid_open,
+	NULL,
+	mga_vid_release
+};
+#endif
+
+#if 0
+static long mga_v4l_read(struct video_device *v, char *buf, unsigned long count, 
+	int noblock)
+{
+	return -EINVAL;
+}
+
+static long mga_v4l_write(struct video_device *v, const char *buf, unsigned long count, int noblock)
+{
+	return -EINVAL;
+}
+
+static int mga_v4l_open(struct video_device *dev, int mode)
+{
+	MOD_INC_USE_COUNT;
+	return 0;
+}
+
+static void mga_v4l_close(struct video_device *dev)
+{
+	//regs.besctl &= ~1;
+	mga_vid_write_regs();
+	vid_overlay_on = 0;
+	MOD_DEC_USE_COUNT;
+	return;
+}
+
+static int mga_v4l_init_done(struct video_device *dev)
+{
+	return 0;
+}
+
+static int mga_v4l_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
+{
+	switch(cmd)
+	{
+		case VIDIOCGCAP:
+		{
+			struct video_capability b;
+			strcpy(b.name, "Matrox G200/400");
+			b.type = VID_TYPE_SCALES|VID_TYPE_OVERLAY|VID_TYPE_CHROMAKEY;
+			b.channels = 0;
+			b.audios = 0;
+			b.maxwidth = 1024;	/* GUESS ?? */
+			b.maxheight = 768;
+			b.minwidth = 32;
+			b.minheight = 16;	/* GUESS ?? */
+			if(copy_to_user(arg,&b,sizeof(b)))
+				return -EFAULT;
+			return 0;
+		}
+		case VIDIOCGPICT:
+		{
+			/*
+			 *	Default values.. if we can change this we
+			 *	can add the feature later
+			 */
+			struct video_picture vp;
+			vp.brightness = 0x8000;
+			vp.hue = 0x8000;
+			vp.colour = 0x8000;
+			vp.whiteness = 0x8000;
+			vp.depth = 8;
+			/* Format is a guess */
+			vp.palette = VIDEO_PALETTE_YUV420P;
+			if(copy_to_user(arg, &vp, sizeof(vp)))
+				return -EFAULT;
+			return 0;
+		}
+		case VIDIOCSPICT:
+		{
+			return -EINVAL;
+		}
+		case VIDIOCSWIN:
+		{
+			struct video_window vw;
+			if(copy_from_user(&vw, arg, sizeof(vw)))
+				return -EFAULT;
+			if(vw.x <0 || vw.y <0 || vw.width < 32 
+				|| vw.height < 16)
+				return -EINVAL;
+			memcpy(&mga_win, &vw, sizeof(mga_win));
+
+			mga_config.x_org = vw.x;
+			mga_config.y_org = vw.y;
+			mga_config.dest_width = vw.width;
+			mga_config.dest_height = vw.height;
+
+			/* 
+			 * May have to add 
+			 *
+			 * #define VIDEO_WINDOW_CHROMAKEY 16 
+			 *
+			 * to <linux/videodev.h> 
+			 */
+
+			//add it here for now
+			#define VIDEO_WINDOW_CHROMAKEY 16 
+
+			if (vw.flags & VIDEO_WINDOW_CHROMAKEY)
+				mga_config.colkey_on = 1;
+			else 
+				mga_config.colkey_on = 0;
+
+			mga_config.colkey_red   = (vw.chromakey >> 24) & 0xFF;
+			mga_config.colkey_green = (vw.chromakey >> 16) & 0xFF;
+			mga_config.colkey_blue  = (vw.chromakey >> 8)  & 0xFF;
+			mga_vid_set_config(&mga_config);
+			return 0;
+				
+		}
+		case VIDIOCGWIN:
+		{
+			if(copy_to_user(arg, &mga_win, sizeof(mga_win)))
+				return -EFAULT;
+			return 0;
+		}
+		case VIDIOCCAPTURE:
+		{
+			int v;
+			if(copy_from_user(&v, arg, sizeof(v)))
+				return -EFAULT;
+			vid_overlay_on = v;
+			if(vid_overlay_on && vid_src_ready)
+			{
+				//regs.besctl |= 1;
+				mga_vid_write_regs();
+			}
+			else
+			{
+				//regs.besctl &= ~1;
+				mga_vid_write_regs();
+			}
+			return 0;
+		}
+		default:
+			return -ENOIOCTLCMD;
+	}
+}
+
+static struct video_device mga_v4l_dev =
+{
+	"Matrox G200/G400",
+	VID_TYPE_CAPTURE,
+	VID_HARDWARE_BT848,		/* This is a lie for now */
+	mga_v4l_open,
+	mga_v4l_close,
+	mga_v4l_read,
+	mga_v4l_write,
+	NULL,
+	mga_v4l_ioctl,
+	NULL,
+	mga_v4l_init_done,
+	NULL,
+	0,
+	0
+};
+
+#endif
+
+/* 
+ * Main Initialization Function 
+ */
+
+
+static int mga_vid_initialize(void)
+{
+	mga_vid_in_use = 0;
+
+	printk( "SiS 6326 YUV Video interface v0.01 (c) Aaron Holtzman \n");
+	if(register_chrdev(MGA_VID_MAJOR, "mga_vid", &mga_vid_fops))
+	{
+		printk("sis_vid: unable to get major: %d\n", MGA_VID_MAJOR);
+		return -EIO;
+	}
+
+	if (!mga_vid_find_card())
+	{
+		printk("sis_vid: no supported devices found\n");
+		unregister_chrdev(MGA_VID_MAJOR, "mga_vid");
+		return -EINVAL;
+	}
+	
+#if 0
+	if (video_register_device(&mga_v4l_dev, VFL_TYPE_GRABBER)<0)
+	{
+		printk("sis_vid: unable to register.\n");
+		unregister_chrdev(MGA_VID_MAJOR, "mga_vid");
+		if(mga_mmio_base)
+			iounmap(mga_mmio_base);
+		mga_mmio_base = 0;
+		return -EINVAL;
+	}
+#endif
+
+	return(0);
+}
+
+int init_module(void)
+{
+	return mga_vid_initialize();
+}
+
+void cleanup_module(void)
+{
+//	video_unregister_device(&mga_v4l_dev);
+	if(mga_mmio_base)
+		iounmap(mga_mmio_base);
+
+	//FIXME turn off BES
+	printk("mga_vid: Cleaning up module\n");
+	unregister_chrdev(MGA_VID_MAJOR, "mga_vid");
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drivers/sis_vid.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,37 @@
+/*
+ *
+ * sis_vid.h
+ *
+ * Copyright (C) 2000 Aaron Holtzman
+ * 
+ * YUV Framebuffer driver for SiS 6326 cards
+ * 
+ * This software has been released under the terms of the GNU Public
+ * license. See http://www.gnu.org/copyleft/gpl.html for details.
+ */
+
+#include <inttypes.h>
+
+typedef struct mga_vid_config_s
+{
+uint32_t card_type;
+uint32_t ram_size;
+uint32_t src_width;
+uint32_t src_height;
+uint32_t dest_width;
+uint32_t dest_height;
+uint32_t x_org;
+uint32_t y_org;
+uint8_t  colkey_on;
+uint8_t  colkey_red;
+uint8_t  colkey_green;
+uint8_t  colkey_blue;
+} mga_vid_config_t;
+
+#define MGA_VID_CONFIG    _IOR('J', 1, mga_vid_config_t)
+#define MGA_VID_ON        _IO ('J', 2)
+#define MGA_VID_OFF       _IO ('J', 3)
+#define MGA_VID_FSEL _IOR('J', 4, int)
+
+#define MGA_G200 0x1234
+#define MGA_G400 0x5678
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/help_avp.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,32 @@
+static char* banner_text=
+"\n"
+"MPlayer v0.10 [AVI parser]  (C) 2000. Arpad Gereoffy <arpi@esp-team.scene.hu>\n"
+"\n";
+
+static char* help_text=
+"Usage:   aviparse [options] [path/]name\n"
+"\n"
+"  Options:\n"
+//"    -o <driver>     select output driver (see '-o help' for driver list)\n"
+//"    -vcd <track>    play video cd track from device instead of plain file\n"
+//"    -bg             play in background (X11 only!)\n"
+//"    -sb <bytepos>   seek to byte position\n"
+//"    -ss <timepos>   seek to second position (with timestamp)\n"
+//"    -nosound        don't play sound\n"
+//"    -abs <bytes>    audio buffer size (in bytes, default: measuring)\n"
+//"    -delay <secs>   audio delay in seconds (may be +/- float value)\n"
+//"    -alsa           enable timing code (works better with ALSA)\n"
+"    -aid <1-99>     select audio channel\n"
+"    -afile <name>   dump raw audio data to file\n"
+"    -vfile <name>   dump raw video data to file\n"
+//"    -vid <0-15>     select video channel\n"
+//"    -fps <value>    force frame rate (if value is wrong in mpeg header)\n"
+//"    -mc <s/5f>      maximum sync correction per 5 frames (in seconds)\n"
+//"    -afm <1-3>      force audio format  1:MPEG 2:PCM 3:AC3 4:Win32\n"
+//"\n"
+//"  Keys:\n"
+//"    <-  or  ->      seek backward/forward  10 seconds\n"
+//"    up or down      seek backward/forward   1 minute\n"
+//"    p or SPACE      pause movie (press any key to continue)\n"
+//"    q  or  ^C       stop playing and quit program\n"
+"\n";
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/help_mp.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,44 @@
+static char* banner_text=
+"\n"
+"MPlayer " VERSION "       (C) 2000-2001 Arpad Gereoffy <arpi@esp-team.scene.hu>\n"
+"\n";
+
+static char* help_text=
+"Usage:   mplayer [options] [path/]name\n"
+"\n"
+"  Options:\n"
+"    -vo <driver>    select output driver (see '-vo help' for driver list)\n"
+"    -vcd <track>    play video cd track from device instead of plain file\n"
+//"    -bg             play in background (X11 only!)\n"
+"    -sb <bytepos>   seek to byte position\n"
+//"    -ss <timepos>   seek to second position (with timestamp)\n"
+"    -nosound        don't play sound\n"
+"    -abs <bytes>    audio buffer size (in bytes, default: measuring)\n"
+"    -delay <secs>   audio delay in seconds (may be +/- float value)\n"
+#ifdef AVI_SYNC_BPS
+"    -nobps          do not use avg. byte/sec value for A-V sync (AVI)\n"
+#else
+"    -bps            use avg. byte/sec value for A-V sync (AVI)\n"
+#endif
+#ifdef ALSA_TIMER
+"    -noalsa         disable timing code\n"
+#else
+"    -alsa           enable timing code (works better with ALSA)\n"
+#endif
+"    -aid <id>       select audio channel [MPG: 0-31  AVI: 1-99]\n"
+"    -vid <id>       select video channel [MPG: 0-15  AVI:  -- ]\n"
+"    -fps <value>    force frame rate (if value is wrong in the header)\n"
+"    -mc <s/5f>      maximum sync correction per 5 frames (in seconds)\n"
+"    -afm <1-5>      force audio format  1:MPEG 2:PCM 3:AC3 4:Win32 5:aLaw\n"
+#ifdef X11_FULLSCREEN
+"    -fs             fullscreen playing (only gl, xmga and xv drivers)\n"
+#endif
+"    -x <x> -y <y>   scale image to <x> * <y> resolution [if scalable!]\n"
+"\n"
+"  Keys:\n"
+"    <-  or  ->      seek backward/forward  10 seconds\n"
+"    up or down      seek backward/forward   1 minute\n"
+"    p or SPACE      pause movie (press any key to continue)\n"
+"    q or ESC        stop playing and quit program\n"
+"    + or -          adjust audio delay by +/- 0.1 second\n"
+"\n";
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liba52/srfftp.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,303 @@
+
+/* 
+ *  srfftp.h
+ *
+ *  Copyright (C) Yuqing Deng <Yuqing_Deng@brown.edu> - April 2000
+ *
+ *  64 and 128 point split radix fft for ac3dec
+ *
+ *  The algorithm is desribed in the book:
+ *  "Computational Frameworks of the Fast Fourier Transform".
+ *
+ *  The ideas and the the organization of code borrowed from djbfft written by
+ *  D. J. Bernstein <djb@cr.py.to>.  djbff can be found at 
+ *  http://cr.yp.to/djbfft.html.
+ *
+ *  srfftp.h 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, or (at your option)
+ *  any later version.
+ *
+ *  srfftp.h 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 GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifndef SRFFTP_H__
+#define SRFFTP_H__
+
+static complex_t delta16[4] = 
+ { {1.00000000000000,  0.00000000000000},
+   {0.92387953251129, -0.38268343236509},
+   {0.70710678118655, -0.70710678118655},
+   {0.38268343236509, -0.92387953251129}};
+
+static complex_t delta16_3[4] = 
+ { {1.00000000000000,  0.00000000000000},
+   {0.38268343236509, -0.92387953251129},
+   {-0.70710678118655, -0.70710678118655},
+   {-0.92387953251129, 0.38268343236509}};
+
+static complex_t delta32[8] = 
+ { {1.00000000000000,  0.00000000000000},
+   {0.98078528040323, -0.19509032201613},
+   {0.92387953251129, -0.38268343236509},
+   {0.83146961230255, -0.55557023301960},
+   {0.70710678118655, -0.70710678118655},
+   {0.55557023301960, -0.83146961230255},
+   {0.38268343236509, -0.92387953251129},
+   {0.19509032201613, -0.98078528040323}};
+
+static complex_t delta32_3[8] = 
+ { {1.00000000000000,  0.00000000000000},
+   {0.83146961230255, -0.55557023301960},
+   {0.38268343236509, -0.92387953251129},
+   {-0.19509032201613, -0.98078528040323},
+   {-0.70710678118655, -0.70710678118655},
+   {-0.98078528040323, -0.19509032201613},
+   {-0.92387953251129, 0.38268343236509},
+   {-0.55557023301960, 0.83146961230255}};
+
+static complex_t delta64[16] = 
+ { {1.00000000000000,  0.00000000000000},
+   {0.99518472667220, -0.09801714032956},
+   {0.98078528040323, -0.19509032201613},
+   {0.95694033573221, -0.29028467725446},
+   {0.92387953251129, -0.38268343236509},
+   {0.88192126434836, -0.47139673682600},
+   {0.83146961230255, -0.55557023301960},
+   {0.77301045336274, -0.63439328416365},
+   {0.70710678118655, -0.70710678118655},
+   {0.63439328416365, -0.77301045336274},
+   {0.55557023301960, -0.83146961230255},
+   {0.47139673682600, -0.88192126434835},
+   {0.38268343236509, -0.92387953251129},
+   {0.29028467725446, -0.95694033573221},
+   {0.19509032201613, -0.98078528040323},
+   {0.09801714032956, -0.99518472667220}};
+
+static complex_t delta64_3[16] = 
+ { {1.00000000000000,  0.00000000000000},
+   {0.95694033573221, -0.29028467725446},
+   {0.83146961230255, -0.55557023301960},
+   {0.63439328416365, -0.77301045336274},
+   {0.38268343236509, -0.92387953251129},
+   {0.09801714032956, -0.99518472667220},
+   {-0.19509032201613, -0.98078528040323},
+   {-0.47139673682600, -0.88192126434836},
+   {-0.70710678118655, -0.70710678118655},
+   {-0.88192126434835, -0.47139673682600},
+   {-0.98078528040323, -0.19509032201613},
+   {-0.99518472667220, 0.09801714032956},
+   {-0.92387953251129, 0.38268343236509},
+   {-0.77301045336274, 0.63439328416365},
+   {-0.55557023301960, 0.83146961230255},
+   {-0.29028467725446, 0.95694033573221}};
+
+static complex_t delta128[32] = 
+ { {1.00000000000000,  0.00000000000000},
+   {0.99879545620517, -0.04906767432742},
+   {0.99518472667220, -0.09801714032956},
+   {0.98917650996478, -0.14673047445536},
+   {0.98078528040323, -0.19509032201613},
+   {0.97003125319454, -0.24298017990326},
+   {0.95694033573221, -0.29028467725446},
+   {0.94154406518302, -0.33688985339222},
+   {0.92387953251129, -0.38268343236509},
+   {0.90398929312344, -0.42755509343028},
+   {0.88192126434836, -0.47139673682600},
+   {0.85772861000027, -0.51410274419322},
+   {0.83146961230255, -0.55557023301960},
+   {0.80320753148064, -0.59569930449243},
+   {0.77301045336274, -0.63439328416365},
+   {0.74095112535496, -0.67155895484702},
+   {0.70710678118655, -0.70710678118655},
+   {0.67155895484702, -0.74095112535496},
+   {0.63439328416365, -0.77301045336274},
+   {0.59569930449243, -0.80320753148064},
+   {0.55557023301960, -0.83146961230255},
+   {0.51410274419322, -0.85772861000027},
+   {0.47139673682600, -0.88192126434835},
+   {0.42755509343028, -0.90398929312344},
+   {0.38268343236509, -0.92387953251129},
+   {0.33688985339222, -0.94154406518302},
+   {0.29028467725446, -0.95694033573221},
+   {0.24298017990326, -0.97003125319454},
+   {0.19509032201613, -0.98078528040323},
+   {0.14673047445536, -0.98917650996478},
+   {0.09801714032956, -0.99518472667220},
+   {0.04906767432742, -0.99879545620517}};
+
+static complex_t delta128_3[32] = 
+ { {1.00000000000000,  0.00000000000000},
+   {0.98917650996478, -0.14673047445536},
+   {0.95694033573221, -0.29028467725446},
+   {0.90398929312344, -0.42755509343028},
+   {0.83146961230255, -0.55557023301960},
+   {0.74095112535496, -0.67155895484702},
+   {0.63439328416365, -0.77301045336274},
+   {0.51410274419322, -0.85772861000027},
+   {0.38268343236509, -0.92387953251129},
+   {0.24298017990326, -0.97003125319454},
+   {0.09801714032956, -0.99518472667220},
+   {-0.04906767432742, -0.99879545620517},
+   {-0.19509032201613, -0.98078528040323},
+   {-0.33688985339222, -0.94154406518302},
+   {-0.47139673682600, -0.88192126434836},
+   {-0.59569930449243, -0.80320753148065},
+   {-0.70710678118655, -0.70710678118655},
+   {-0.80320753148065, -0.59569930449243},
+   {-0.88192126434835, -0.47139673682600},
+   {-0.94154406518302, -0.33688985339222},
+   {-0.98078528040323, -0.19509032201613},
+   {-0.99879545620517, -0.04906767432742},
+   {-0.99518472667220, 0.09801714032956},
+   {-0.97003125319454, 0.24298017990326},
+   {-0.92387953251129, 0.38268343236509},
+   {-0.85772861000027, 0.51410274419322},
+   {-0.77301045336274, 0.63439328416365},
+   {-0.67155895484702, 0.74095112535496},
+   {-0.55557023301960, 0.83146961230255},
+   {-0.42755509343028, 0.90398929312344},
+   {-0.29028467725446, 0.95694033573221},
+   {-0.14673047445536, 0.98917650996478}};
+
+#define HSQRT2 0.707106781188;
+
+#define TRANSZERO(A0,A4,A8,A12) { \
+  u_r = wTB[0].re; \
+  v_i = u_r - wTB[k*2].re; \
+  u_r += wTB[k*2].re; \
+  u_i = wTB[0].im; \
+  v_r = wTB[k*2].im - u_i; \
+  u_i += wTB[k*2].im; \
+  a_r = A0.re; \
+  a_i = A0.im; \
+  a1_r = a_r; \
+  a1_r += u_r; \
+  A0.re = a1_r; \
+  a_r -= u_r; \
+  A8.re = a_r; \
+  a1_i = a_i; \
+  a1_i += u_i; \
+  A0.im = a1_i; \
+  a_i -= u_i; \
+  A8.im = a_i; \
+  a1_r = A4.re; \
+  a1_i = A4.im; \
+  a_r = a1_r; \
+  a_r -= v_r; \
+  A4.re = a_r; \
+  a1_r += v_r; \
+  A12.re = a1_r; \
+  a_i = a1_i; \
+  a_i -= v_i; \
+  A4.im = a_i; \
+  a1_i += v_i; \
+  A12.im = a1_i; \
+  }
+
+#define TRANSHALF_16(A2,A6,A10,A14) {\
+  u_r = wTB[2].re; \
+  a_r = u_r; \
+  u_i = wTB[2].im; \
+  u_r += u_i; \
+  u_i -= a_r; \
+  a_r = wTB[6].re; \
+  a1_r = a_r; \
+  a_i = wTB[6].im; \
+  a_r = a_i - a_r; \
+  a_i += a1_r; \
+  v_i = u_r - a_r; \
+  u_r += a_r; \
+  v_r = u_i + a_i; \
+  u_i -= a_i; \
+  v_i *= HSQRT2; \
+  v_r *= HSQRT2; \
+  u_r *= HSQRT2; \
+  u_i *= HSQRT2; \
+  a_r = A2.re; \
+  a_i = A2.im; \
+  a1_r = a_r; \
+  a1_r += u_r; \
+  A2.re = a1_r; \
+  a_r -= u_r; \
+  A10.re = a_r; \
+  a1_i = a_i; \
+  a1_i += u_i; \
+  A2.im = a1_i; \
+  a_i -= u_i; \
+  A10.im = a_i; \
+  a1_r = A6.re; \
+  a1_i = A6.im;  \
+  a_r = a1_r; \
+  a1_r += v_r; \
+  A6.re = a1_r; \
+  a_r -= v_r; \
+  A14.re = a_r; \
+  a_i = a1_i; \
+  a1_i -= v_i; \
+  A6.im = a1_i; \
+  a_i += v_i; \
+  A14.im = a_i; \
+  }
+
+#define TRANS(A1,A5,A9,A13,WT,WB,D,D3) { \
+  u_r = WT.re; \
+  a_r = u_r; \
+  a_r *= D.im; \
+  u_r *= D.re; \
+  a_i = WT.im; \
+  a1_i = a_i; \
+  a1_i *= D.re; \
+  a_i *= D.im; \
+  u_r -= a_i; \
+  u_i = a_r; \
+  u_i += a1_i; \
+  a_r = WB.re; \
+  a1_r = a_r; \
+  a1_r *= D3.re; \
+  a_r *= D3.im; \
+  a_i = WB.im; \
+  a1_i = a_i; \
+  a_i *= D3.re; \
+  a1_i *= D3.im; \
+  a1_r -= a1_i; \
+  a_r += a_i; \
+  v_i = u_r - a1_r; \
+  u_r += a1_r; \
+  v_r = a_r - u_i; \
+  u_i += a_r; \
+  a_r = A1.re; \
+  a_i = A1.im; \
+  a1_r = a_r; \
+  a1_r += u_r; \
+  A1.re = a1_r; \
+  a_r -= u_r; \
+  A9.re = a_r; \
+  a1_i = a_i; \
+  a1_i += u_i; \
+  A1.im = a1_i; \
+  a_i -= u_i; \
+  A9.im = a_i; \
+  a1_r = A5.re; \
+  a1_i = A5.im;  \
+  a_r = a1_r; \
+  a1_r -= v_r; \
+  A5.re = a1_r; \
+  a_r += v_r; \
+  A13.re = a_r; \
+  a_i = a1_i; \
+  a1_i -= v_i; \
+  A5.im = a1_i; \
+  a_i += v_i; \
+  A13.im = a_i; \
+  }
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/Makefile	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,35 @@
+
+LIBNAME = libmpeg2.a
+
+include ../config.mak
+
+SRCS	= decode.c header.c idct.c idct_mmx.c motion_comp.c motion_comp_mmx.c slice.c stats.c
+OBJS	= decode.o header.o idct.o idct_mmx.o motion_comp.o motion_comp_mmx.o slice.o stats.o
+CFLAGS  = $(OPTFLAGS) -DMPG12PLAY
+INCLUDE = -I. -I../libvo -I..
+
+.SUFFIXES: .c .o
+
+# .PHONY: all clean
+
+.c.o:
+	$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $<
+
+$(LIBNAME):	$(OBJS)
+	$(AR) r $(LIBNAME) $(OBJS)
+
+all:	$(LIBNAME)
+
+clean:
+	rm -f *.o *.a *~
+
+distclean:
+	makedepend
+	rm -f Makefile.bak *.o *.a *~
+
+dep:	depend
+
+depend:
+	makedepend -- $(CFLAGS) -- $(SRCS) &> /dev/null
+
+# DO NOT DELETE
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/attributes.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,31 @@
+/*
+ * attributes.h
+ * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *
+ * mpeg2dec 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.
+ *
+ * mpeg2dec 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+//use gcc attribs to align critical data structures
+
+/* maximum supported data alignment */
+#define ATTRIBUTE_ALIGNED_MAX 64
+
+#ifdef ATTRIBUTE_ALIGNED_MAX
+#define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
+#else
+#define ATTR_ALIGN(align)
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/decode.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,319 @@
+/* Copyright (C) Aaron Holtzman <aholtzma@ess.engr.uvic.ca> - Nov 1999 */
+/* Some cleanup & hacking by A'rpi/ESP-team - Oct 2000 */
+
+/* mpeg2dec version: */
+#define PACKAGE "mpeg2dec"
+//#define VERSION "0.1.7-cvs"
+#define VERSION "0.1.8-cvs"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "config.h"
+
+//#include "video_out.h"
+
+#include "mpeg2.h"
+#include "mpeg2_internal.h"
+
+#include "../linux/shmem.h"
+
+//#include "motion_comp.h"
+//#include "idct.h"
+//#include "header.h"
+//#include "slice.h"
+//#include "stats.h"
+
+#include "attributes.h"
+#ifdef __i386__
+#include "mmx.h"
+#endif
+
+//this is where we keep the state of the decoder
+//picture_t picture_data;
+//picture_t *picture=&picture_data;
+picture_t *picture=NULL;
+
+//global config struct
+mpeg2_config_t config;
+
+// the maximum chunk size is determined by vbv_buffer_size which is 224K for
+// MP@ML streams. (we make no pretenses ofdecoding anything more than that)
+//static uint8_t chunk_buffer[224 * 1024 + 4];
+//static uint32_t shift = 0;
+
+static int drop_flag = 0;
+static int drop_frame = 0;
+
+int quant_store[MBR+1][MBC+1]; // [Review]
+
+void mpeg2_init (void)
+{
+
+    printf (PACKAGE"-"VERSION" (C) 2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>\n");
+    config.flags = 0;
+#ifdef HAVE_MMX
+    config.flags |= MM_ACCEL_X86_MMX;
+#endif
+#ifdef HAVE_SSE
+    config.flags |= MM_ACCEL_X86_MMXEXT;
+#endif
+#ifdef HAVE_3DNOW
+    config.flags |= MM_ACCEL_X86_3DNOW;
+#endif
+#ifdef HAVE_MLIB
+    config.flags |= MM_ACCEL_MLIB;
+#endif
+
+    printf("libmpeg2 config flags = 0x%X\n",config.flags);
+
+    picture=shmem_alloc(sizeof(picture_t)); // !!! NEW HACK :) !!!
+
+    header_state_init (picture);
+    picture->repeat_count=0;
+    
+    picture->pp_options=0;
+
+    idct_init ();
+    motion_comp_init ();
+}
+
+void mpeg2_allocate_image_buffers (picture_t * picture)
+{
+	int frame_size,buff_size;
+        unsigned char *base=NULL;
+
+        // height+1 requires for yuv2rgb_mmx code (it reads next line after last)
+	frame_size = picture->coded_picture_width * (1+picture->coded_picture_height);
+        frame_size = (frame_size+31)&(~31); // align to 32 byte boundary
+        buff_size = frame_size + (frame_size/4)*2; // 4Y + 1U + 1V
+
+	// allocate images in YV12 format
+        base = shmem_alloc(buff_size);
+	picture->throwaway_frame[0] = base;
+	picture->throwaway_frame[1] = base + frame_size * 5 / 4;
+	picture->throwaway_frame[2] = base + frame_size;
+
+        base = shmem_alloc(buff_size);
+	picture->backward_reference_frame[0] = base;
+	picture->backward_reference_frame[1] = base + frame_size * 5 / 4;
+	picture->backward_reference_frame[2] = base + frame_size;
+
+        base = shmem_alloc(buff_size);
+	picture->forward_reference_frame[0] = base;
+	picture->forward_reference_frame[1] = base + frame_size * 5 / 4;
+	picture->forward_reference_frame[2] = base + frame_size;
+
+        base = shmem_alloc(buff_size);
+	picture->pp_frame[0] = base;
+	picture->pp_frame[1] = base + frame_size * 5 / 4;
+	picture->pp_frame[2] = base + frame_size;
+
+}
+
+static void decode_reorder_frames (void)
+{
+    if (picture->picture_coding_type != B_TYPE) {
+
+	//reuse the soon to be outdated forward reference frame
+	picture->current_frame[0] = picture->forward_reference_frame[0];
+	picture->current_frame[1] = picture->forward_reference_frame[1];
+	picture->current_frame[2] = picture->forward_reference_frame[2];
+
+	//make the backward reference frame the new forward reference frame
+	picture->forward_reference_frame[0] =
+	    picture->backward_reference_frame[0];
+	picture->forward_reference_frame[1] =
+	    picture->backward_reference_frame[1];
+	picture->forward_reference_frame[2] =
+	    picture->backward_reference_frame[2];
+
+	picture->backward_reference_frame[0] = picture->current_frame[0];
+	picture->backward_reference_frame[1] = picture->current_frame[1];
+	picture->backward_reference_frame[2] = picture->current_frame[2];
+
+    } else {
+
+	picture->current_frame[0] = picture->throwaway_frame[0];
+	picture->current_frame[1] = picture->throwaway_frame[1];
+	picture->current_frame[2] = picture->throwaway_frame[2];
+
+    }
+}
+
+static int in_slice_flag=0;
+
+static int parse_chunk (vo_functions_t * output, int code, uint8_t * buffer)
+{
+    int is_frame_done = 0;
+
+    stats_header (code, buffer);
+
+    is_frame_done = in_slice_flag && ((!code) || (code >= 0xb0));
+    if (is_frame_done) {
+	in_slice_flag = 0;
+        
+        if(picture->picture_structure != FRAME_PICTURE) printf("Field! %d  \n",picture->second_field);
+        
+	    if ( ((HACK_MODE == 2) || (picture->mpeg1))
+                && ((picture->picture_structure == FRAME_PICTURE) ||
+		 (picture->second_field))
+            ) {
+	        uint8_t ** bar;
+                int stride[3];
+
+		if (picture->picture_coding_type == B_TYPE)
+		    bar = picture->throwaway_frame;
+		else
+		    bar = picture->forward_reference_frame;
+                
+                stride[0]=picture->coded_picture_width;
+                stride[1]=stride[2]=stride[0]/2;
+
+                if(picture->pp_options){
+                    // apply OpenDivX postprocess filter
+                    postprocess(bar, stride[0],
+                        picture->pp_frame, stride[0],
+                        picture->coded_picture_width, picture->coded_picture_height, 
+                        &quant_store[1][1], (MBC+1), picture->pp_options);
+		    output->draw_slice (picture->pp_frame, stride, 
+                        picture->display_picture_width,
+                        picture->display_picture_height, 0, 0);
+                } else {
+		    output->draw_slice (bar, stride, 
+                        picture->display_picture_width,
+                        picture->display_picture_height, 0, 0);
+                }
+                
+	    }
+#ifdef ARCH_X86
+	    if (config.flags & MM_ACCEL_X86_MMX) emms ();
+#endif
+	    output->flip_page ();
+    }
+
+    switch (code) {
+    case 0x00:	/* picture_start_code */
+	if (header_process_picture_header (picture, buffer)) {
+	    printf ("bad picture header\n");
+	    exit (1);
+	}
+
+	drop_frame = drop_flag && (picture->picture_coding_type == B_TYPE);
+	//decode_reorder_frames ();
+	break;
+
+    case 0xb3:	/* sequence_header_code */
+	if (header_process_sequence_header (picture, buffer)) {
+	    printf ("bad sequence header\n");
+	    exit (1);
+	}
+	break;
+
+    case 0xb5:	/* extension_start_code */
+	if (header_process_extension (picture, buffer)) {
+	    printf ("bad extension\n");
+	    exit (1);
+	}
+	break;
+
+    default:
+//	if (code >= 0xb9)  printf ("stream not demultiplexed ?\n");
+	if (code >= 0xb0)  break;
+
+	if (!(in_slice_flag)) {
+	    in_slice_flag = 1;
+
+	    if(!(picture->second_field)) decode_reorder_frames ();
+	}
+
+	if (!drop_frame) {
+	    uint8_t ** bar;
+
+	    slice_process (picture, code, buffer);
+
+	    if ((HACK_MODE < 2) && (!(picture->mpeg1))) {
+		uint8_t * foo[3];
+	        uint8_t ** bar;
+		//frame_t * bar;
+                int stride[3];
+		int offset;
+
+		if (picture->picture_coding_type == B_TYPE)
+		    bar = picture->throwaway_frame;
+		else
+		    bar = picture->forward_reference_frame;
+
+		offset = (code-1) * 4 * picture->coded_picture_width;
+		if ((! HACK_MODE) && (picture->picture_coding_type == B_TYPE))
+		    offset = 0;
+
+		foo[0] = bar[0] + 4 * offset;
+		foo[1] = bar[1] + offset;
+		foo[2] = bar[2] + offset;
+                
+                stride[0]=picture->coded_picture_width;
+                stride[1]=stride[2]=stride[0]/2;
+
+		output->draw_slice (foo, stride, 
+                    picture->display_picture_width, 16, 0, (code-1)*16);
+	    }
+#ifdef ARCH_X86
+	    if (config.flags & MM_ACCEL_X86_MMX) emms ();
+#endif
+
+	}
+    }
+
+    return is_frame_done;
+}
+
+
+int mpeg2_decode_data (vo_functions_t *output, uint8_t *current, uint8_t *end)
+{
+    //static uint8_t code = 0xff;
+    //static uint8_t chunk_buffer[65536];
+    //static uint8_t *chunk_ptr = chunk_buffer;
+    //static uint32_t shift = 0;
+  uint8_t code;
+  uint8_t *pos=NULL;
+  uint8_t *start=current;
+  int ret = 0;
+
+//  printf("RCVD %d bytes\n",end-current);
+
+while(current<end){
+  // FIND NEXT HEAD:
+  unsigned int head=-1;
+  uint8_t c;
+  //--------------------
+  while(current<end){
+      c=current[0];
+      ++current;
+      head<<=8;
+      if(head==0x100) break; // synced
+      head|=c;
+  }
+  //--------------------
+  if(pos){
+    //if((code&0x100)!=0x100) printf("libmpeg2: FATAL! code=%X\n",code);
+    //printf("pos=%d  chunk %3X  size=%d  next-code=%X\n",pos-start,code,current-pos,head|c);
+    ret+=parse_chunk(output, code&0xFF, pos);
+  }
+  //--------------------
+  pos=current;code=head|c;
+}
+
+  if(code==0x1FF) ret+=parse_chunk(output, 0xFF, NULL); // send 'end of frame'
+
+    return ret;
+}
+
+void mpeg2_drop (int flag)
+{
+    drop_flag = flag;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/header.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,273 @@
+/*
+ * slice.c
+ * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *
+ * mpeg2dec 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.
+ *
+ * mpeg2dec 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "config.h"
+
+#include <inttypes.h>
+
+#include "mpeg2_internal.h"
+#include "attributes.h"
+
+// default intra quant matrix, in zig-zag order
+static uint8_t default_intra_quantizer_matrix[64] ATTR_ALIGN(16) = {
+    8,
+    16, 16,
+    19, 16, 19,
+    22, 22, 22, 22,
+    22, 22, 26, 24, 26,
+    27, 27, 27, 26, 26, 26,
+    26, 27, 27, 27, 29, 29, 29,
+    34, 34, 34, 29, 29, 29, 27, 27,
+    29, 29, 32, 32, 34, 34, 37,
+    38, 37, 35, 35, 34, 35,
+    38, 38, 40, 40, 40,
+    48, 48, 46, 46,
+    56, 56, 58,
+    69, 69,
+    83
+};
+
+uint8_t scan_norm[64] ATTR_ALIGN(16) =
+{
+    // Zig-Zag scan pattern
+     0, 1, 8,16, 9, 2, 3,10,
+    17,24,32,25,18,11, 4, 5,
+    12,19,26,33,40,48,41,34,
+    27,20,13, 6, 7,14,21,28,
+    35,42,49,56,57,50,43,36,
+    29,22,15,23,30,37,44,51,
+    58,59,52,45,38,31,39,46,
+    53,60,61,54,47,55,62,63
+};
+
+uint8_t scan_alt[64] ATTR_ALIGN(16) =
+{
+    // Alternate scan pattern
+    0,8,16,24,1,9,2,10,17,25,32,40,48,56,57,49,
+    41,33,26,18,3,11,4,12,19,27,34,42,50,58,35,43,
+    51,59,20,28,5,13,6,14,21,29,36,44,52,60,37,45,
+    53,61,22,30,7,15,23,31,38,46,54,62,39,47,55,63
+};
+
+void header_state_init (picture_t * picture)
+{
+    //FIXME we should set pointers to the real scan matrices here (mmx vs
+    //normal) instead of the ifdefs in header_process_picture_coding_extension
+
+    picture->scan = scan_norm;
+}
+
+static const int frameratecode2framerate[16] = {
+   0, 24000*10000/1001, 24*10000,25*10000, 30000*10000/1001, 30*10000,50*10000,60000*10000/1001,
+  60*10000, 0,0,0,0,0,0,0
+};
+
+int header_process_sequence_header (picture_t * picture, uint8_t * buffer)
+{
+    unsigned int h_size;
+    unsigned int v_size;
+    int i;
+
+    if ((buffer[6] & 0x20) != 0x20)
+	return 1;	// missing marker_bit
+
+    v_size = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
+
+    picture->display_picture_width = (v_size >> 12);
+    picture->display_picture_height = (v_size & 0xfff);
+
+    h_size = ((v_size >> 12) + 15) & ~15;
+    v_size = ((v_size & 0xfff) + 15) & ~15;
+
+    if ((h_size > 768) || (v_size > 576))
+	return 1;	// size restrictions for MP@ML or MPEG1
+
+    //XXX this needs field fixups
+    picture->coded_picture_width = h_size;
+    picture->coded_picture_height = v_size;
+    picture->last_mba = ((h_size * v_size) >> 8) - 1;
+
+    // this is not used by the decoder
+    picture->aspect_ratio_information = buffer[3] >> 4;
+    picture->frame_rate_code = buffer[3] & 15;
+    picture->frame_rate = frameratecode2framerate[picture->frame_rate_code];
+
+    picture->bitrate = (buffer[4]<<10)|(buffer[5]<<2)|(buffer[6]>>6);
+
+    if (buffer[7] & 2) {
+	for (i = 0; i < 64; i++)
+	    picture->intra_quantizer_matrix[scan_norm[i]] =
+		(buffer[i+7] << 7) | (buffer[i+8] >> 1);
+	buffer += 64;
+    } else {
+	for (i = 0; i < 64; i++)
+	    picture->intra_quantizer_matrix[scan_norm[i]] =
+		default_intra_quantizer_matrix [i];
+    }
+
+    if (buffer[7] & 1) {
+	for (i = 0; i < 64; i++)
+	    picture->non_intra_quantizer_matrix[scan_norm[i]] =
+		buffer[i+8];
+    } else {
+	for (i = 0; i < 64; i++)
+	    picture->non_intra_quantizer_matrix[i] = 16;
+    }
+
+    // MPEG1 - for testing only
+    picture->mpeg1 = 1;
+    picture->intra_dc_precision = 0;
+    picture->frame_pred_frame_dct = 1;
+    picture->q_scale_type = 0;
+    picture->concealment_motion_vectors = 0;
+    //picture->alternate_scan = 0;
+    picture->picture_structure = FRAME_PICTURE;
+    //picture->second_field = 0;
+
+    return 0;
+}
+
+static int header_process_sequence_extension (picture_t * picture,
+					      uint8_t * buffer)
+{
+    // MPEG1 - for testing only
+    picture->mpeg1 = 0;
+
+    // check chroma format, size extensions, marker bit
+    if(((buffer[1]>>1)&3)!=1){
+      printf("This CHROMA format not yet supported :(\n");
+      return 1;
+    }
+    if ((buffer[1] & 1) || (buffer[2] & 0xe0)){
+      printf("Big resolution video not yet supported :(\n");
+      return 1;
+    }
+    if((buffer[3] & 0x01) != 0x01) return 1; // marker bit
+
+
+    // this is not used by the decoder
+    picture->progressive_sequence = (buffer[1] >> 3) & 1;
+
+    if (picture->progressive_sequence)
+	picture->coded_picture_height =
+	    (picture->coded_picture_height + 31) & ~31;
+    picture->bitrate>>=1; // hack
+
+    return 0;
+}
+
+static int header_process_quant_matrix_extension (picture_t * picture,
+						  uint8_t * buffer)
+{
+    int i;
+
+    if (buffer[0] & 8) {
+	for (i = 0; i < 64; i++)
+	    picture->intra_quantizer_matrix[scan_norm[i]] =
+		(buffer[i] << 5) | (buffer[i+1] >> 3);
+	buffer += 64;
+    }
+
+    if (buffer[0] & 4) {
+	for (i = 0; i < 64; i++)
+	    picture->non_intra_quantizer_matrix[scan_norm[i]] =
+		(buffer[i] << 6) | (buffer[i+1] >> 2);
+    }
+
+    return 0;
+}
+
+static int header_process_picture_coding_extension (picture_t * picture, uint8_t * buffer)
+{
+    //pre subtract 1 for use later in compute_motion_vector
+    picture->f_code[0][0] = (buffer[0] & 15) - 1;
+    picture->f_code[0][1] = (buffer[1] >> 4) - 1;
+    picture->f_code[1][0] = (buffer[1] & 15) - 1;
+    picture->f_code[1][1] = (buffer[2] >> 4) - 1;
+
+    picture->intra_dc_precision = (buffer[2] >> 2) & 3;
+    picture->picture_structure = buffer[2] & 3;
+    picture->frame_pred_frame_dct = (buffer[3] >> 6) & 1;
+    picture->concealment_motion_vectors = (buffer[3] >> 5) & 1;
+    picture->q_scale_type = (buffer[3] >> 4) & 1;
+    picture->intra_vlc_format = (buffer[3] >> 3) & 1;
+
+    if (buffer[3] & 4)	// alternate_scan
+	picture->scan = scan_alt;
+    else
+	picture->scan = scan_norm;
+
+    // these are not used by the decoder
+    picture->top_field_first = buffer[3] >> 7;
+    picture->repeat_first_field = (buffer[3] >> 1) & 1;
+    picture->progressive_frame = buffer[4] >> 7;
+
+    // repeat_first implementation by A'rpi/ESP-team, based on libmpeg3:
+    if(picture->repeat_count>=100) picture->repeat_count=0;
+    if(picture->repeat_first_field){
+        if(picture->progressive_sequence){
+            if(picture->top_field_first)
+                picture->repeat_count+=200;
+            else
+                picture->repeat_count+=100;
+        } else
+        if(picture->progressive_frame){
+                picture->repeat_count+=50;
+        }
+    }
+
+    return 0;
+}
+
+int header_process_extension (picture_t * picture, uint8_t * buffer)
+{
+    switch (buffer[0] & 0xf0) {
+    case 0x10:	// sequence extension
+	return header_process_sequence_extension (picture, buffer);
+
+    case 0x30:	// quant matrix extension
+	return header_process_quant_matrix_extension (picture, buffer);
+
+    case 0x80:	// picture coding extension
+	return header_process_picture_coding_extension (picture, buffer);
+    }
+
+    return 0;
+}
+
+int header_process_picture_header (picture_t *picture, uint8_t * buffer)
+{
+    picture->picture_coding_type = (buffer [1] >> 3) & 7;
+
+    // forward_f_code and backward_f_code - used in mpeg1 only
+    picture->f_code[0][1] = (buffer[3] >> 2) & 1;
+    picture->f_code[0][0] =
+	(((buffer[3] << 1) | (buffer[4] >> 7)) & 7) - 1;
+    picture->f_code[1][1] = (buffer[4] >> 6) & 1;
+    picture->f_code[1][0] = ((buffer[4] >> 3) & 7) - 1;
+
+    // move in header_process_picture_header
+        picture->second_field =
+            (picture->picture_structure != FRAME_PICTURE) &&
+            !(picture->second_field);
+
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/idct.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,289 @@
+/*
+ * idct.c
+ * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * Portions of this code are from the MPEG software simulation group
+ * idct implementation. This code will be replaced with a new
+ * implementation soon.
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *
+ * mpeg2dec 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.
+ *
+ * mpeg2dec 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/**********************************************************/
+/* inverse two dimensional DCT, Chen-Wang algorithm */
+/* (cf. IEEE ASSP-32, pp. 803-816, Aug. 1984) */
+/* 32-bit integer arithmetic (8 bit coefficients) */
+/* 11 mults, 29 adds per DCT */
+/* sE, 18.8.91 */
+/**********************************************************/
+/* coefficients extended to 12 bit for IEEE1180-1990 */
+/* compliance sE, 2.1.94 */
+/**********************************************************/
+
+/* this code assumes >> to be a two's-complement arithmetic */
+/* right shift: (-2)>>1 == -1 , (-3)>>1 == -2 */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <inttypes.h>
+
+#include "mpeg2_internal.h"
+#include "mm_accel.h"
+
+#define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
+#define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
+#define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
+#define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
+#define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
+#define W7 565  /* 2048*sqrt (2)*cos (7*pi/16) */
+
+
+// idct main entry point 
+void (*idct_block_copy) (int16_t * block, uint8_t * dest, int stride);
+void (*idct_block_add) (int16_t * block, uint8_t * dest, int stride);
+
+static void idct_block_copy_c (int16_t *block, uint8_t * dest, int stride);
+static void idct_block_add_c (int16_t *block, uint8_t * dest, int stride);
+
+static uint8_t clip_lut[1024];
+#define CLIP(i) ((clip_lut+384)[ (i)])
+
+void idct_init (void)
+{
+#ifdef ARCH_X86
+    if (config.flags & MM_ACCEL_X86_MMXEXT) {
+	fprintf (stderr, "Using MMXEXT for IDCT transform\n");
+	idct_block_copy = idct_block_copy_mmxext;
+	idct_block_add = idct_block_add_mmxext;
+	idct_mmx_init ();
+    } else if (config.flags & MM_ACCEL_X86_MMX) {
+	fprintf (stderr, "Using MMX for IDCT transform\n");
+	idct_block_copy = idct_block_copy_mmx;
+	idct_block_add = idct_block_add_mmx;
+	idct_mmx_init ();
+    } else
+#endif
+#ifdef LIBMPEG2_MLIB
+    if (config.flags & MM_ACCEL_MLIB) {
+	fprintf (stderr, "Using mlib for IDCT transform\n");
+	idct_block_copy = idct_block_copy_mlib;
+	idct_block_add = idct_block_add_mlib;
+    } else
+#endif
+    {
+	int i;
+
+	fprintf (stderr, "No accelerated IDCT transform found\n");
+	idct_block_copy = idct_block_copy_c;
+	idct_block_add = idct_block_add_c;
+	for (i = -384; i < 640; i++)
+	    clip_lut[i+384] = (i < 0) ? 0 : ((i > 255) ? 255 : i);
+    }
+}
+
+/* row (horizontal) IDCT
+ *
+ * 7 pi 1
+ * dst[k] = sum c[l] * src[l] * cos ( -- * ( k + - ) * l )
+ * l=0 8 2
+ *
+ * where: c[0] = 128
+ * c[1..7] = 128*sqrt (2)
+ */
+
+static void inline idct_row (int16_t * block)
+{
+    int x0, x1, x2, x3, x4, x5, x6, x7, x8;
+
+    x1 = block[4] << 11;
+    x2 = block[6];
+    x3 = block[2];
+    x4 = block[1];
+    x5 = block[7];
+    x6 = block[5];
+    x7 = block[3];
+
+    /* shortcut */
+    if (! (x1 | x2 | x3 | x4 | x5 | x6 | x7 )) {
+	block[0] = block[1] = block[2] = block[3] = block[4] =
+	    block[5] = block[6] = block[7] = block[0]<<3;
+	return;
+    }
+
+    x0 = (block[0] << 11) + 128; /* for proper rounding in the fourth stage */
+
+    /* first stage */
+    x8 = W7 * (x4 + x5);
+    x4 = x8 + (W1 - W7) * x4;
+    x5 = x8 - (W1 + W7) * x5;
+    x8 = W3 * (x6 + x7);
+    x6 = x8 - (W3 - W5) * x6;
+    x7 = x8 - (W3 + W5) * x7;
+ 
+    /* second stage */
+    x8 = x0 + x1;
+    x0 -= x1;
+    x1 = W6 * (x3 + x2);
+    x2 = x1 - (W2 + W6) * x2;
+    x3 = x1 + (W2 - W6) * x3;
+    x1 = x4 + x6;
+    x4 -= x6;
+    x6 = x5 + x7;
+    x5 -= x7;
+ 
+    /* third stage */
+    x7 = x8 + x3;
+    x8 -= x3;
+    x3 = x0 + x2;
+    x0 -= x2;
+    x2 = (181 * (x4 + x5) + 128) >> 8;
+    x4 = (181 * (x4 - x5) + 128) >> 8;
+ 
+    /* fourth stage */
+    block[0] = (x7 + x1) >> 8;
+    block[1] = (x3 + x2) >> 8;
+    block[2] = (x0 + x4) >> 8;
+    block[3] = (x8 + x6) >> 8;
+    block[4] = (x8 - x6) >> 8;
+    block[5] = (x0 - x4) >> 8;
+    block[6] = (x3 - x2) >> 8;
+    block[7] = (x7 - x1) >> 8;
+}
+
+/* column (vertical) IDCT
+ *
+ * 7 pi 1
+ * dst[8*k] = sum c[l] * src[8*l] * cos ( -- * ( k + - ) * l )
+ * l=0 8 2
+ *
+ * where: c[0] = 1/1024
+ * c[1..7] = (1/1024)*sqrt (2)
+ */
+
+static void inline idct_col (int16_t *block)
+{
+    int x0, x1, x2, x3, x4, x5, x6, x7, x8;
+
+    /* shortcut */
+    x1 = block [8*4] << 8;
+    x2 = block [8*6];
+    x3 = block [8*2];
+    x4 = block [8*1];
+    x5 = block [8*7];
+    x6 = block [8*5];
+    x7 = block [8*3];
+
+#if 0
+    if (! (x1 | x2 | x3 | x4 | x5 | x6 | x7 )) {
+	block[8*0] = block[8*1] = block[8*2] = block[8*3] = block[8*4] =
+	    block[8*5] = block[8*6] = block[8*7] = (block[8*0] + 32) >> 6;
+	return;
+    }
+#endif
+
+    x0 = (block[8*0] << 8) + 8192;
+
+    /* first stage */
+    x8 = W7 * (x4 + x5) + 4;
+    x4 = (x8 + (W1 - W7) * x4) >> 3;
+    x5 = (x8 - (W1 + W7) * x5) >> 3;
+    x8 = W3 * (x6 + x7) + 4;
+    x6 = (x8 - (W3 - W5) * x6) >> 3;
+    x7 = (x8 - (W3 + W5) * x7) >> 3;
+ 
+    /* second stage */
+    x8 = x0 + x1;
+    x0 -= x1;
+    x1 = W6 * (x3 + x2) + 4;
+    x2 = (x1 - (W2 + W6) * x2) >> 3;
+    x3 = (x1 + (W2 - W6) * x3) >> 3;
+    x1 = x4 + x6;
+    x4 -= x6;
+    x6 = x5 + x7;
+    x5 -= x7;
+ 
+    /* third stage */
+    x7 = x8 + x3;
+    x8 -= x3;
+    x3 = x0 + x2;
+    x0 -= x2;
+    x2 = (181 * (x4 + x5) + 128) >> 8;
+    x4 = (181 * (x4 - x5) + 128) >> 8;
+ 
+    /* fourth stage */
+    block[8*0] = (x7 + x1) >> 14;
+    block[8*1] = (x3 + x2) >> 14;
+    block[8*2] = (x0 + x4) >> 14;
+    block[8*3] = (x8 + x6) >> 14;
+    block[8*4] = (x8 - x6) >> 14;
+    block[8*5] = (x0 - x4) >> 14;
+    block[8*6] = (x3 - x2) >> 14;
+    block[8*7] = (x7 - x1) >> 14;
+}
+
+void idct_block_copy_c (int16_t * block, uint8_t * dest, int stride)
+{
+    int i;
+
+    for (i = 0; i < 8; i++)
+	idct_row (block + 8 * i);
+
+    for (i = 0; i < 8; i++)
+	idct_col (block + i);
+
+    i = 8;
+    do {
+	dest[0] = CLIP (block[0]);
+	dest[1] = CLIP (block[1]);
+	dest[2] = CLIP (block[2]);
+	dest[3] = CLIP (block[3]);
+	dest[4] = CLIP (block[4]);
+	dest[5] = CLIP (block[5]);
+	dest[6] = CLIP (block[6]);
+	dest[7] = CLIP (block[7]);
+
+	dest += stride;
+	block += 8;
+    } while (--i);
+}
+
+void idct_block_add_c (int16_t * block, uint8_t * dest, int stride)
+{
+    int i;
+
+    for (i = 0; i < 8; i++)
+	idct_row (block + 8 * i);
+
+    for (i = 0; i < 8; i++)
+	idct_col (block + i);
+
+    i = 8;
+    do {
+	dest[0] = CLIP (block[0] + dest[0]);
+	dest[1] = CLIP (block[1] + dest[1]);
+	dest[2] = CLIP (block[2] + dest[2]);
+	dest[3] = CLIP (block[3] + dest[3]);
+	dest[4] = CLIP (block[4] + dest[4]);
+	dest[5] = CLIP (block[5] + dest[5]);
+	dest[6] = CLIP (block[6] + dest[6]);
+	dest[7] = CLIP (block[7] + dest[7]);
+
+	dest += stride;
+	block += 8;
+    } while (--i);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/idct_mlib.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,47 @@
+/*
+ * idct_mlib.c
+ * Copyright (C) 1999 Håkan Hjort <d95hjort@dtek.chalmers.se>
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *
+ * mpeg2dec 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.
+ *
+ * mpeg2dec 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "config.h"
+
+#ifdef LIBMPEG2_MLIB
+
+#include <inttypes.h>
+#include <mlib_types.h>
+#include <mlib_status.h>
+#include <mlib_sys.h>
+#include <mlib_video.h>
+
+#include "mpeg2_internal.h"
+
+void idct_block_copy_mlib (int16_t * block, uint8_t * dest, int stride)
+{
+    mlib_VideoIDCT8x8_U8_S16 (dest, block, stride);
+}
+
+void idct_block_add_mlib (int16_t * block, uint8_t * dest, int stride)
+{
+    // Should we use mlib_VideoIDCT_IEEE_S16_S16 here ??
+    // it's ~30% slower.
+    mlib_VideoIDCT8x8_S16_S16 (block, block);
+    mlib_VideoAddBlock_U8_S16 (dest, block, stride);
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/idct_mmx.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,706 @@
+/*
+ * idct_mmx.c
+ * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *
+ * mpeg2dec 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.
+ *
+ * mpeg2dec 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "config.h"
+
+#ifdef ARCH_X86
+
+#include <inttypes.h>
+
+#include "mpeg2_internal.h"
+#include "attributes.h"
+#include "mmx.h"
+
+#define ROW_SHIFT 11
+#define COL_SHIFT 6
+
+#define round(bias) ((int)(((bias)+0.5) * (1<<ROW_SHIFT)))
+#define rounder(bias) {round (bias), round (bias)}
+
+
+#if 0
+// C row IDCT - its just here to document the MMXEXT and MMX versions
+static inline void idct_row (int16_t * row, int offset,
+			     int16_t * table, int32_t * rounder)
+{
+    int C1, C2, C3, C4, C5, C6, C7;
+    int a0, a1, a2, a3, b0, b1, b2, b3;
+
+    row += offset;
+
+    C1 = table[1];
+    C2 = table[2];
+    C3 = table[3];
+    C4 = table[4];
+    C5 = table[5];
+    C6 = table[6];
+    C7 = table[7];
+
+    a0 = C4*row[0] + C2*row[2] + C4*row[4] + C6*row[6] + *rounder;
+    a1 = C4*row[0] + C6*row[2] - C4*row[4] - C2*row[6] + *rounder;
+    a2 = C4*row[0] - C6*row[2] - C4*row[4] + C2*row[6] + *rounder;
+    a3 = C4*row[0] - C2*row[2] + C4*row[4] - C6*row[6] + *rounder;
+
+    b0 = C1*row[1] + C3*row[3] + C5*row[5] + C7*row[7];
+    b1 = C3*row[1] - C7*row[3] - C1*row[5] - C5*row[7];
+    b2 = C5*row[1] - C1*row[3] + C7*row[5] + C3*row[7];
+    b3 = C7*row[1] - C5*row[3] + C3*row[5] - C1*row[7];
+
+    row[0] = (a0 + b0) >> ROW_SHIFT;
+    row[1] = (a1 + b1) >> ROW_SHIFT;
+    row[2] = (a2 + b2) >> ROW_SHIFT;
+    row[3] = (a3 + b3) >> ROW_SHIFT;
+    row[4] = (a3 - b3) >> ROW_SHIFT;
+    row[5] = (a2 - b2) >> ROW_SHIFT;
+    row[6] = (a1 - b1) >> ROW_SHIFT;
+    row[7] = (a0 - b0) >> ROW_SHIFT;
+}
+#endif
+
+
+// MMXEXT row IDCT
+
+#define mmxext_table(c1,c2,c3,c4,c5,c6,c7)	{  c4,  c2, -c4, -c2,	\
+						   c4,  c6,  c4,  c6,	\
+						   c1,  c3, -c1, -c5,	\
+						   c5,  c7,  c3, -c7,	\
+						   c4, -c6,  c4, -c6,	\
+						  -c4,  c2,  c4, -c2,	\
+						   c5, -c1,  c3, -c1,	\
+						   c7,  c3,  c7, -c5 }
+
+static inline void mmxext_row_head (int16_t * row, int offset, int16_t * table)
+{
+    movq_m2r (*(row+offset), mm2);	// mm2 = x6 x4 x2 x0
+
+    movq_m2r (*(row+offset+4), mm5);	// mm5 = x7 x5 x3 x1
+    movq_r2r (mm2, mm0);		// mm0 = x6 x4 x2 x0
+
+    movq_m2r (*table, mm3);		// mm3 = -C2 -C4 C2 C4
+    movq_r2r (mm5, mm6);		// mm6 = x7 x5 x3 x1
+
+    movq_m2r (*(table+4), mm4);		// mm4 = C6 C4 C6 C4
+    pmaddwd_r2r (mm0, mm3);		// mm3 = -C4*x4-C2*x6 C4*x0+C2*x2
+
+    pshufw_r2r (mm2, mm2, 0x4e);	// mm2 = x2 x0 x6 x4
+}
+
+static inline void mmxext_row (int16_t * table, int32_t * rounder)
+{
+    movq_m2r (*(table+8), mm1);		// mm1 = -C5 -C1 C3 C1
+    pmaddwd_r2r (mm2, mm4);		// mm4 = C4*x0+C6*x2 C4*x4+C6*x6
+
+    pmaddwd_m2r (*(table+16), mm0);	// mm0 = C4*x4-C6*x6 C4*x0-C6*x2
+    pshufw_r2r (mm6, mm6, 0x4e);	// mm6 = x3 x1 x7 x5
+
+    movq_m2r (*(table+12), mm7);	// mm7 = -C7 C3 C7 C5
+    pmaddwd_r2r (mm5, mm1);		// mm1 = -C1*x5-C5*x7 C1*x1+C3*x3
+
+    paddd_m2r (*rounder, mm3);		// mm3 += rounder
+    pmaddwd_r2r (mm6, mm7);		// mm7 = C3*x1-C7*x3 C5*x5+C7*x7
+
+    pmaddwd_m2r (*(table+20), mm2);	// mm2 = C4*x0-C2*x2 -C4*x4+C2*x6
+    paddd_r2r (mm4, mm3);		// mm3 = a1 a0 + rounder
+
+    pmaddwd_m2r (*(table+24), mm5);	// mm5 = C3*x5-C1*x7 C5*x1-C1*x3
+    movq_r2r (mm3, mm4);		// mm4 = a1 a0 + rounder
+
+    pmaddwd_m2r (*(table+28), mm6);	// mm6 = C7*x1-C5*x3 C7*x5+C3*x7
+    paddd_r2r (mm7, mm1);		// mm1 = b1 b0
+
+    paddd_m2r (*rounder, mm0);		// mm0 += rounder
+    psubd_r2r (mm1, mm3);		// mm3 = a1-b1 a0-b0 + rounder
+
+    psrad_i2r (ROW_SHIFT, mm3);		// mm3 = y6 y7
+    paddd_r2r (mm4, mm1);		// mm1 = a1+b1 a0+b0 + rounder
+
+    paddd_r2r (mm2, mm0);		// mm0 = a3 a2 + rounder
+    psrad_i2r (ROW_SHIFT, mm1);		// mm1 = y1 y0
+
+    paddd_r2r (mm6, mm5);		// mm5 = b3 b2
+    movq_r2r (mm0, mm4);		// mm4 = a3 a2 + rounder
+
+    paddd_r2r (mm5, mm0);		// mm0 = a3+b3 a2+b2 + rounder
+    psubd_r2r (mm5, mm4);		// mm4 = a3-b3 a2-b2 + rounder
+}
+
+static inline void mmxext_row_tail (int16_t * row, int store)
+{
+    psrad_i2r (ROW_SHIFT, mm0);		// mm0 = y3 y2
+
+    psrad_i2r (ROW_SHIFT, mm4);		// mm4 = y4 y5
+
+    packssdw_r2r (mm0, mm1);		// mm1 = y3 y2 y1 y0
+
+    packssdw_r2r (mm3, mm4);		// mm4 = y6 y7 y4 y5
+
+    movq_r2m (mm1, *(row+store));	// save y3 y2 y1 y0
+    pshufw_r2r (mm4, mm4, 0xb1);	// mm4 = y7 y6 y5 y4
+
+    // slot
+
+    movq_r2m (mm4, *(row+store+4));	// save y7 y6 y5 y4
+}
+
+static inline void mmxext_row_mid (int16_t * row, int store,
+				   int offset, int16_t * table)
+{
+    movq_m2r (*(row+offset), mm2);	// mm2 = x6 x4 x2 x0
+    psrad_i2r (ROW_SHIFT, mm0);		// mm0 = y3 y2
+
+    movq_m2r (*(row+offset+4), mm5);	// mm5 = x7 x5 x3 x1
+    psrad_i2r (ROW_SHIFT, mm4);		// mm4 = y4 y5
+
+    packssdw_r2r (mm0, mm1);		// mm1 = y3 y2 y1 y0
+    movq_r2r (mm5, mm6);		// mm6 = x7 x5 x3 x1
+
+    packssdw_r2r (mm3, mm4);		// mm4 = y6 y7 y4 y5
+    movq_r2r (mm2, mm0);		// mm0 = x6 x4 x2 x0
+
+    movq_r2m (mm1, *(row+store));	// save y3 y2 y1 y0
+    pshufw_r2r (mm4, mm4, 0xb1);	// mm4 = y7 y6 y5 y4
+
+    movq_m2r (*table, mm3);		// mm3 = -C2 -C4 C2 C4
+    movq_r2m (mm4, *(row+store+4));	// save y7 y6 y5 y4
+
+    pmaddwd_r2r (mm0, mm3);		// mm3 = -C4*x4-C2*x6 C4*x0+C2*x2
+
+    movq_m2r (*(table+4), mm4);		// mm4 = C6 C4 C6 C4
+    pshufw_r2r (mm2, mm2, 0x4e);	// mm2 = x2 x0 x6 x4
+}
+
+
+// MMX row IDCT
+
+#define mmx_table(c1,c2,c3,c4,c5,c6,c7)	{  c4,  c2,  c4,  c6,	\
+					   c4,  c6, -c4, -c2,	\
+					   c1,  c3,  c3, -c7,	\
+					   c5,  c7, -c1, -c5,	\
+					   c4, -c6,  c4, -c2,	\
+					  -c4,  c2,  c4, -c6,	\
+					   c5, -c1,  c7, -c5,	\
+					   c7,  c3,  c3, -c1 }
+
+static inline void mmx_row_head (int16_t * row, int offset, int16_t * table)
+{
+    movq_m2r (*(row+offset), mm2);	// mm2 = x6 x4 x2 x0
+
+    movq_m2r (*(row+offset+4), mm5);	// mm5 = x7 x5 x3 x1
+    movq_r2r (mm2, mm0);		// mm0 = x6 x4 x2 x0
+
+    movq_m2r (*table, mm3);		// mm3 = C6 C4 C2 C4
+    movq_r2r (mm5, mm6);		// mm6 = x7 x5 x3 x1
+
+    punpckldq_r2r (mm0, mm0);		// mm0 = x2 x0 x2 x0
+
+    movq_m2r (*(table+4), mm4);		// mm4 = -C2 -C4 C6 C4
+    pmaddwd_r2r (mm0, mm3);		// mm3 = C4*x0+C6*x2 C4*x0+C2*x2
+
+    movq_m2r (*(table+8), mm1);		// mm1 = -C7 C3 C3 C1
+    punpckhdq_r2r (mm2, mm2);		// mm2 = x6 x4 x6 x4
+}
+
+static inline void mmx_row (int16_t * table, int32_t * rounder)
+{
+    pmaddwd_r2r (mm2, mm4);		// mm4 = -C4*x4-C2*x6 C4*x4+C6*x6
+    punpckldq_r2r (mm5, mm5);		// mm5 = x3 x1 x3 x1
+
+    pmaddwd_m2r (*(table+16), mm0);	// mm0 = C4*x0-C2*x2 C4*x0-C6*x2
+    punpckhdq_r2r (mm6, mm6);		// mm6 = x7 x5 x7 x5
+
+    movq_m2r (*(table+12), mm7);	// mm7 = -C5 -C1 C7 C5
+    pmaddwd_r2r (mm5, mm1);		// mm1 = C3*x1-C7*x3 C1*x1+C3*x3
+
+    paddd_m2r (*rounder, mm3);		// mm3 += rounder
+    pmaddwd_r2r (mm6, mm7);		// mm7 = -C1*x5-C5*x7 C5*x5+C7*x7
+
+    pmaddwd_m2r (*(table+20), mm2);	// mm2 = C4*x4-C6*x6 -C4*x4+C2*x6
+    paddd_r2r (mm4, mm3);		// mm3 = a1 a0 + rounder
+
+    pmaddwd_m2r (*(table+24), mm5);	// mm5 = C7*x1-C5*x3 C5*x1-C1*x3
+    movq_r2r (mm3, mm4);		// mm4 = a1 a0 + rounder
+
+    pmaddwd_m2r (*(table+28), mm6);	// mm6 = C3*x5-C1*x7 C7*x5+C3*x7
+    paddd_r2r (mm7, mm1);		// mm1 = b1 b0
+
+    paddd_m2r (*rounder, mm0);		// mm0 += rounder
+    psubd_r2r (mm1, mm3);		// mm3 = a1-b1 a0-b0 + rounder
+
+    psrad_i2r (ROW_SHIFT, mm3);		// mm3 = y6 y7
+    paddd_r2r (mm4, mm1);		// mm1 = a1+b1 a0+b0 + rounder
+
+    paddd_r2r (mm2, mm0);		// mm0 = a3 a2 + rounder
+    psrad_i2r (ROW_SHIFT, mm1);		// mm1 = y1 y0
+
+    paddd_r2r (mm6, mm5);		// mm5 = b3 b2
+    movq_r2r (mm0, mm7);		// mm7 = a3 a2 + rounder
+
+    paddd_r2r (mm5, mm0);		// mm0 = a3+b3 a2+b2 + rounder
+    psubd_r2r (mm5, mm7);		// mm7 = a3-b3 a2-b2 + rounder
+}
+
+static inline void mmx_row_tail (int16_t * row, int store)
+{
+    psrad_i2r (ROW_SHIFT, mm0);		// mm0 = y3 y2
+
+    psrad_i2r (ROW_SHIFT, mm7);		// mm7 = y4 y5
+
+    packssdw_r2r (mm0, mm1);		// mm1 = y3 y2 y1 y0
+
+    packssdw_r2r (mm3, mm7);		// mm7 = y6 y7 y4 y5
+
+    movq_r2m (mm1, *(row+store));	// save y3 y2 y1 y0
+    movq_r2r (mm7, mm4);		// mm4 = y6 y7 y4 y5
+
+    pslld_i2r (16, mm7);		// mm7 = y7 0 y5 0
+
+    psrld_i2r (16, mm4);		// mm4 = 0 y6 0 y4
+
+    por_r2r (mm4, mm7);			// mm7 = y7 y6 y5 y4
+
+    // slot
+
+    movq_r2m (mm7, *(row+store+4));	// save y7 y6 y5 y4
+}
+
+static inline void mmx_row_mid (int16_t * row, int store,
+				int offset, int16_t * table)
+{
+    movq_m2r (*(row+offset), mm2);	// mm2 = x6 x4 x2 x0
+    psrad_i2r (ROW_SHIFT, mm0);		// mm0 = y3 y2
+
+    movq_m2r (*(row+offset+4), mm5);	// mm5 = x7 x5 x3 x1
+    psrad_i2r (ROW_SHIFT, mm7);		// mm7 = y4 y5
+
+    packssdw_r2r (mm0, mm1);		// mm1 = y3 y2 y1 y0
+    movq_r2r (mm5, mm6);		// mm6 = x7 x5 x3 x1
+
+    packssdw_r2r (mm3, mm7);		// mm7 = y6 y7 y4 y5
+    movq_r2r (mm2, mm0);		// mm0 = x6 x4 x2 x0
+
+    movq_r2m (mm1, *(row+store));	// save y3 y2 y1 y0
+    movq_r2r (mm7, mm1);		// mm1 = y6 y7 y4 y5
+
+    punpckldq_r2r (mm0, mm0);		// mm0 = x2 x0 x2 x0
+    psrld_i2r (16, mm7);		// mm7 = 0 y6 0 y4
+
+    movq_m2r (*table, mm3);		// mm3 = C6 C4 C2 C4
+    pslld_i2r (16, mm1);		// mm1 = y7 0 y5 0
+
+    movq_m2r (*(table+4), mm4);		// mm4 = -C2 -C4 C6 C4
+    por_r2r (mm1, mm7);			// mm7 = y7 y6 y5 y4
+
+    movq_m2r (*(table+8), mm1);		// mm1 = -C7 C3 C3 C1
+    punpckhdq_r2r (mm2, mm2);		// mm2 = x6 x4 x6 x4
+
+    movq_r2m (mm7, *(row+store+4));	// save y7 y6 y5 y4
+    pmaddwd_r2r (mm0, mm3);		// mm3 = C4*x0+C6*x2 C4*x0+C2*x2
+}
+
+
+#if 0
+// C column IDCT - its just here to document the MMXEXT and MMX versions
+static inline void idct_col (int16_t * col, int offset)
+{
+// multiplication - as implemented on mmx
+#define F(c,x) (((c) * (x)) >> 16)
+
+// saturation - it helps us handle torture test cases
+#define S(x) (((x)>32767) ? 32767 : ((x)<-32768) ? -32768 : (x))
+
+    int16_t x0, x1, x2, x3, x4, x5, x6, x7;
+    int16_t y0, y1, y2, y3, y4, y5, y6, y7;
+    int16_t a0, a1, a2, a3, b0, b1, b2, b3;
+    int16_t u04, v04, u26, v26, u17, v17, u35, v35, u12, v12;
+
+    col += offset;
+
+    x0 = col[0*8];
+    x1 = col[1*8];
+    x2 = col[2*8];
+    x3 = col[3*8];
+    x4 = col[4*8];
+    x5 = col[5*8];
+    x6 = col[6*8];
+    x7 = col[7*8];
+
+    u04 = S (x0 + x4);
+    v04 = S (x0 - x4);
+    u26 = S (F (T2, x6) + x2);	// -0.5
+    v26 = S (F (T2, x2) - x6);	// -0.5
+
+    a0 = S (u04 + u26);
+    a1 = S (v04 + v26);
+    a2 = S (v04 - v26);
+    a3 = S (u04 - u26);
+
+    u17 = S (F (T1, x7) + x1);	// -0.5
+    v17 = S (F (T1, x1) - x7);	// -0.5
+    u35 = S (F (T3, x5) + x3);	// -0.5
+    v35 = S (F (T3, x3) - x5);	// -0.5
+
+    b0 = S (u17 + u35);
+    b3 = S (v17 - v35);
+    u12 = S (u17 - u35);
+    v12 = S (v17 + v35);
+    u12 = S (2 * F (C4, u12));	// -0.5
+    v12 = S (2 * F (C4, v12));	// -0.5
+    b1 = S (u12 + v12);
+    b2 = S (u12 - v12);
+
+    y0 = S (a0 + b0) >> COL_SHIFT;
+    y1 = S (a1 + b1) >> COL_SHIFT;
+    y2 = S (a2 + b2) >> COL_SHIFT;
+    y3 = S (a3 + b3) >> COL_SHIFT;
+
+    y4 = S (a3 - b3) >> COL_SHIFT;
+    y5 = S (a2 - b2) >> COL_SHIFT;
+    y6 = S (a1 - b1) >> COL_SHIFT;
+    y7 = S (a0 - b0) >> COL_SHIFT;
+
+    col[0*8] = y0;
+    col[1*8] = y1;
+    col[2*8] = y2;
+    col[3*8] = y3;
+    col[4*8] = y4;
+    col[5*8] = y5;
+    col[6*8] = y6;
+    col[7*8] = y7;
+}
+#endif
+
+
+// MMX column IDCT
+static inline void idct_col (int16_t * col, int offset)
+{
+#define T1 13036
+#define T2 27146
+#define T3 43790
+#define C4 23170
+
+    static short _T1[] ATTR_ALIGN(8) = {T1,T1,T1,T1};
+    static short _T2[] ATTR_ALIGN(8) = {T2,T2,T2,T2};
+    static short _T3[] ATTR_ALIGN(8) = {T3,T3,T3,T3};
+    static short _C4[] ATTR_ALIGN(8) = {C4,C4,C4,C4};
+    static mmx_t scratch0, scratch1;
+
+    /* column code adapted from peter gubanov */
+    /* http://www.elecard.com/peter/idct.shtml */
+
+    movq_m2r (*_T1, mm0);		// mm0 = T1
+
+    movq_m2r (*(col+offset+1*8), mm1);	// mm1 = x1
+    movq_r2r (mm0, mm2);		// mm2 = T1
+
+    movq_m2r (*(col+offset+7*8), mm4);	// mm4 = x7
+    pmulhw_r2r (mm1, mm0);		// mm0 = T1*x1
+
+    movq_m2r (*_T3, mm5);		// mm5 = T3
+    pmulhw_r2r (mm4, mm2);		// mm2 = T1*x7
+
+    movq_m2r (*(col+offset+5*8), mm6);	// mm6 = x5
+    movq_r2r (mm5, mm7);		// mm7 = T3-1
+
+    movq_m2r (*(col+offset+3*8), mm3);	// mm3 = x3
+    psubsw_r2r (mm4, mm0);		// mm0 = v17
+
+    movq_m2r (*_T2, mm4);		// mm4 = T2
+    pmulhw_r2r (mm3, mm5);		// mm5 = (T3-1)*x3
+
+    paddsw_r2r (mm2, mm1);		// mm1 = u17
+    pmulhw_r2r (mm6, mm7);		// mm7 = (T3-1)*x5
+
+    // slot
+
+    movq_r2r (mm4, mm2);		// mm2 = T2
+    paddsw_r2r (mm3, mm5);		// mm5 = T3*x3
+
+    pmulhw_m2r (*(col+offset+2*8), mm4);// mm4 = T2*x2
+    paddsw_r2r (mm6, mm7);		// mm7 = T3*x5
+
+    psubsw_r2r (mm6, mm5);		// mm5 = v35
+    paddsw_r2r (mm3, mm7);		// mm7 = u35
+
+    movq_m2r (*(col+offset+6*8), mm3);	// mm3 = x6
+    movq_r2r (mm0, mm6);		// mm6 = v17
+
+    pmulhw_r2r (mm3, mm2);		// mm2 = T2*x6
+    psubsw_r2r (mm5, mm0);		// mm0 = b3
+
+    psubsw_r2r (mm3, mm4);		// mm4 = v26
+    paddsw_r2r (mm6, mm5);		// mm5 = v12
+
+    movq_r2m (mm0, scratch0);		// save b3
+    movq_r2r (mm1, mm6);		// mm6 = u17
+
+    paddsw_m2r (*(col+offset+2*8), mm2);// mm2 = u26
+    paddsw_r2r (mm7, mm6);		// mm6 = b0
+
+    psubsw_r2r (mm7, mm1);		// mm1 = u12
+    movq_r2r (mm1, mm7);		// mm7 = u12
+
+    movq_m2r (*(col+offset+0*8), mm3);	// mm3 = x0
+    paddsw_r2r (mm5, mm1);		// mm1 = u12+v12
+
+    movq_m2r (*_C4, mm0);		// mm0 = C4/2
+    psubsw_r2r (mm5, mm7);		// mm7 = u12-v12
+
+    movq_r2m (mm6, scratch1);		// save b0
+    pmulhw_r2r (mm0, mm1);		// mm1 = b1/2
+
+    movq_r2r (mm4, mm6);		// mm6 = v26
+    pmulhw_r2r (mm0, mm7);		// mm7 = b2/2
+
+    movq_m2r (*(col+offset+4*8), mm5);	// mm5 = x4
+    movq_r2r (mm3, mm0);		// mm0 = x0
+
+    psubsw_r2r (mm5, mm3);		// mm3 = v04
+    paddsw_r2r (mm5, mm0);		// mm0 = u04
+
+    paddsw_r2r (mm3, mm4);		// mm4 = a1
+    movq_r2r (mm0, mm5);		// mm5 = u04
+
+    psubsw_r2r (mm6, mm3);		// mm3 = a2
+    paddsw_r2r (mm2, mm5);		// mm5 = a0
+
+    paddsw_r2r (mm1, mm1);		// mm1 = b1
+    psubsw_r2r (mm2, mm0);		// mm0 = a3
+
+    paddsw_r2r (mm7, mm7);		// mm7 = b2
+    movq_r2r (mm3, mm2);		// mm2 = a2
+
+    movq_r2r (mm4, mm6);		// mm6 = a1
+    paddsw_r2r (mm7, mm3);		// mm3 = a2+b2
+
+    psraw_i2r (COL_SHIFT, mm3);		// mm3 = y2
+    paddsw_r2r (mm1, mm4);		// mm4 = a1+b1
+
+    psraw_i2r (COL_SHIFT, mm4);		// mm4 = y1
+    psubsw_r2r (mm1, mm6);		// mm6 = a1-b1
+
+    movq_m2r (scratch1, mm1);		// mm1 = b0
+    psubsw_r2r (mm7, mm2);		// mm2 = a2-b2
+
+    psraw_i2r (COL_SHIFT, mm6);		// mm6 = y6
+    movq_r2r (mm5, mm7);		// mm7 = a0
+
+    movq_r2m (mm4, *(col+offset+1*8));	// save y1
+    psraw_i2r (COL_SHIFT, mm2);		// mm2 = y5
+
+    movq_r2m (mm3, *(col+offset+2*8));	// save y2
+    paddsw_r2r (mm1, mm5);		// mm5 = a0+b0
+
+    movq_m2r (scratch0, mm4);		// mm4 = b3
+    psubsw_r2r (mm1, mm7);		// mm7 = a0-b0
+
+    psraw_i2r (COL_SHIFT, mm5);		// mm5 = y0
+    movq_r2r (mm0, mm3);		// mm3 = a3
+
+    movq_r2m (mm2, *(col+offset+5*8));	// save y5
+    psubsw_r2r (mm4, mm3);		// mm3 = a3-b3
+
+    psraw_i2r (COL_SHIFT, mm7);		// mm7 = y7
+    paddsw_r2r (mm0, mm4);		// mm4 = a3+b3
+
+    movq_r2m (mm5, *(col+offset+0*8));	// save y0
+    psraw_i2r (COL_SHIFT, mm3);		// mm3 = y4
+
+    movq_r2m (mm6, *(col+offset+6*8));	// save y6
+    psraw_i2r (COL_SHIFT, mm4);		// mm4 = y3
+
+    movq_r2m (mm7, *(col+offset+7*8));	// save y7
+
+    movq_r2m (mm3, *(col+offset+4*8));	// save y4
+
+    movq_r2m (mm4, *(col+offset+3*8));	// save y3
+}
+
+
+static int32_t rounder0[] ATTR_ALIGN(8) =
+    rounder ((1 << (COL_SHIFT - 1)) - 0.5);
+static int32_t rounder4[] ATTR_ALIGN(8) = rounder (0);
+static int32_t rounder1[] ATTR_ALIGN(8) =
+    rounder (1.25683487303);	// C1*(C1/C4+C1+C7)/2
+static int32_t rounder7[] ATTR_ALIGN(8) =
+    rounder (-0.25);		// C1*(C7/C4+C7-C1)/2
+static int32_t rounder2[] ATTR_ALIGN(8) =
+    rounder (0.60355339059);	// C2 * (C6+C2)/2
+static int32_t rounder6[] ATTR_ALIGN(8) =
+    rounder (-0.25);		// C2 * (C6-C2)/2
+static int32_t rounder3[] ATTR_ALIGN(8) =
+    rounder (0.087788325588);	// C3*(-C3/C4+C3+C5)/2
+static int32_t rounder5[] ATTR_ALIGN(8) =
+    rounder (-0.441341716183);	// C3*(-C5/C4+C5-C3)/2
+
+
+#define declare_idct(idct,table,idct_row_head,idct_row,idct_row_tail,idct_row_mid)	\
+static inline void idct (int16_t * block)				\
+{									\
+    static int16_t table04[] ATTR_ALIGN(16) =				\
+	table (22725, 21407, 19266, 16384, 12873,  8867, 4520);		\
+    static int16_t table17[] ATTR_ALIGN(16) =				\
+	table (31521, 29692, 26722, 22725, 17855, 12299, 6270);		\
+    static int16_t table26[] ATTR_ALIGN(16) =				\
+	table (29692, 27969, 25172, 21407, 16819, 11585, 5906);		\
+    static int16_t table35[] ATTR_ALIGN(16) =				\
+	table (26722, 25172, 22654, 19266, 15137, 10426, 5315);		\
+									\
+    idct_row_head (block, 0*8, table04);				\
+    idct_row (table04, rounder0);					\
+    idct_row_mid (block, 0*8, 4*8, table04);				\
+    idct_row (table04, rounder4);					\
+    idct_row_mid (block, 4*8, 1*8, table17);				\
+    idct_row (table17, rounder1);					\
+    idct_row_mid (block, 1*8, 7*8, table17);				\
+    idct_row (table17, rounder7);					\
+    idct_row_mid (block, 7*8, 2*8, table26);				\
+    idct_row (table26, rounder2);					\
+    idct_row_mid (block, 2*8, 6*8, table26);				\
+    idct_row (table26, rounder6);					\
+    idct_row_mid (block, 6*8, 3*8, table35);				\
+    idct_row (table35, rounder3);					\
+    idct_row_mid (block, 3*8, 5*8, table35);				\
+    idct_row (table35, rounder5);					\
+    idct_row_tail (block, 5*8);						\
+									\
+    idct_col (block, 0);						\
+    idct_col (block, 4);						\
+}
+
+
+#define COPY_MMX(offset,r0,r1,r2)	\
+do {					\
+    movq_m2r (*(block+offset), r0);	\
+    dest += stride;			\
+    movq_m2r (*(block+offset+4), r1);	\
+    movq_r2m (r2, *dest);		\
+    packuswb_r2r (r1, r0);		\
+} while (0)
+
+static void block_copy (int16_t * block, uint8_t * dest, int stride)
+{
+    movq_m2r (*(block+0*8), mm0);
+    movq_m2r (*(block+0*8+4), mm1);
+    movq_m2r (*(block+1*8), mm2);
+    packuswb_r2r (mm1, mm0);
+    movq_m2r (*(block+1*8+4), mm3);
+    movq_r2m (mm0, *dest);
+    packuswb_r2r (mm3, mm2);
+    COPY_MMX (2*8, mm0, mm1, mm2);
+    COPY_MMX (3*8, mm2, mm3, mm0);
+    COPY_MMX (4*8, mm0, mm1, mm2);
+    COPY_MMX (5*8, mm2, mm3, mm0);
+    COPY_MMX (6*8, mm0, mm1, mm2);
+    COPY_MMX (7*8, mm2, mm3, mm0);
+    movq_r2m (mm2, *(dest+stride));
+}
+
+
+#define ADD_MMX(offset,r1,r2,r3,r4)	\
+do {					\
+    movq_m2r (*(dest+2*stride), r1);	\
+    packuswb_r2r (r4, r3);		\
+    movq_r2r (r1, r2);			\
+    dest += stride;			\
+    movq_r2m (r3, *dest);		\
+    punpcklbw_r2r (mm0, r1);		\
+    paddsw_m2r (*(block+offset), r1);	\
+    punpckhbw_r2r (mm0, r2);		\
+    paddsw_m2r (*(block+offset+4), r2);	\
+} while (0)
+
+static void block_add (int16_t * block, uint8_t * dest, int stride)
+{
+    movq_m2r (*dest, mm1);
+    pxor_r2r (mm0, mm0);
+    movq_m2r (*(dest+stride), mm3);
+    movq_r2r (mm1, mm2);
+    punpcklbw_r2r (mm0, mm1);
+    movq_r2r (mm3, mm4);
+    paddsw_m2r (*(block+0*8), mm1);
+    punpckhbw_r2r (mm0, mm2);
+    paddsw_m2r (*(block+0*8+4), mm2);
+    punpcklbw_r2r (mm0, mm3);
+    paddsw_m2r (*(block+1*8), mm3);
+    packuswb_r2r (mm2, mm1);
+    punpckhbw_r2r (mm0, mm4);
+    movq_r2m (mm1, *dest);
+    paddsw_m2r (*(block+1*8+4), mm4);
+    ADD_MMX (2*8, mm1, mm2, mm3, mm4);
+    ADD_MMX (3*8, mm3, mm4, mm1, mm2);
+    ADD_MMX (4*8, mm1, mm2, mm3, mm4);
+    ADD_MMX (5*8, mm3, mm4, mm1, mm2);
+    ADD_MMX (6*8, mm1, mm2, mm3, mm4);
+    ADD_MMX (7*8, mm3, mm4, mm1, mm2);
+    packuswb_r2r (mm4, mm3);
+    movq_r2m (mm3, *(dest+stride));
+}
+
+
+declare_idct (mmxext_idct, mmxext_table,
+	      mmxext_row_head, mmxext_row, mmxext_row_tail, mmxext_row_mid)
+
+void idct_block_copy_mmxext (int16_t * block, uint8_t * dest, int stride)
+{
+    mmxext_idct (block);
+    block_copy (block, dest, stride);
+}
+
+void idct_block_add_mmxext (int16_t * block, uint8_t * dest, int stride)
+{
+    mmxext_idct (block);
+    block_add (block, dest, stride);
+}
+
+
+declare_idct (mmx_idct, mmx_table,
+	      mmx_row_head, mmx_row, mmx_row_tail, mmx_row_mid)
+
+void idct_block_copy_mmx (int16_t * block, uint8_t * dest, int stride)
+{
+    mmx_idct (block);
+    block_copy (block, dest, stride);
+}
+
+void idct_block_add_mmx (int16_t * block, uint8_t * dest, int stride)
+{
+    mmx_idct (block);
+    block_add (block, dest, stride);
+}
+
+
+void idct_mmx_init (void)
+{
+    extern uint8_t scan_norm[64];
+    extern uint8_t scan_alt[64];
+    int i, j;
+
+    // the mmx/mmxext idct uses a reordered input, so we patch scan tables
+
+    for (i = 0; i < 64; i++) {
+	j = scan_norm[i];
+	scan_norm[i] = (j & 0x38) | ((j & 6) >> 1) | ((j & 1) << 2);
+	j = scan_alt[i];
+	scan_alt[i] = (j & 0x38) | ((j & 6) >> 1) | ((j & 1) << 2);
+    }
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/mm_accel.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,30 @@
+/*
+ * oms_accel.h
+ * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *
+ * mpeg2dec 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.
+ *
+ * mpeg2dec 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// generic accelerations
+#define MM_ACCEL_MLIB		0x00000001
+
+// x86 accelerations
+#define MM_ACCEL_X86_MMX	0x80000000
+#define MM_ACCEL_X86_3DNOW	0x40000000
+#define MM_ACCEL_X86_MMXEXT	0x20000000
+
+//uint32_t mm_accel (void);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/mmx.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,255 @@
+/*
+ * mmx.h
+ * Copyright (C) 1997-1999 H. Dietz and R. Fisher
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *
+ * mpeg2dec 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.
+ *
+ * mpeg2dec 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ * The type of an value that fits in an MMX register (note that long
+ * long constant values MUST be suffixed by LL and unsigned long long
+ * values by ULL, lest they be truncated by the compiler)
+ */
+
+typedef	union {
+	long long		q;	/* Quadword (64-bit) value */
+	unsigned long long	uq;	/* Unsigned Quadword */
+	int			d[2];	/* 2 Doubleword (32-bit) values */
+	unsigned int		ud[2];	/* 2 Unsigned Doubleword */
+	short			w[4];	/* 4 Word (16-bit) values */
+	unsigned short		uw[4];	/* 4 Unsigned Word */
+	char			b[8];	/* 8 Byte (8-bit) values */
+	unsigned char		ub[8];	/* 8 Unsigned Byte */
+	float			s[2];	/* Single-precision (32-bit) value */
+} ATTR_ALIGN(8) mmx_t;	/* On an 8-byte (64-bit) boundary */
+
+
+#define	mmx_i2r(op,imm,reg) \
+	__asm__ __volatile__ (#op " %0, %%" #reg \
+			      : /* nothing */ \
+			      : "X" (imm) )
+
+#define	mmx_m2r(op,mem,reg) \
+	__asm__ __volatile__ (#op " %0, %%" #reg \
+			      : /* nothing */ \
+			      : "X" (mem))
+
+#define	mmx_r2m(op,reg,mem) \
+	__asm__ __volatile__ (#op " %%" #reg ", %0" \
+			      : "=X" (mem) \
+			      : /* nothing */ )
+
+#define	mmx_r2r(op,regs,regd) \
+	__asm__ __volatile__ (#op " %" #regs ", %" #regd)
+
+
+#define	emms() __asm__ __volatile__ ("emms")
+
+#define	movd_m2r(var,reg)	mmx_m2r (movd, var, reg)
+#define	movd_r2m(reg,var)	mmx_r2m (movd, reg, var)
+#define	movd_r2r(regs,regd)	mmx_r2r (movd, regs, regd)
+
+#define	movq_m2r(var,reg)	mmx_m2r (movq, var, reg)
+#define	movq_r2m(reg,var)	mmx_r2m (movq, reg, var)
+#define	movq_r2r(regs,regd)	mmx_r2r (movq, regs, regd)
+
+#define	packssdw_m2r(var,reg)	mmx_m2r (packssdw, var, reg)
+#define	packssdw_r2r(regs,regd) mmx_r2r (packssdw, regs, regd)
+#define	packsswb_m2r(var,reg)	mmx_m2r (packsswb, var, reg)
+#define	packsswb_r2r(regs,regd) mmx_r2r (packsswb, regs, regd)
+
+#define	packuswb_m2r(var,reg)	mmx_m2r (packuswb, var, reg)
+#define	packuswb_r2r(regs,regd) mmx_r2r (packuswb, regs, regd)
+
+#define	paddb_m2r(var,reg)	mmx_m2r (paddb, var, reg)
+#define	paddb_r2r(regs,regd)	mmx_r2r (paddb, regs, regd)
+#define	paddd_m2r(var,reg)	mmx_m2r (paddd, var, reg)
+#define	paddd_r2r(regs,regd)	mmx_r2r (paddd, regs, regd)
+#define	paddw_m2r(var,reg)	mmx_m2r (paddw, var, reg)
+#define	paddw_r2r(regs,regd)	mmx_r2r (paddw, regs, regd)
+
+#define	paddsb_m2r(var,reg)	mmx_m2r (paddsb, var, reg)
+#define	paddsb_r2r(regs,regd)	mmx_r2r (paddsb, regs, regd)
+#define	paddsw_m2r(var,reg)	mmx_m2r (paddsw, var, reg)
+#define	paddsw_r2r(regs,regd)	mmx_r2r (paddsw, regs, regd)
+
+#define	paddusb_m2r(var,reg)	mmx_m2r (paddusb, var, reg)
+#define	paddusb_r2r(regs,regd)	mmx_r2r (paddusb, regs, regd)
+#define	paddusw_m2r(var,reg)	mmx_m2r (paddusw, var, reg)
+#define	paddusw_r2r(regs,regd)	mmx_r2r (paddusw, regs, regd)
+
+#define	pand_m2r(var,reg)	mmx_m2r (pand, var, reg)
+#define	pand_r2r(regs,regd)	mmx_r2r (pand, regs, regd)
+
+#define	pandn_m2r(var,reg)	mmx_m2r (pandn, var, reg)
+#define	pandn_r2r(regs,regd)	mmx_r2r (pandn, regs, regd)
+
+#define	pcmpeqb_m2r(var,reg)	mmx_m2r (pcmpeqb, var, reg)
+#define	pcmpeqb_r2r(regs,regd)	mmx_r2r (pcmpeqb, regs, regd)
+#define	pcmpeqd_m2r(var,reg)	mmx_m2r (pcmpeqd, var, reg)
+#define	pcmpeqd_r2r(regs,regd)	mmx_r2r (pcmpeqd, regs, regd)
+#define	pcmpeqw_m2r(var,reg)	mmx_m2r (pcmpeqw, var, reg)
+#define	pcmpeqw_r2r(regs,regd)	mmx_r2r (pcmpeqw, regs, regd)
+
+#define	pcmpgtb_m2r(var,reg)	mmx_m2r (pcmpgtb, var, reg)
+#define	pcmpgtb_r2r(regs,regd)	mmx_r2r (pcmpgtb, regs, regd)
+#define	pcmpgtd_m2r(var,reg)	mmx_m2r (pcmpgtd, var, reg)
+#define	pcmpgtd_r2r(regs,regd)	mmx_r2r (pcmpgtd, regs, regd)
+#define	pcmpgtw_m2r(var,reg)	mmx_m2r (pcmpgtw, var, reg)
+#define	pcmpgtw_r2r(regs,regd)	mmx_r2r (pcmpgtw, regs, regd)
+
+#define	pmaddwd_m2r(var,reg)	mmx_m2r (pmaddwd, var, reg)
+#define	pmaddwd_r2r(regs,regd)	mmx_r2r (pmaddwd, regs, regd)
+
+#define	pmulhw_m2r(var,reg)	mmx_m2r (pmulhw, var, reg)
+#define	pmulhw_r2r(regs,regd)	mmx_r2r (pmulhw, regs, regd)
+
+#define	pmullw_m2r(var,reg)	mmx_m2r (pmullw, var, reg)
+#define	pmullw_r2r(regs,regd)	mmx_r2r (pmullw, regs, regd)
+
+#define	por_m2r(var,reg)	mmx_m2r (por, var, reg)
+#define	por_r2r(regs,regd)	mmx_r2r (por, regs, regd)
+
+#define	pslld_i2r(imm,reg)	mmx_i2r (pslld, imm, reg)
+#define	pslld_m2r(var,reg)	mmx_m2r (pslld, var, reg)
+#define	pslld_r2r(regs,regd)	mmx_r2r (pslld, regs, regd)
+#define	psllq_i2r(imm,reg)	mmx_i2r (psllq, imm, reg)
+#define	psllq_m2r(var,reg)	mmx_m2r (psllq, var, reg)
+#define	psllq_r2r(regs,regd)	mmx_r2r (psllq, regs, regd)
+#define	psllw_i2r(imm,reg)	mmx_i2r (psllw, imm, reg)
+#define	psllw_m2r(var,reg)	mmx_m2r (psllw, var, reg)
+#define	psllw_r2r(regs,regd)	mmx_r2r (psllw, regs, regd)
+
+#define	psrad_i2r(imm,reg)	mmx_i2r (psrad, imm, reg)
+#define	psrad_m2r(var,reg)	mmx_m2r (psrad, var, reg)
+#define	psrad_r2r(regs,regd)	mmx_r2r (psrad, regs, regd)
+#define	psraw_i2r(imm,reg)	mmx_i2r (psraw, imm, reg)
+#define	psraw_m2r(var,reg)	mmx_m2r (psraw, var, reg)
+#define	psraw_r2r(regs,regd)	mmx_r2r (psraw, regs, regd)
+
+#define	psrld_i2r(imm,reg)	mmx_i2r (psrld, imm, reg)
+#define	psrld_m2r(var,reg)	mmx_m2r (psrld, var, reg)
+#define	psrld_r2r(regs,regd)	mmx_r2r (psrld, regs, regd)
+#define	psrlq_i2r(imm,reg)	mmx_i2r (psrlq, imm, reg)
+#define	psrlq_m2r(var,reg)	mmx_m2r (psrlq, var, reg)
+#define	psrlq_r2r(regs,regd)	mmx_r2r (psrlq, regs, regd)
+#define	psrlw_i2r(imm,reg)	mmx_i2r (psrlw, imm, reg)
+#define	psrlw_m2r(var,reg)	mmx_m2r (psrlw, var, reg)
+#define	psrlw_r2r(regs,regd)	mmx_r2r (psrlw, regs, regd)
+
+#define	psubb_m2r(var,reg)	mmx_m2r (psubb, var, reg)
+#define	psubb_r2r(regs,regd)	mmx_r2r (psubb, regs, regd)
+#define	psubd_m2r(var,reg)	mmx_m2r (psubd, var, reg)
+#define	psubd_r2r(regs,regd)	mmx_r2r (psubd, regs, regd)
+#define	psubw_m2r(var,reg)	mmx_m2r (psubw, var, reg)
+#define	psubw_r2r(regs,regd)	mmx_r2r (psubw, regs, regd)
+
+#define	psubsb_m2r(var,reg)	mmx_m2r (psubsb, var, reg)
+#define	psubsb_r2r(regs,regd)	mmx_r2r (psubsb, regs, regd)
+#define	psubsw_m2r(var,reg)	mmx_m2r (psubsw, var, reg)
+#define	psubsw_r2r(regs,regd)	mmx_r2r (psubsw, regs, regd)
+
+#define	psubusb_m2r(var,reg)	mmx_m2r (psubusb, var, reg)
+#define	psubusb_r2r(regs,regd)	mmx_r2r (psubusb, regs, regd)
+#define	psubusw_m2r(var,reg)	mmx_m2r (psubusw, var, reg)
+#define	psubusw_r2r(regs,regd)	mmx_r2r (psubusw, regs, regd)
+
+#define	punpckhbw_m2r(var,reg)		mmx_m2r (punpckhbw, var, reg)
+#define	punpckhbw_r2r(regs,regd)	mmx_r2r (punpckhbw, regs, regd)
+#define	punpckhdq_m2r(var,reg)		mmx_m2r (punpckhdq, var, reg)
+#define	punpckhdq_r2r(regs,regd)	mmx_r2r (punpckhdq, regs, regd)
+#define	punpckhwd_m2r(var,reg)		mmx_m2r (punpckhwd, var, reg)
+#define	punpckhwd_r2r(regs,regd)	mmx_r2r (punpckhwd, regs, regd)
+
+#define	punpcklbw_m2r(var,reg) 		mmx_m2r (punpcklbw, var, reg)
+#define	punpcklbw_r2r(regs,regd)	mmx_r2r (punpcklbw, regs, regd)
+#define	punpckldq_m2r(var,reg)		mmx_m2r (punpckldq, var, reg)
+#define	punpckldq_r2r(regs,regd)	mmx_r2r (punpckldq, regs, regd)
+#define	punpcklwd_m2r(var,reg)		mmx_m2r (punpcklwd, var, reg)
+#define	punpcklwd_r2r(regs,regd)	mmx_r2r (punpcklwd, regs, regd)
+
+#define	pxor_m2r(var,reg)	mmx_m2r (pxor, var, reg)
+#define	pxor_r2r(regs,regd)	mmx_r2r (pxor, regs, regd)
+
+
+/* 3DNOW extensions */
+
+#define pavgusb_m2r(var,reg)	mmx_m2r (pavgusb, var, reg)
+#define pavgusb_r2r(regs,regd)	mmx_r2r (pavgusb, regs, regd)
+
+
+/* AMD MMX extensions - also available in intel SSE */
+
+
+#define mmx_m2ri(op,mem,reg,imm) \
+        __asm__ __volatile__ (#op " %1, %0, %%" #reg \
+                              : /* nothing */ \
+                              : "X" (mem), "X" (imm))
+#define mmx_r2ri(op,regs,regd,imm) \
+        __asm__ __volatile__ (#op " %0, %%" #regs ", %%" #regd \
+                              : /* nothing */ \
+                              : "X" (imm) )
+
+#define	mmx_fetch(mem,hint) \
+	__asm__ __volatile__ ("prefetch" #hint " %0" \
+			      : /* nothing */ \
+			      : "X" (mem))
+
+
+#define	maskmovq(regs,maskreg)		mmx_r2ri (maskmovq, regs, maskreg)
+
+#define	movntq_r2m(mmreg,var)		mmx_r2m (movntq, mmreg, var)
+
+#define	pavgb_m2r(var,reg)		mmx_m2r (pavgb, var, reg)
+#define	pavgb_r2r(regs,regd)		mmx_r2r (pavgb, regs, regd)
+#define	pavgw_m2r(var,reg)		mmx_m2r (pavgw, var, reg)
+#define	pavgw_r2r(regs,regd)		mmx_r2r (pavgw, regs, regd)
+
+#define	pextrw_r2r(mmreg,reg,imm)	mmx_r2ri (pextrw, mmreg, reg, imm)
+
+#define	pinsrw_r2r(reg,mmreg,imm)	mmx_r2ri (pinsrw, reg, mmreg, imm)
+
+#define	pmaxsw_m2r(var,reg)		mmx_m2r (pmaxsw, var, reg)
+#define	pmaxsw_r2r(regs,regd)		mmx_r2r (pmaxsw, regs, regd)
+
+#define	pmaxub_m2r(var,reg)		mmx_m2r (pmaxub, var, reg)
+#define	pmaxub_r2r(regs,regd)		mmx_r2r (pmaxub, regs, regd)
+
+#define	pminsw_m2r(var,reg)		mmx_m2r (pminsw, var, reg)
+#define	pminsw_r2r(regs,regd)		mmx_r2r (pminsw, regs, regd)
+
+#define	pminub_m2r(var,reg)		mmx_m2r (pminub, var, reg)
+#define	pminub_r2r(regs,regd)		mmx_r2r (pminub, regs, regd)
+
+#define	pmovmskb(mmreg,reg) \
+	__asm__ __volatile__ ("movmskps %" #mmreg ", %" #reg)
+
+#define	pmulhuw_m2r(var,reg)		mmx_m2r (pmulhuw, var, reg)
+#define	pmulhuw_r2r(regs,regd)		mmx_r2r (pmulhuw, regs, regd)
+
+#define	prefetcht0(mem)			mmx_fetch (mem, t0)
+#define	prefetcht1(mem)			mmx_fetch (mem, t1)
+#define	prefetcht2(mem)			mmx_fetch (mem, t2)
+#define	prefetchnta(mem)		mmx_fetch (mem, nta)
+
+#define	psadbw_m2r(var,reg)		mmx_m2r (psadbw, var, reg)
+#define	psadbw_r2r(regs,regd)		mmx_r2r (psadbw, regs, regd)
+
+#define	pshufw_m2r(var,reg,imm)		mmx_m2ri(pshufw, var, reg, imm)
+#define	pshufw_r2r(regs,regd,imm)	mmx_r2ri(pshufw, regs, regd, imm)
+
+#define	sfence() __asm__ __volatile__ ("sfence\n\t")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/motion_comp.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,125 @@
+/*
+ * motion_comp.c
+ * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *
+ * mpeg2dec 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.
+ *
+ * mpeg2dec 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <inttypes.h>
+
+#include "mpeg2_internal.h"
+#include "mm_accel.h"
+
+mc_functions_t mc_functions;
+
+void motion_comp_init (void)
+{
+
+#ifdef ARCH_X86
+    if (config.flags & MM_ACCEL_X86_MMXEXT) {
+	fprintf (stderr, "Using MMXEXT for motion compensation\n");
+	mc_functions = mc_functions_mmxext;
+    } else if (config.flags & MM_ACCEL_X86_3DNOW) {
+	fprintf (stderr, "Using 3DNOW for motion compensation\n");
+	mc_functions = mc_functions_3dnow;
+    } else if (config.flags & MM_ACCEL_X86_MMX) {
+	fprintf (stderr, "Using MMX for motion compensation\n");
+	mc_functions = mc_functions_mmx;
+    } else
+#endif
+#ifdef LIBMPEG2_MLIB
+    if (config.flags & MM_ACCEL_MLIB) {
+	fprintf (stderr, "Using mlib for motion compensation\n");
+	mc_functions = mc_functions_mlib;
+    } else
+#endif
+    {
+	fprintf (stderr, "No accelerated motion compensation found\n");
+	mc_functions = mc_functions_c;
+    }
+}
+
+#define avg2(a,b) ((a+b+1)>>1)
+#define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
+
+#define predict_(i) (ref[i])
+#define predict_x(i) (avg2 (ref[i], ref[i+1]))
+#define predict_y(i) (avg2 (ref[i], (ref+stride)[i]))
+#define predict_xy(i) (avg4 (ref[i], ref[i+1], (ref+stride)[i], (ref+stride)[i+1]))
+
+#define put(predictor,i) dest[i] = predictor (i)
+#define avg(predictor,i) dest[i] = avg2 (predictor (i), dest[i])
+
+// mc function template
+
+#define MC_FUNC(op,xy)						\
+static void MC_##op##_##xy##16_c (uint8_t * dest, uint8_t * ref,\
+				 int stride, int height)	\
+{								\
+    do {							\
+	op (predict_##xy, 0);					\
+	op (predict_##xy, 1);					\
+	op (predict_##xy, 2);					\
+	op (predict_##xy, 3);					\
+	op (predict_##xy, 4);					\
+	op (predict_##xy, 5);					\
+	op (predict_##xy, 6);					\
+	op (predict_##xy, 7);					\
+	op (predict_##xy, 8);					\
+	op (predict_##xy, 9);					\
+	op (predict_##xy, 10);					\
+	op (predict_##xy, 11);					\
+	op (predict_##xy, 12);					\
+	op (predict_##xy, 13);					\
+	op (predict_##xy, 14);					\
+	op (predict_##xy, 15);					\
+	ref += stride;						\
+	dest += stride;						\
+    } while (--height);						\
+}								\
+static void MC_##op##_##xy##8_c (uint8_t * dest, uint8_t * ref,	\
+				int stride, int height)		\
+{								\
+    do {							\
+	op (predict_##xy, 0);					\
+	op (predict_##xy, 1);					\
+	op (predict_##xy, 2);					\
+	op (predict_##xy, 3);					\
+	op (predict_##xy, 4);					\
+	op (predict_##xy, 5);					\
+	op (predict_##xy, 6);					\
+	op (predict_##xy, 7);					\
+	ref += stride;						\
+	dest += stride;						\
+    } while (--height);						\
+}
+
+// definitions of the actual mc functions
+
+MC_FUNC (put,)
+MC_FUNC (avg,)
+MC_FUNC (put,x)
+MC_FUNC (avg,x)
+MC_FUNC (put,y)
+MC_FUNC (avg,y)
+MC_FUNC (put,xy)
+MC_FUNC (avg,xy)
+
+MOTION_COMP_EXTERN (c)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/motion_comp_mlib.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,180 @@
+/*
+ * MC_mlib.c
+ * Copyright (C) 2000 Håkan Hjort <d95hjort@dtek.chalmers.se>
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *
+ * mpeg2dec 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.
+ *
+ * mpeg2dec 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "config.h"
+
+#ifdef LIBMPEG2_MLIB
+
+#include <inttypes.h>
+#include <mlib_types.h>
+#include <mlib_status.h>
+#include <mlib_sys.h>
+#include <mlib_video.h>
+
+#include "mpeg2_internal.h"
+
+static void MC_put_16_mlib (uint8_t * dest, uint8_t * ref,
+			    int stride, int height)
+{
+    if (height == 16) 
+	mlib_VideoCopyRef_U8_U8_16x16 (dest, ref, stride);
+    else
+	mlib_VideoCopyRef_U8_U8_16x8 (dest, ref, stride);
+}
+
+static void MC_put_x16_mlib (uint8_t * dest, uint8_t * ref,
+			     int stride, int height)
+{
+    if (height == 16)
+	mlib_VideoInterpX_U8_U8_16x16 (dest, ref, stride, stride);
+    else
+	mlib_VideoInterpX_U8_U8_16x8 (dest, ref, stride, stride);
+}
+
+static void MC_put_y16_mlib (uint8_t * dest, uint8_t * ref,
+			     int stride, int height)
+{
+    if (height == 16)
+	mlib_VideoInterpY_U8_U8_16x16 (dest, ref, stride, stride);
+    else
+	mlib_VideoInterpY_U8_U8_16x8 (dest, ref, stride, stride);
+}
+
+static void MC_put_xy16_mlib (uint8_t * dest, uint8_t * ref,
+			      int stride, int height)
+{
+    if (height == 16)
+	mlib_VideoInterpXY_U8_U8_16x16 (dest, ref, stride, stride);
+    else
+	mlib_VideoInterpXY_U8_U8_16x8 (dest, ref, stride, stride);
+}
+
+static void MC_put_8_mlib (uint8_t * dest, uint8_t * ref,
+			   int stride, int height)
+{
+    if (height == 8)
+	mlib_VideoCopyRef_U8_U8_8x8 (dest, ref, stride);
+    else
+	mlib_VideoCopyRef_U8_U8_8x4 (dest, ref, stride);
+}
+
+static void MC_put_x8_mlib (uint8_t * dest, uint8_t * ref,
+			    int stride, int height)
+{
+    if (height == 8)
+	mlib_VideoInterpX_U8_U8_8x8 (dest, ref, stride, stride);
+    else
+	mlib_VideoInterpX_U8_U8_8x4 (dest, ref, stride, stride);
+}
+
+static void MC_put_y8_mlib (uint8_t * dest, uint8_t * ref,
+			    int stride, int height)
+{
+    if (height == 8)
+	mlib_VideoInterpY_U8_U8_8x8 (dest, ref, stride, stride);
+    else
+	mlib_VideoInterpY_U8_U8_8x4 (dest, ref, stride, stride);
+}
+
+static void MC_put_xy8_mlib (uint8_t * dest, uint8_t * ref,
+			     int stride, int height)
+{
+    if (height == 8) 
+	mlib_VideoInterpXY_U8_U8_8x8 (dest, ref, stride, stride);
+    else
+	mlib_VideoInterpXY_U8_U8_8x4 (dest, ref, stride, stride);
+}
+
+static void MC_avg_16_mlib (uint8_t * dest, uint8_t * ref,
+			    int stride, int height)
+{
+    if (height == 16)
+	mlib_VideoCopyRefAve_U8_U8_16x16 (dest, ref, stride);
+    else
+	mlib_VideoCopyRefAve_U8_U8_16x8 (dest, ref, stride);
+}
+
+static void MC_avg_x16_mlib (uint8_t * dest, uint8_t * ref,
+			     int stride, int height)
+{
+    if (height == 16)
+	mlib_VideoInterpAveX_U8_U8_16x16 (dest, ref, stride, stride);
+    else
+	mlib_VideoInterpAveX_U8_U8_16x8 (dest, ref, stride, stride);
+}
+
+static void MC_avg_y16_mlib (uint8_t * dest, uint8_t * ref,
+			     int stride, int height)
+{
+    if (height == 16)
+	mlib_VideoInterpAveY_U8_U8_16x16 (dest, ref, stride, stride);
+    else
+	mlib_VideoInterpAveY_U8_U8_16x8 (dest, ref, stride, stride);
+}
+
+static void MC_avg_xy16_mlib (uint8_t * dest, uint8_t * ref,
+			      int stride, int height)
+{
+    if (height == 16)
+	mlib_VideoInterpAveXY_U8_U8_16x16 (dest, ref, stride, stride);
+    else
+	mlib_VideoInterpAveXY_U8_U8_16x8 (dest, ref, stride, stride);
+}
+
+static void MC_avg_8_mlib (uint8_t * dest, uint8_t * ref,
+			   int stride, int height)
+{
+    if (height == 8)
+	mlib_VideoCopyRefAve_U8_U8_8x8 (dest, ref, stride);
+    else
+	mlib_VideoCopyRefAve_U8_U8_8x4 (dest, ref, stride);
+}
+
+static void MC_avg_x8_mlib (uint8_t * dest, uint8_t * ref,
+			    int stride, int height)
+{
+    if (height == 8)
+	mlib_VideoInterpAveX_U8_U8_8x8 (dest, ref, stride, stride);
+    else
+	mlib_VideoInterpAveX_U8_U8_8x4 (dest, ref, stride, stride);
+}
+
+static void MC_avg_y8_mlib (uint8_t * dest, uint8_t * ref,
+			    int stride, int height)
+{
+    if (height == 8)
+	mlib_VideoInterpAveY_U8_U8_8x8 (dest, ref, stride, stride);
+    else
+	mlib_VideoInterpAveY_U8_U8_8x4 (dest, ref, stride, stride);
+}
+
+static void MC_avg_xy8_mlib (uint8_t * dest, uint8_t * ref,
+			     int stride, int height)
+{
+    if (height == 8)
+	mlib_VideoInterpAveXY_U8_U8_8x8 (dest, ref, stride, stride);
+    else
+	mlib_VideoInterpAveXY_U8_U8_8x4 (dest, ref, stride, stride);
+}
+
+MOTION_COMP_EXTERN (mlib)
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/motion_comp_mmx.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,1025 @@
+/*
+ * motion_comp_mmx.c
+ * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *
+ * mpeg2dec 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.
+ *
+ * mpeg2dec 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "config.h"
+
+#ifdef ARCH_X86
+
+#include <inttypes.h>
+
+#include "mpeg2_internal.h"
+#include "attributes.h"
+#include "mmx.h"
+
+#define CPU_MMXEXT 0
+#define CPU_3DNOW 1
+
+
+//MMX code - needs a rewrite
+
+
+
+
+
+
+
+// some rounding constants
+mmx_t round1 = {0x0001000100010001LL};
+mmx_t round4 = {0x0002000200020002LL};
+
+/*
+ * This code should probably be compiled with loop unrolling
+ * (ie, -funroll-loops in gcc)becuase some of the loops
+ * use a small static number of iterations. This was written
+ * with the assumption the compiler knows best about when
+ * unrolling will help
+ */
+
+static inline void mmx_zero_reg ()
+{
+    // load 0 into mm0
+    pxor_r2r (mm0, mm0);
+}
+
+static inline void mmx_average_2_U8 (uint8_t * dest,
+				     uint8_t * src1, uint8_t * src2)
+{
+    //
+    // *dest = (*src1 + *src2 + 1)/ 2;
+    //
+
+    movq_m2r (*src1, mm1);	// load 8 src1 bytes
+    movq_r2r (mm1, mm2);	// copy 8 src1 bytes
+
+    movq_m2r (*src2, mm3);	// load 8 src2 bytes
+    movq_r2r (mm3, mm4);	// copy 8 src2 bytes
+
+    punpcklbw_r2r (mm0, mm1);	// unpack low src1 bytes
+    punpckhbw_r2r (mm0, mm2);	// unpack high src1 bytes
+
+    punpcklbw_r2r (mm0, mm3);	// unpack low src2 bytes
+    punpckhbw_r2r (mm0, mm4);	// unpack high src2 bytes
+
+    paddw_r2r (mm3, mm1);	// add lows to mm1
+    paddw_m2r (round1, mm1);
+    psraw_i2r (1, mm1);		// /2
+
+    paddw_r2r (mm4, mm2);	// add highs to mm2
+    paddw_m2r (round1, mm2);
+    psraw_i2r (1, mm2);		// /2
+
+    packuswb_r2r (mm2, mm1);	// pack (w/ saturation)
+    movq_r2m (mm1, *dest);	// store result in dest
+}
+
+static inline void mmx_interp_average_2_U8 (uint8_t * dest,
+					    uint8_t * src1, uint8_t * src2)
+{
+    //
+    // *dest = (*dest + (*src1 + *src2 + 1)/ 2 + 1)/ 2;
+    //
+
+    movq_m2r (*dest, mm1);	// load 8 dest bytes
+    movq_r2r (mm1, mm2);	// copy 8 dest bytes
+
+    movq_m2r (*src1, mm3);	// load 8 src1 bytes
+    movq_r2r (mm3, mm4);	// copy 8 src1 bytes
+
+    movq_m2r (*src2, mm5);	// load 8 src2 bytes
+    movq_r2r (mm5, mm6);	// copy 8 src2 bytes
+
+    punpcklbw_r2r (mm0, mm1);	// unpack low dest bytes
+    punpckhbw_r2r (mm0, mm2);	// unpack high dest bytes
+
+    punpcklbw_r2r (mm0, mm3);	// unpack low src1 bytes
+    punpckhbw_r2r (mm0, mm4);	// unpack high src1 bytes
+
+    punpcklbw_r2r (mm0, mm5);	// unpack low src2 bytes
+    punpckhbw_r2r (mm0, mm6);	// unpack high src2 bytes
+
+    paddw_r2r (mm5, mm3);	// add lows
+    paddw_m2r (round1, mm3);
+    psraw_i2r (1, mm3);		// /2
+
+    paddw_r2r (mm6, mm4);	// add highs
+    paddw_m2r (round1, mm4);
+    psraw_i2r (1, mm4);		// /2
+
+    paddw_r2r (mm3, mm1);	// add lows
+    paddw_m2r (round1, mm1);
+    psraw_i2r (1, mm1);		// /2
+
+    paddw_r2r (mm4, mm2);	// add highs
+    paddw_m2r (round1, mm2);
+    psraw_i2r (1, mm2);		// /2
+
+    packuswb_r2r (mm2, mm1);	// pack (w/ saturation)
+    movq_r2m (mm1, *dest);	// store result in dest
+}
+
+static inline void mmx_average_4_U8 (uint8_t * dest,
+				     uint8_t * src1, uint8_t * src2,
+				     uint8_t * src3, uint8_t * src4)
+{
+    //
+    // *dest = (*src1 + *src2 + *src3 + *src4 + 2)/ 4;
+    //
+
+    movq_m2r (*src1, mm1);	// load 8 src1 bytes
+    movq_r2r (mm1, mm2);	// copy 8 src1 bytes
+
+    punpcklbw_r2r (mm0, mm1);	// unpack low src1 bytes
+    punpckhbw_r2r (mm0, mm2);	// unpack high src1 bytes
+
+    movq_m2r (*src2, mm3);	// load 8 src2 bytes
+    movq_r2r (mm3, mm4);	// copy 8 src2 bytes
+
+    punpcklbw_r2r (mm0, mm3);	// unpack low src2 bytes
+    punpckhbw_r2r (mm0, mm4);	// unpack high src2 bytes
+
+    paddw_r2r (mm3, mm1);	// add lows
+    paddw_r2r (mm4, mm2);	// add highs
+
+    // now have partials in mm1 and mm2
+
+    movq_m2r (*src3, mm3);	// load 8 src3 bytes
+    movq_r2r (mm3, mm4);	// copy 8 src3 bytes
+
+    punpcklbw_r2r (mm0, mm3);	// unpack low src3 bytes
+    punpckhbw_r2r (mm0, mm4);	// unpack high src3 bytes
+
+    paddw_r2r (mm3, mm1);	// add lows
+    paddw_r2r (mm4, mm2);	// add highs
+
+    movq_m2r (*src4, mm5);	// load 8 src4 bytes
+    movq_r2r (mm5, mm6);	// copy 8 src4 bytes
+
+    punpcklbw_r2r (mm0, mm5);	// unpack low src4 bytes
+    punpckhbw_r2r (mm0, mm6);	// unpack high src4 bytes
+
+    paddw_r2r (mm5, mm1);	// add lows
+    paddw_r2r (mm6, mm2);	// add highs
+
+    // now have subtotal in mm1 and mm2
+
+    paddw_m2r (round4, mm1);
+    psraw_i2r (2, mm1);		// /4
+    paddw_m2r (round4, mm2);
+    psraw_i2r (2, mm2);		// /4
+
+    packuswb_r2r (mm2, mm1);	// pack (w/ saturation)
+    movq_r2m (mm1, *dest);	// store result in dest
+}
+
+static inline void mmx_interp_average_4_U8 (uint8_t * dest,
+					    uint8_t * src1, uint8_t * src2,
+					    uint8_t * src3, uint8_t * src4)
+{
+    //
+    // *dest = (*dest + (*src1 + *src2 + *src3 + *src4 + 2)/ 4 + 1)/ 2;
+    //
+
+    movq_m2r (*src1, mm1);	// load 8 src1 bytes
+    movq_r2r (mm1, mm2);	// copy 8 src1 bytes
+
+    punpcklbw_r2r (mm0, mm1);	// unpack low src1 bytes
+    punpckhbw_r2r (mm0, mm2);	// unpack high src1 bytes
+
+    movq_m2r (*src2, mm3);	// load 8 src2 bytes
+    movq_r2r (mm3, mm4);	// copy 8 src2 bytes
+
+    punpcklbw_r2r (mm0, mm3);	// unpack low src2 bytes
+    punpckhbw_r2r (mm0, mm4);	// unpack high src2 bytes
+
+    paddw_r2r (mm3, mm1);	// add lows
+    paddw_r2r (mm4, mm2);	// add highs
+
+    // now have partials in mm1 and mm2
+
+    movq_m2r (*src3, mm3);	// load 8 src3 bytes
+    movq_r2r (mm3, mm4);	// copy 8 src3 bytes
+
+    punpcklbw_r2r (mm0, mm3);	// unpack low src3 bytes
+    punpckhbw_r2r (mm0, mm4);	// unpack high src3 bytes
+
+    paddw_r2r (mm3, mm1);	// add lows
+    paddw_r2r (mm4, mm2);	// add highs
+
+    movq_m2r (*src4, mm5);	// load 8 src4 bytes
+    movq_r2r (mm5, mm6);	// copy 8 src4 bytes
+
+    punpcklbw_r2r (mm0, mm5);	// unpack low src4 bytes
+    punpckhbw_r2r (mm0, mm6);	// unpack high src4 bytes
+
+    paddw_r2r (mm5, mm1);	// add lows
+    paddw_r2r (mm6, mm2);	// add highs
+
+    paddw_m2r (round4, mm1);
+    psraw_i2r (2, mm1);		// /4
+    paddw_m2r (round4, mm2);
+    psraw_i2r (2, mm2);		// /4
+
+    // now have subtotal/4 in mm1 and mm2
+
+    movq_m2r (*dest, mm3);	// load 8 dest bytes
+    movq_r2r (mm3, mm4);	// copy 8 dest bytes
+
+    punpcklbw_r2r (mm0, mm3);	// unpack low dest bytes
+    punpckhbw_r2r (mm0, mm4);	// unpack high dest bytes
+
+    paddw_r2r (mm3, mm1);	// add lows
+    paddw_r2r (mm4, mm2);	// add highs
+
+    paddw_m2r (round1, mm1);
+    psraw_i2r (1, mm1);		// /2
+    paddw_m2r (round1, mm2);
+    psraw_i2r (1, mm2);		// /2
+
+    // now have end value in mm1 and mm2
+
+    packuswb_r2r (mm2, mm1);	// pack (w/ saturation)
+    movq_r2m (mm1,*dest);	// store result in dest
+}
+
+//-----------------------------------------------------------------------
+
+static inline void MC_avg_mmx (int width, int height,
+			       uint8_t * dest, uint8_t * ref, int stride)
+{
+    mmx_zero_reg ();
+
+    do {
+	mmx_average_2_U8 (dest, dest, ref);
+
+	if (width == 16)
+	    mmx_average_2_U8 (dest+8, dest+8, ref+8);
+
+	dest += stride;
+	ref += stride;
+    } while (--height);
+}
+
+static void MC_avg_16_mmx (uint8_t * dest, uint8_t * ref,
+			   int stride, int height)
+{
+    MC_avg_mmx (16, height, dest, ref, stride);
+}
+
+static void MC_avg_8_mmx (uint8_t * dest, uint8_t * ref,
+			  int stride, int height)
+{
+    MC_avg_mmx (8, height, dest, ref, stride);
+}
+
+//-----------------------------------------------------------------------
+
+static inline void MC_put_mmx (int width, int height,
+			       uint8_t * dest, uint8_t * ref, int stride)
+{
+    mmx_zero_reg ();
+
+    do {
+	movq_m2r (* ref, mm1);	// load 8 ref bytes
+	movq_r2m (mm1,* dest);	// store 8 bytes at curr
+
+	if (width == 16)
+	    {
+		movq_m2r (* (ref+8), mm1);	// load 8 ref bytes
+		movq_r2m (mm1,* (dest+8));	// store 8 bytes at curr
+	    }
+
+	dest += stride;
+	ref += stride;
+    } while (--height);
+}
+
+static void MC_put_16_mmx (uint8_t * dest, uint8_t * ref,
+			   int stride, int height)
+{
+    MC_put_mmx (16, height, dest, ref, stride);
+}
+
+static void MC_put_8_mmx (uint8_t * dest, uint8_t * ref,
+			  int stride, int height)
+{
+    MC_put_mmx (8, height, dest, ref, stride);
+}
+
+//-----------------------------------------------------------------------
+
+// Half pixel interpolation in the x direction
+static inline void MC_avg_x_mmx (int width, int height,
+				 uint8_t * dest, uint8_t * ref, int stride)
+{
+    mmx_zero_reg ();
+
+    do {
+	mmx_interp_average_2_U8 (dest, ref, ref+1);
+
+	if (width == 16)
+	    mmx_interp_average_2_U8 (dest+8, ref+8, ref+9);
+
+	dest += stride;
+	ref += stride;
+    } while (--height);
+}
+
+static void MC_avg_x16_mmx (uint8_t * dest, uint8_t * ref,
+			    int stride, int height)
+{
+    MC_avg_x_mmx (16, height, dest, ref, stride);
+}
+
+static void MC_avg_x8_mmx (uint8_t * dest, uint8_t * ref,
+			   int stride, int height)
+{
+    MC_avg_x_mmx (8, height, dest, ref, stride);
+}
+
+//-----------------------------------------------------------------------
+
+static inline void MC_put_x_mmx (int width, int height,
+				 uint8_t * dest, uint8_t * ref, int stride)
+{
+    mmx_zero_reg ();
+
+    do {
+	mmx_average_2_U8 (dest, ref, ref+1);
+
+	if (width == 16)
+	    mmx_average_2_U8 (dest+8, ref+8, ref+9);
+
+	dest += stride;
+	ref += stride;
+    } while (--height);
+}
+
+static void MC_put_x16_mmx (uint8_t * dest, uint8_t * ref,
+			    int stride, int height)
+{
+    MC_put_x_mmx (16, height, dest, ref, stride);
+}
+
+static void MC_put_x8_mmx (uint8_t * dest, uint8_t * ref,
+			   int stride, int height)
+{
+    MC_put_x_mmx (8, height, dest, ref, stride);
+}
+
+//-----------------------------------------------------------------------
+
+static inline void MC_avg_xy_mmx (int width, int height,
+				  uint8_t * dest, uint8_t * ref, int stride)
+{
+    uint8_t * ref_next = ref+stride;
+
+    mmx_zero_reg ();
+
+    do {
+	mmx_interp_average_4_U8 (dest, ref, ref+1, ref_next, ref_next+1);
+
+	if (width == 16)
+	    mmx_interp_average_4_U8 (dest+8, ref+8, ref+9,
+				     ref_next+8, ref_next+9);
+
+	dest += stride;
+	ref += stride;
+	ref_next += stride;
+    } while (--height);
+}
+
+static void MC_avg_xy16_mmx (uint8_t * dest, uint8_t * ref,
+			     int stride, int height)
+{
+    MC_avg_xy_mmx (16, height, dest, ref, stride);
+}
+
+static void MC_avg_xy8_mmx (uint8_t * dest, uint8_t * ref,
+			    int stride, int height)
+{
+    MC_avg_xy_mmx (8, height, dest, ref, stride);
+}
+
+//-----------------------------------------------------------------------
+
+static inline void MC_put_xy_mmx (int width, int height,
+				  uint8_t * dest, uint8_t * ref, int stride)
+{
+    uint8_t * ref_next = ref+stride;
+
+    mmx_zero_reg ();
+
+    do {
+	mmx_average_4_U8 (dest, ref, ref+1, ref_next, ref_next+1);
+
+	if (width == 16)
+	    mmx_average_4_U8 (dest+8, ref+8, ref+9, ref_next+8, ref_next+9);
+
+	dest += stride;
+	ref += stride;
+	ref_next += stride;
+    } while (--height);
+}
+
+static void MC_put_xy16_mmx (uint8_t * dest, uint8_t * ref,
+			     int stride, int height)
+{
+    MC_put_xy_mmx (16, height, dest, ref, stride);
+}
+
+static void MC_put_xy8_mmx (uint8_t * dest, uint8_t * ref,
+			    int stride, int height)
+{
+    MC_put_xy_mmx (8, height, dest, ref, stride);
+}
+
+//-----------------------------------------------------------------------
+
+static inline void MC_avg_y_mmx (int width, int height,
+				 uint8_t * dest, uint8_t * ref, int stride)
+{
+    uint8_t * ref_next = ref+stride;
+
+    mmx_zero_reg ();
+
+    do {
+	mmx_interp_average_2_U8 (dest, ref, ref_next);
+
+	if (width == 16)
+	    mmx_interp_average_2_U8 (dest+8, ref+8, ref_next+8);
+
+	dest += stride;
+	ref += stride;
+	ref_next += stride;
+    } while (--height);
+}
+
+static void MC_avg_y16_mmx (uint8_t * dest, uint8_t * ref,
+			    int stride, int height)
+{
+    MC_avg_y_mmx (16, height, dest, ref, stride);
+}
+
+static void MC_avg_y8_mmx (uint8_t * dest, uint8_t * ref,
+			   int stride, int height)
+{
+    MC_avg_y_mmx (8, height, dest, ref, stride);
+}
+
+//-----------------------------------------------------------------------
+
+static inline void MC_put_y_mmx (int width, int height,
+				 uint8_t * dest, uint8_t * ref, int stride)
+{
+    uint8_t * ref_next = ref+stride;
+
+    mmx_zero_reg ();
+
+    do {
+	mmx_average_2_U8 (dest, ref, ref_next);
+
+	if (width == 16)
+	    mmx_average_2_U8 (dest+8, ref+8, ref_next+8);
+
+	dest += stride;
+	ref += stride;
+	ref_next += stride;
+    } while (--height);
+}
+
+static void MC_put_y16_mmx (uint8_t * dest, uint8_t * ref,
+			    int stride, int height)
+{
+    MC_put_y_mmx (16, height, dest, ref, stride);
+}
+
+static void MC_put_y8_mmx (uint8_t * dest, uint8_t * ref,
+			   int stride, int height)
+{
+    MC_put_y_mmx (8, height, dest, ref, stride);
+}
+
+
+MOTION_COMP_EXTERN (mmx)
+
+
+
+
+
+
+
+//CPU_MMXEXT/CPU_3DNOW adaptation layer
+
+#define pavg_r2r(src,dest)		\
+do {					\
+    if (cpu == CPU_MMXEXT)		\
+	pavgb_r2r (src, dest);		\
+    else				\
+	pavgusb_r2r (src, dest);	\
+} while (0)
+
+#define pavg_m2r(src,dest)		\
+do {					\
+    if (cpu == CPU_MMXEXT)		\
+	pavgb_m2r (src, dest);		\
+    else				\
+	pavgusb_m2r (src, dest);	\
+} while (0)
+
+
+//CPU_MMXEXT code
+
+
+static inline void MC_put1_8 (int height, uint8_t * dest, uint8_t * ref,
+			      int stride)
+{
+    do {
+	movq_m2r (*ref, mm0);
+	movq_r2m (mm0, *dest);
+	ref += stride;
+	dest += stride;
+    } while (--height);
+}
+
+static inline void MC_put1_16 (int height, uint8_t * dest, uint8_t * ref,
+			       int stride)
+{
+    do {
+	movq_m2r (*ref, mm0);
+	movq_m2r (*(ref+8), mm1);
+	ref += stride;
+	movq_r2m (mm0, *dest);
+	movq_r2m (mm1, *(dest+8));
+	dest += stride;
+    } while (--height);
+}
+
+static inline void MC_avg1_8 (int height, uint8_t * dest, uint8_t * ref,
+			      int stride, int cpu)
+{
+    do {
+	movq_m2r (*ref, mm0);
+	pavg_m2r (*dest, mm0);
+	ref += stride;
+	movq_r2m (mm0, *dest);
+	dest += stride;
+    } while (--height);
+}
+
+static inline void MC_avg1_16 (int height, uint8_t * dest, uint8_t * ref,
+			       int stride, int cpu)
+{
+    do {
+	movq_m2r (*ref, mm0);
+	movq_m2r (*(ref+8), mm1);
+	pavg_m2r (*dest, mm0);
+	pavg_m2r (*(dest+8), mm1);
+	movq_r2m (mm0, *dest);
+	ref += stride;
+	movq_r2m (mm1, *(dest+8));
+	dest += stride;
+    } while (--height);
+}
+
+static inline void MC_put2_8 (int height, uint8_t * dest, uint8_t * ref,
+			      int stride, int offset, int cpu)
+{
+    do {
+	movq_m2r (*ref, mm0);
+	pavg_m2r (*(ref+offset), mm0);
+	ref += stride;
+	movq_r2m (mm0, *dest);
+	dest += stride;
+    } while (--height);
+}
+
+static inline void MC_put2_16 (int height, uint8_t * dest, uint8_t * ref,
+			       int stride, int offset, int cpu)
+{
+    do {
+	movq_m2r (*ref, mm0);
+	movq_m2r (*(ref+8), mm1);
+	pavg_m2r (*(ref+offset), mm0);
+	pavg_m2r (*(ref+offset+8), mm1);
+	movq_r2m (mm0, *dest);
+	ref += stride;
+	movq_r2m (mm1, *(dest+8));
+	dest += stride;
+    } while (--height);
+}
+
+static inline void MC_avg2_8 (int height, uint8_t * dest, uint8_t * ref,
+			      int stride, int offset, int cpu)
+{
+    do {
+	movq_m2r (*ref, mm0);
+	pavg_m2r (*(ref+offset), mm0);
+	pavg_m2r (*dest, mm0);
+	ref += stride;
+	movq_r2m (mm0, *dest);
+	dest += stride;
+    } while (--height);
+}
+
+static inline void MC_avg2_16 (int height, uint8_t * dest, uint8_t * ref,
+			       int stride, int offset, int cpu)
+{
+    do {
+	movq_m2r (*ref, mm0);
+	movq_m2r (*(ref+8), mm1);
+	pavg_m2r (*(ref+offset), mm0);
+	pavg_m2r (*(ref+offset+8), mm1);
+	pavg_m2r (*dest, mm0);
+	pavg_m2r (*(dest+8), mm1);
+	ref += stride;
+	movq_r2m (mm0, *dest);
+	movq_r2m (mm1, *(dest+8));
+	dest += stride;
+    } while (--height);
+}
+
+static mmx_t mask_one = {0x0101010101010101LL};
+
+static inline void MC_put4_8 (int height, uint8_t * dest, uint8_t * ref,
+			      int stride, int cpu)
+{
+    movq_m2r (*ref, mm0);
+    movq_m2r (*(ref+1), mm1);
+    movq_r2r (mm0, mm7);
+    pxor_r2r (mm1, mm7);
+    pavg_r2r (mm1, mm0);
+    ref += stride;
+
+    do {
+	movq_m2r (*ref, mm2);
+	movq_r2r (mm0, mm5);
+
+	movq_m2r (*(ref+1), mm3);
+	movq_r2r (mm2, mm6);
+
+	pxor_r2r (mm3, mm6);
+	pavg_r2r (mm3, mm2);
+
+	por_r2r (mm6, mm7);
+	pxor_r2r (mm2, mm5);
+
+	pand_r2r (mm5, mm7);
+	pavg_r2r (mm2, mm0);
+
+	pand_m2r (mask_one, mm7);
+
+	psubusb_r2r (mm7, mm0);
+
+	ref += stride;
+	movq_r2m (mm0, *dest);
+	dest += stride;
+
+	movq_r2r (mm6, mm7);	// unroll !
+	movq_r2r (mm2, mm0);	// unroll !
+    } while (--height);
+}
+
+static inline void MC_put4_16 (int height, uint8_t * dest, uint8_t * ref,
+			       int stride, int cpu)
+{
+    do {
+	movq_m2r (*ref, mm0);
+	movq_m2r (*(ref+stride+1), mm1);
+	movq_r2r (mm0, mm7);
+	movq_m2r (*(ref+1), mm2);
+	pxor_r2r (mm1, mm7);
+	movq_m2r (*(ref+stride), mm3);
+	movq_r2r (mm2, mm6);
+	pxor_r2r (mm3, mm6);
+	pavg_r2r (mm1, mm0);
+	pavg_r2r (mm3, mm2);
+	por_r2r (mm6, mm7);
+	movq_r2r (mm0, mm6);
+	pxor_r2r (mm2, mm6);
+	pand_r2r (mm6, mm7);
+	pand_m2r (mask_one, mm7);
+	pavg_r2r (mm2, mm0);
+	psubusb_r2r (mm7, mm0);
+	movq_r2m (mm0, *dest);
+
+	movq_m2r (*(ref+8), mm0);
+	movq_m2r (*(ref+stride+9), mm1);
+	movq_r2r (mm0, mm7);
+	movq_m2r (*(ref+9), mm2);
+	pxor_r2r (mm1, mm7);
+	movq_m2r (*(ref+stride+8), mm3);
+	movq_r2r (mm2, mm6);
+	pxor_r2r (mm3, mm6);
+	pavg_r2r (mm1, mm0);
+	pavg_r2r (mm3, mm2);
+	por_r2r (mm6, mm7);
+	movq_r2r (mm0, mm6);
+	pxor_r2r (mm2, mm6);
+	pand_r2r (mm6, mm7);
+	pand_m2r (mask_one, mm7);
+	pavg_r2r (mm2, mm0);
+	psubusb_r2r (mm7, mm0);
+	ref += stride;
+	movq_r2m (mm0, *(dest+8));
+	dest += stride;
+    } while (--height);
+}
+
+static inline void MC_avg4_8 (int height, uint8_t * dest, uint8_t * ref,
+			      int stride, int cpu)
+{
+    do {
+	movq_m2r (*ref, mm0);
+	movq_m2r (*(ref+stride+1), mm1);
+	movq_r2r (mm0, mm7);
+	movq_m2r (*(ref+1), mm2);
+	pxor_r2r (mm1, mm7);
+	movq_m2r (*(ref+stride), mm3);
+	movq_r2r (mm2, mm6);
+	pxor_r2r (mm3, mm6);
+	pavg_r2r (mm1, mm0);
+	pavg_r2r (mm3, mm2);
+	por_r2r (mm6, mm7);
+	movq_r2r (mm0, mm6);
+	pxor_r2r (mm2, mm6);
+	pand_r2r (mm6, mm7);
+	pand_m2r (mask_one, mm7);
+	pavg_r2r (mm2, mm0);
+	psubusb_r2r (mm7, mm0);
+	movq_m2r (*dest, mm1);
+	pavg_r2r (mm1, mm0);
+	ref += stride;
+	movq_r2m (mm0, *dest);
+	dest += stride;
+    } while (--height);
+}
+
+static inline void MC_avg4_16 (int height, uint8_t * dest, uint8_t * ref,
+			       int stride, int cpu)
+{
+    do {
+	movq_m2r (*ref, mm0);
+	movq_m2r (*(ref+stride+1), mm1);
+	movq_r2r (mm0, mm7);
+	movq_m2r (*(ref+1), mm2);
+	pxor_r2r (mm1, mm7);
+	movq_m2r (*(ref+stride), mm3);
+	movq_r2r (mm2, mm6);
+	pxor_r2r (mm3, mm6);
+	pavg_r2r (mm1, mm0);
+	pavg_r2r (mm3, mm2);
+	por_r2r (mm6, mm7);
+	movq_r2r (mm0, mm6);
+	pxor_r2r (mm2, mm6);
+	pand_r2r (mm6, mm7);
+	pand_m2r (mask_one, mm7);
+	pavg_r2r (mm2, mm0);
+	psubusb_r2r (mm7, mm0);
+	movq_m2r (*dest, mm1);
+	pavg_r2r (mm1, mm0);
+	movq_r2m (mm0, *dest);
+
+	movq_m2r (*(ref+8), mm0);
+	movq_m2r (*(ref+stride+9), mm1);
+	movq_r2r (mm0, mm7);
+	movq_m2r (*(ref+9), mm2);
+	pxor_r2r (mm1, mm7);
+	movq_m2r (*(ref+stride+8), mm3);
+	movq_r2r (mm2, mm6);
+	pxor_r2r (mm3, mm6);
+	pavg_r2r (mm1, mm0);
+	pavg_r2r (mm3, mm2);
+	por_r2r (mm6, mm7);
+	movq_r2r (mm0, mm6);
+	pxor_r2r (mm2, mm6);
+	pand_r2r (mm6, mm7);
+	pand_m2r (mask_one, mm7);
+	pavg_r2r (mm2, mm0);
+	psubusb_r2r (mm7, mm0);
+	movq_m2r (*(dest+8), mm1);
+	pavg_r2r (mm1, mm0);
+	ref += stride;
+	movq_r2m (mm0, *(dest+8));
+	dest += stride;
+    } while (--height);
+}
+
+static void MC_avg_16_mmxext (uint8_t * dest, uint8_t * ref,
+			      int stride, int height)
+{
+    MC_avg1_16 (height, dest, ref, stride, CPU_MMXEXT);
+}
+
+static void MC_avg_8_mmxext (uint8_t * dest, uint8_t * ref,
+			     int stride, int height)
+{
+    MC_avg1_8 (height, dest, ref, stride, CPU_MMXEXT);
+}
+
+static void MC_put_16_mmxext (uint8_t * dest, uint8_t * ref,
+			      int stride, int height)
+{
+    MC_put1_16 (height, dest, ref, stride);
+}
+
+static void MC_put_8_mmxext (uint8_t * dest, uint8_t * ref,
+			     int stride, int height)
+{
+    MC_put1_8 (height, dest, ref, stride);
+}
+
+static void MC_avg_x16_mmxext (uint8_t * dest, uint8_t * ref,
+			       int stride, int height)
+{
+    MC_avg2_16 (height, dest, ref, stride, 1, CPU_MMXEXT);
+}
+
+static void MC_avg_x8_mmxext (uint8_t * dest, uint8_t * ref,
+			      int stride, int height)
+{
+    MC_avg2_8 (height, dest, ref, stride, 1, CPU_MMXEXT);
+}
+
+static void MC_put_x16_mmxext (uint8_t * dest, uint8_t * ref,
+			       int stride, int height)
+{
+    MC_put2_16 (height, dest, ref, stride, 1, CPU_MMXEXT);
+}
+
+static void MC_put_x8_mmxext (uint8_t * dest, uint8_t * ref,
+			      int stride, int height)
+{
+    MC_put2_8 (height, dest, ref, stride, 1, CPU_MMXEXT);
+}
+
+static void MC_avg_y16_mmxext (uint8_t * dest, uint8_t * ref,
+			       int stride, int height)
+{
+    MC_avg2_16 (height, dest, ref, stride, stride, CPU_MMXEXT);
+}
+
+static void MC_avg_y8_mmxext (uint8_t * dest, uint8_t * ref,
+			      int stride, int height)
+{
+    MC_avg2_8 (height, dest, ref, stride, stride, CPU_MMXEXT);
+}
+
+static void MC_put_y16_mmxext (uint8_t * dest, uint8_t * ref,
+			       int stride, int height)
+{
+    MC_put2_16 (height, dest, ref, stride, stride, CPU_MMXEXT);
+}
+
+static void MC_put_y8_mmxext (uint8_t * dest, uint8_t * ref,
+			      int stride, int height)
+{
+    MC_put2_8 (height, dest, ref, stride, stride, CPU_MMXEXT);
+}
+
+static void MC_avg_xy16_mmxext (uint8_t * dest, uint8_t * ref,
+				int stride, int height)
+{
+    MC_avg4_16 (height, dest, ref, stride, CPU_MMXEXT);
+}
+
+static void MC_avg_xy8_mmxext (uint8_t * dest, uint8_t * ref,
+			       int stride, int height)
+{
+    MC_avg4_8 (height, dest, ref, stride, CPU_MMXEXT);
+}
+
+static void MC_put_xy16_mmxext (uint8_t * dest, uint8_t * ref,
+				int stride, int height)
+{
+    MC_put4_16 (height, dest, ref, stride, CPU_MMXEXT);
+}
+
+static void MC_put_xy8_mmxext (uint8_t * dest, uint8_t * ref,
+			       int stride, int height)
+{
+    MC_put4_8 (height, dest, ref, stride, CPU_MMXEXT);
+}
+
+
+MOTION_COMP_EXTERN (mmxext)
+
+
+
+static void MC_avg_16_3dnow (uint8_t * dest, uint8_t * ref,
+			      int stride, int height)
+{
+    MC_avg1_16 (height, dest, ref, stride, CPU_3DNOW);
+}
+
+static void MC_avg_8_3dnow (uint8_t * dest, uint8_t * ref,
+			     int stride, int height)
+{
+    MC_avg1_8 (height, dest, ref, stride, CPU_3DNOW);
+}
+
+static void MC_put_16_3dnow (uint8_t * dest, uint8_t * ref,
+			      int stride, int height)
+{
+    MC_put1_16 (height, dest, ref, stride);
+}
+
+static void MC_put_8_3dnow (uint8_t * dest, uint8_t * ref,
+			     int stride, int height)
+{
+    MC_put1_8 (height, dest, ref, stride);
+}
+
+static void MC_avg_x16_3dnow (uint8_t * dest, uint8_t * ref,
+			       int stride, int height)
+{
+    MC_avg2_16 (height, dest, ref, stride, 1, CPU_3DNOW);
+}
+
+static void MC_avg_x8_3dnow (uint8_t * dest, uint8_t * ref,
+			      int stride, int height)
+{
+    MC_avg2_8 (height, dest, ref, stride, 1, CPU_3DNOW);
+}
+
+static void MC_put_x16_3dnow (uint8_t * dest, uint8_t * ref,
+			       int stride, int height)
+{
+    MC_put2_16 (height, dest, ref, stride, 1, CPU_3DNOW);
+}
+
+static void MC_put_x8_3dnow (uint8_t * dest, uint8_t * ref,
+			      int stride, int height)
+{
+    MC_put2_8 (height, dest, ref, stride, 1, CPU_3DNOW);
+}
+
+static void MC_avg_y16_3dnow (uint8_t * dest, uint8_t * ref,
+			       int stride, int height)
+{
+    MC_avg2_16 (height, dest, ref, stride, stride, CPU_3DNOW);
+}
+
+static void MC_avg_y8_3dnow (uint8_t * dest, uint8_t * ref,
+			      int stride, int height)
+{
+    MC_avg2_8 (height, dest, ref, stride, stride, CPU_3DNOW);
+}
+
+static void MC_put_y16_3dnow (uint8_t * dest, uint8_t * ref,
+			       int stride, int height)
+{
+    MC_put2_16 (height, dest, ref, stride, stride, CPU_3DNOW);
+}
+
+static void MC_put_y8_3dnow (uint8_t * dest, uint8_t * ref,
+			      int stride, int height)
+{
+    MC_put2_8 (height, dest, ref, stride, stride, CPU_3DNOW);
+}
+
+static void MC_avg_xy16_3dnow (uint8_t * dest, uint8_t * ref,
+				int stride, int height)
+{
+    MC_avg4_16 (height, dest, ref, stride, CPU_3DNOW);
+}
+
+static void MC_avg_xy8_3dnow (uint8_t * dest, uint8_t * ref,
+			       int stride, int height)
+{
+    MC_avg4_8 (height, dest, ref, stride, CPU_3DNOW);
+}
+
+static void MC_put_xy16_3dnow (uint8_t * dest, uint8_t * ref,
+				int stride, int height)
+{
+    MC_put4_16 (height, dest, ref, stride, CPU_3DNOW);
+}
+
+static void MC_put_xy8_3dnow (uint8_t * dest, uint8_t * ref,
+			       int stride, int height)
+{
+    MC_put4_8 (height, dest, ref, stride, CPU_3DNOW);
+}
+
+
+MOTION_COMP_EXTERN (3dnow)
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/mpeg2.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,57 @@
+/*
+ * mpeg2.h
+ *
+ * Copyright (C) Aaron Holtzman <aholtzma@ess.engr.uvic.ca> - Mar 2000
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *	
+ * mpeg2dec 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, or (at your option)
+ * any later version.
+ * 
+ * mpeg2dec 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 GNU Make; see the file COPYING. If not, write to
+ * the Free Software Foundation, 
+ *
+ */
+
+#ifdef __OMS__
+#include <oms/plugin/output_video.h>
+#ifndef vo_functions_t
+#define vo_functions_t plugin_output_video_t
+#endif
+#else
+//FIXME normally I wouldn't nest includes, but we'll leave this here until I get
+//another chance to move things around
+#include "video_out.h"
+#endif
+
+#include <inttypes.h>
+#ifdef __OMS__
+#include <oms/accel.h>
+#else
+#include "mm_accel.h"
+#endif
+
+//config flags
+#define MPEG2_MLIB_ENABLE MM_ACCEL_MLIB
+#define MPEG2_MMX_ENABLE MM_ACCEL_X86_MMX
+#define MPEG2_3DNOW_ENABLE MM_ACCEL_X86_3DNOW
+#define MPEG2_SSE_ENABLE MM_ACCEL_X86_MMXEXT
+
+//typedef struct mpeg2_config_s {
+//    //Bit flags that enable various things
+//    uint32_t flags;
+//} mpeg2_config_t;
+
+void mpeg2_init (void);
+//void mpeg2_allocate_image_buffers (picture_t * picture);
+int mpeg2_decode_data (vo_functions_t *, uint8_t * data_start, uint8_t * data_end);
+//void mpeg2_close (vo_functions_t *);
+void mpeg2_drop (int flag);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/mpeg2_internal.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,220 @@
+#include <inttypes.h>
+/*
+ * mpeg2_internal.h
+ * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *
+ * mpeg2dec 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.
+ *
+ * mpeg2dec 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// hack mode - temporary
+// 0 = decode B pictures in a small slice buffer, display slice per slice
+// 1 = decode in a frame buffer, display slice per slice
+// 2 = decode in a frame buffer, display whole frames
+#define HACK_MODE 0
+
+// macroblock modes
+#define MACROBLOCK_INTRA 1
+#define MACROBLOCK_PATTERN 2
+#define MACROBLOCK_MOTION_BACKWARD 4
+#define MACROBLOCK_MOTION_FORWARD 8
+#define MACROBLOCK_QUANT 16
+#define DCT_TYPE_INTERLACED 32
+// motion_type
+#define MOTION_TYPE_MASK (3*64)
+#define MOTION_TYPE_BASE 64
+#define MC_FIELD (1*64)
+#define MC_FRAME (2*64)
+#define MC_16X8 (2*64)
+#define MC_DMV (3*64)
+
+//picture structure
+#define TOP_FIELD 1
+#define BOTTOM_FIELD 2
+#define FRAME_PICTURE 3
+
+//picture coding type
+#define I_TYPE 1
+#define P_TYPE 2
+#define B_TYPE 3
+#define D_TYPE 4
+
+//The picture struct contains all of the top level state
+//information (ie everything except slice and macroblock
+//state)
+typedef struct picture_s {
+    //-- sequence header stuff --
+    uint8_t intra_quantizer_matrix [64];
+    uint8_t non_intra_quantizer_matrix [64];
+
+    //The width and height of the picture snapped to macroblock units
+    int coded_picture_width;
+    int coded_picture_height;
+
+    //-- picture header stuff --
+
+    //what type of picture this is (I,P,or B) D from MPEG-1 isn't supported
+    int picture_coding_type;
+	
+    //-- picture coding extension stuff --
+	
+    //quantization factor for motion vectors
+    int f_code[2][2];
+    //quantization factor for intra dc coefficients
+    int intra_dc_precision;
+    //top/bottom/both fields
+    int picture_structure;
+    //bool to indicate all predictions are frame based
+    int frame_pred_frame_dct;
+    //bool to indicate whether intra blocks have motion vectors 
+    // (for concealment)
+    int concealment_motion_vectors;
+    //bit to indicate which quantization table to use
+    int q_scale_type;
+    //bool to use different vlc tables
+    int intra_vlc_format;
+
+    //last macroblock in the picture
+    int last_mba;
+    //width of picture in macroblocks
+    int mb_width;
+
+    //stuff derived from bitstream
+
+    //pointer to the zigzag scan we're supposed to be using
+    uint8_t * scan;
+
+    //Pointer to the current planar frame buffer (Y,Cr,CB)
+    uint8_t * current_frame[3];    
+    //storage for reference frames plus a b-frame
+    uint8_t * forward_reference_frame[3];
+    uint8_t * backward_reference_frame[3];
+    uint8_t * throwaway_frame[3];
+    uint8_t * pp_frame[3];  // postprocess
+    //uint8_t * throwaway_frame;
+
+    int pp_options; // postprocess
+
+    int second_field;
+
+    // MPEG1 - testing
+    uint8_t mpeg1;
+
+    //these things are not needed by the decoder
+    //NOTICE : this is a temporary interface, we will build a better one later.
+    int aspect_ratio_information;
+    int frame_rate_code;
+    int progressive_sequence;
+    int top_field_first; // this one is actually used for DMV MC
+    int repeat_first_field;
+    int progressive_frame;
+    // added by A'rpi/ESP-team:
+    int repeat_count;
+    int bitrate;
+    int frame_rate;
+    int display_picture_width;
+    int display_picture_height;
+} picture_t;
+
+typedef struct motion_s {
+    uint8_t * ref[2][3];
+    int pmv[2][2];
+    int f_code[2];
+} motion_t;
+
+// state that is carried from one macroblock to the next inside of a same slice
+typedef struct slice_s {
+    // bit parsing stuff
+    uint32_t bitstream_buf;	// current 32 bit working set of buffer
+    int bitstream_bits;		// used bits in working set
+    uint8_t * bitstream_ptr;	// buffer with stream data
+
+    //Motion vectors
+    //The f_ and b_ correspond to the forward and backward motion
+    //predictors
+    motion_t b_motion;
+    motion_t f_motion;
+
+    // predictor for DC coefficients in intra blocks
+    int16_t dc_dct_pred[3];
+
+    uint16_t quantizer_scale;	// remove
+} slice_t;
+
+typedef struct mpeg2_config_s {
+    //Bit flags that enable various things
+    uint32_t flags;
+} mpeg2_config_t;
+
+//The only global variable,
+//the config struct
+extern mpeg2_config_t config;
+
+
+
+// slice.c
+void header_state_init (picture_t * picture);
+int header_process_picture_header (picture_t * picture, uint8_t * buffer);
+int header_process_sequence_header (picture_t * picture, uint8_t * buffer);
+int header_process_extension (picture_t * picture, uint8_t * buffer);
+
+// idct.c
+void idct_init (void);
+
+// idct_mlib.c
+void idct_block_copy_mlib (int16_t * block, uint8_t * dest, int stride);
+void idct_block_add_mlib (int16_t * block, uint8_t * dest, int stride);
+
+// idct_mmx.c
+void idct_block_copy_mmxext (int16_t *block, uint8_t * dest, int stride);
+void idct_block_add_mmxext (int16_t *block, uint8_t * dest, int stride);
+void idct_block_copy_mmx (int16_t *block, uint8_t * dest, int stride);
+void idct_block_add_mmx (int16_t *block, uint8_t * dest, int stride);
+void idct_mmx_init (void);
+
+// motion_comp.c
+void motion_comp_init (void);
+
+typedef struct mc_functions_s
+{
+    void (* put [8]) (uint8_t *dst, uint8_t *, int32_t, int32_t);
+    void (* avg [8]) (uint8_t *dst, uint8_t *, int32_t, int32_t);
+} mc_functions_t;
+
+#define MOTION_COMP_EXTERN(x) mc_functions_t mc_functions_##x =		\
+{									\
+    {MC_put_16_##x, MC_put_x16_##x, MC_put_y16_##x, MC_put_xy16_##x,	\
+     MC_put_8_##x,  MC_put_x8_##x,  MC_put_y8_##x,  MC_put_xy8_##x},	\
+    {MC_avg_16_##x, MC_avg_x16_##x, MC_avg_y16_##x, MC_avg_xy16_##x,	\
+     MC_avg_8_##x,  MC_avg_x8_##x,  MC_avg_y8_##x,  MC_avg_xy8_##x}	\
+};
+
+extern mc_functions_t mc_functions_c;
+extern mc_functions_t mc_functions_mmx;
+extern mc_functions_t mc_functions_mmxext;
+extern mc_functions_t mc_functions_3dnow;
+extern mc_functions_t mc_functions_mlib;
+
+// slice.c
+int slice_process (picture_t *picture, uint8_t code, uint8_t * buffer);
+
+// stats.c
+void stats_header (uint8_t code, uint8_t * buffer);
+
+#define MBC 45
+#define MBR 36
+extern int quant_store[MBR+1][MBC+1]; // [Review]
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/slice.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,1797 @@
+/*
+ * slice.c
+ * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *
+ * mpeg2dec 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.
+ *
+ * mpeg2dec 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <inttypes.h>
+
+#include "mpeg2_internal.h"
+#include "attributes.h"
+
+extern mc_functions_t mc_functions;
+extern void (* idct_block_copy) (int16_t * block, uint8_t * dest, int stride);
+extern void (* idct_block_add) (int16_t * block, uint8_t * dest, int stride);
+
+static int16_t DCTblock[64] ATTR_ALIGN(16);
+
+#include "vlc.h"
+
+static int non_linear_quantizer_scale [] = {
+     0,  1,  2,  3,  4,  5,   6,   7,
+     8, 10, 12, 14, 16, 18,  20,  22,
+    24, 28, 32, 36, 40, 44,  48,  52,
+    56, 64, 72, 80, 88, 96, 104, 112
+};
+
+static inline int get_macroblock_modes (slice_t * slice, int picture_structure,
+					int picture_coding_type,
+					int frame_pred_frame_dct)
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)
+#define bit_ptr (slice->bitstream_ptr)
+    int macroblock_modes;
+    MBtab * tab;
+
+    switch (picture_coding_type) {
+    case I_TYPE:
+
+	tab = MB_I + UBITS (bit_buf, 1);
+	DUMPBITS (bit_buf, bits, tab->len);
+	macroblock_modes = tab->modes;
+
+	if ((! frame_pred_frame_dct) && (picture_structure == FRAME_PICTURE)) {
+	    macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED;
+	    DUMPBITS (bit_buf, bits, 1);
+	}
+
+	return macroblock_modes;
+
+    case P_TYPE:
+
+	tab = MB_P + UBITS (bit_buf, 5);
+	DUMPBITS (bit_buf, bits, tab->len);
+	macroblock_modes = tab->modes;
+
+	if (picture_structure != FRAME_PICTURE) {
+	    if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) {
+		macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE;
+		DUMPBITS (bit_buf, bits, 2);
+	    }
+	    return macroblock_modes;
+	} else if (frame_pred_frame_dct) {
+	    if (macroblock_modes & MACROBLOCK_MOTION_FORWARD)
+		macroblock_modes |= MC_FRAME;
+	    return macroblock_modes;
+	} else {
+	    if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) {
+		macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE;
+		DUMPBITS (bit_buf, bits, 2);
+	    }
+	    if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) {
+		macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED;
+		DUMPBITS (bit_buf, bits, 1);
+	    }
+	    return macroblock_modes;
+	}
+
+    case B_TYPE:
+
+	tab = MB_B + UBITS (bit_buf, 6);
+	DUMPBITS (bit_buf, bits, tab->len);
+	macroblock_modes = tab->modes;
+
+	if (picture_structure != FRAME_PICTURE) {
+	    if (! (macroblock_modes & MACROBLOCK_INTRA)) {
+		macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE;
+		DUMPBITS (bit_buf, bits, 2);
+	    }
+	    return macroblock_modes;
+	} else if (frame_pred_frame_dct) {
+	    //if (! (macroblock_modes & MACROBLOCK_INTRA))
+	    macroblock_modes |= MC_FRAME;
+	    return macroblock_modes;
+	} else {
+	    if (macroblock_modes & MACROBLOCK_INTRA)
+		goto intra;
+	    macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE;
+	    DUMPBITS (bit_buf, bits, 2);
+	    if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) {
+	    intra:
+		macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED;
+		DUMPBITS (bit_buf, bits, 1);
+	    }
+	    return macroblock_modes;
+	}
+
+    case D_TYPE:
+
+	DUMPBITS (bit_buf, bits, 1);
+	return MACROBLOCK_INTRA;
+
+    default:
+	return 0;
+    }
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static inline int get_quantizer_scale (slice_t * slice, int q_scale_type)
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)
+#define bit_ptr (slice->bitstream_ptr)
+
+    int quantizer_scale_code;
+
+    quantizer_scale_code = UBITS (bit_buf, 5);
+    DUMPBITS (bit_buf, bits, 5);
+
+    if (q_scale_type)
+	return non_linear_quantizer_scale [quantizer_scale_code];
+    else
+	return quantizer_scale_code << 1;
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static inline int get_motion_delta (slice_t * slice, int f_code)
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)
+#define bit_ptr (slice->bitstream_ptr)
+
+    int delta;
+    int sign;
+    MVtab * tab;
+
+    if (bit_buf & 0x80000000) {
+	DUMPBITS (bit_buf, bits, 1);
+	return 0;
+    } else if (bit_buf >= 0x0c000000) {
+
+	tab = MV_4 + UBITS (bit_buf, 4);
+	delta = (tab->delta << f_code) + 1;
+	bits += tab->len + f_code + 1;
+	bit_buf <<= tab->len;
+
+	sign = SBITS (bit_buf, 1);
+	bit_buf <<= 1;
+
+	if (f_code)
+	    delta += UBITS (bit_buf, f_code);
+	bit_buf <<= f_code;
+
+	return (delta ^ sign) - sign;
+
+    } else {
+
+	tab = MV_10 + UBITS (bit_buf, 10);
+	delta = (tab->delta << f_code) + 1;
+	bits += tab->len + 1;
+	bit_buf <<= tab->len;
+
+	sign = SBITS (bit_buf, 1);
+	bit_buf <<= 1;
+
+	if (f_code) {
+	    NEEDBITS (bit_buf, bits, bit_ptr);
+	    delta += UBITS (bit_buf, f_code);
+	    DUMPBITS (bit_buf, bits, f_code);
+	}
+
+	return (delta ^ sign) - sign;
+
+    }
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static inline int bound_motion_vector (int vector, int f_code)
+{
+#if 1
+    int limit;
+
+    limit = 16 << f_code;
+
+    if (vector >= limit)
+	return vector - 2*limit;
+    else if (vector < -limit)
+	return vector + 2*limit;
+    else return vector;
+#else
+    return (vector << (27 - f_code)) >> (27 - f_code);
+#endif
+}
+
+static inline int get_dmv (slice_t * slice)
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)
+#define bit_ptr (slice->bitstream_ptr)
+
+    DMVtab * tab;
+
+    tab = DMV_2 + UBITS (bit_buf, 2);
+    DUMPBITS (bit_buf, bits, tab->len);
+    return tab->dmv;
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static inline int get_coded_block_pattern (slice_t * slice)
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)
+#define bit_ptr (slice->bitstream_ptr)
+
+    CBPtab * tab;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+
+    if (bit_buf >= 0x20000000) {
+
+	tab = CBP_7 - 16 + UBITS (bit_buf, 7);
+	DUMPBITS (bit_buf, bits, tab->len);
+	return tab->cbp;
+
+    } else {
+
+	tab = CBP_9 + UBITS (bit_buf, 9);
+	DUMPBITS (bit_buf, bits, tab->len);
+	return tab->cbp;
+    }
+
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static inline int get_luma_dc_dct_diff (slice_t * slice)
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)
+#define bit_ptr (slice->bitstream_ptr)
+    DCtab * tab;
+    int size;
+    int dc_diff;
+
+    if (bit_buf < 0xf8000000) {
+	tab = DC_lum_5 + UBITS (bit_buf, 5);
+	size = tab->size;
+	if (size) {
+	    bits += tab->len + size;
+	    bit_buf <<= tab->len;
+	    dc_diff =
+		UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);
+	    bit_buf <<= size;
+	    return dc_diff;
+	} else {
+	    DUMPBITS (bit_buf, bits, 3);
+	    return 0;
+	}
+    } else {
+	tab = DC_long - 0x1e0 + UBITS (bit_buf, 9);
+	size = tab->size;
+	DUMPBITS (bit_buf, bits, tab->len);
+	NEEDBITS (bit_buf, bits, bit_ptr);
+	dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);
+	DUMPBITS (bit_buf, bits, size);
+	return dc_diff;
+    }
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static inline int get_chroma_dc_dct_diff (slice_t * slice)
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)
+#define bit_ptr (slice->bitstream_ptr)
+    DCtab * tab;
+    int size;
+    int dc_diff;
+
+    if (bit_buf < 0xf8000000) {
+	tab = DC_chrom_5 + UBITS (bit_buf, 5);
+	size = tab->size;
+	if (size) {
+	    bits += tab->len + size;
+	    bit_buf <<= tab->len;
+	    dc_diff =
+		UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);
+	    bit_buf <<= size;
+	    return dc_diff;
+	} else {
+	    DUMPBITS (bit_buf, bits, 2);
+	    return 0;
+	}
+    } else {
+	tab = DC_long - 0x3e0 + UBITS (bit_buf, 10);
+	size = tab->size;
+	DUMPBITS (bit_buf, bits, tab->len + 1);
+	NEEDBITS (bit_buf, bits, bit_ptr);
+	dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);
+	DUMPBITS (bit_buf, bits, size);
+	return dc_diff;
+    }
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+#define SATURATE(val)		\
+do {				\
+    if (val > 2047)		\
+	val = 2047;		\
+    else if (val < -2048)	\
+	val = -2048;		\
+} while (0)
+
+static void get_intra_block_B14 (picture_t * picture, slice_t * slice,
+				 int16_t * dest)
+{
+    int i;
+    int j;
+    int val;
+    uint8_t * scan = picture->scan;
+    uint8_t * quant_matrix = picture->intra_quantizer_matrix;
+    int quantizer_scale = slice->quantizer_scale;
+    int mismatch;
+    DCTtab * tab;
+    uint32_t bit_buf;
+    int bits;
+    uint8_t * bit_ptr;
+
+    i = 0;
+    mismatch = ~dest[0];
+
+    bit_buf = slice->bitstream_buf;
+    bits = slice->bitstream_bits;
+    bit_ptr = slice->bitstream_ptr;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+
+    while (1) {
+	if (bit_buf >= 0x28000000) {
+
+	    tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5);
+
+	    i += tab->run;
+	    if (i >= 64)
+		break;	// end of block
+
+	normal_code:
+	    j = scan[i];
+	    bit_buf <<= tab->len;
+	    bits += tab->len + 1;
+	    val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4;
+
+	    // if (bitstream_get (1)) val = -val;
+	    val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
+
+	    SATURATE (val);
+	    dest[j] = val;
+	    mismatch ^= val;
+
+	    bit_buf <<= 1;
+	    NEEDBITS (bit_buf, bits, bit_ptr);
+
+	    continue;
+
+	} else if (bit_buf >= 0x04000000) {
+
+	    tab = DCT_B14_8 - 4 + UBITS (bit_buf, 8);
+
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+
+	    // escape code
+
+	    i += UBITS (bit_buf << 6, 6) - 64;
+	    if (i >= 64)
+		break;	// illegal, but check needed to avoid buffer overflow
+
+	    j = scan[i];
+
+	    DUMPBITS (bit_buf, bits, 12);
+	    NEEDBITS (bit_buf, bits, bit_ptr);
+	    val = (SBITS (bit_buf, 12) *
+		   quantizer_scale * quant_matrix[j]) / 16;
+
+	    SATURATE (val);
+	    dest[j] = val;
+	    mismatch ^= val;
+
+	    DUMPBITS (bit_buf, bits, 12);
+	    NEEDBITS (bit_buf, bits, bit_ptr);
+
+	    continue;
+
+	} else if (bit_buf >= 0x02000000) {
+	    tab = DCT_B14_10 - 8 + UBITS (bit_buf, 10);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	} else if (bit_buf >= 0x00800000) {
+	    tab = DCT_13 - 16 + UBITS (bit_buf, 13);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	} else if (bit_buf >= 0x00200000) {
+	    tab = DCT_15 - 16 + UBITS (bit_buf, 15);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	} else {
+	    tab = DCT_16 + UBITS (bit_buf, 16);
+	    bit_buf <<= 16;
+	    GETWORD (bit_buf, bits + 16, bit_ptr);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	}
+	break;	// illegal, but check needed to avoid buffer overflow
+    }
+    dest[63] ^= mismatch & 1;
+    DUMPBITS (bit_buf, bits, 2);	// dump end of block code
+    slice->bitstream_buf = bit_buf;
+    slice->bitstream_bits = bits;
+    slice->bitstream_ptr = bit_ptr;
+}
+
+static void get_intra_block_B15 (picture_t * picture, slice_t * slice,
+				 int16_t * dest)
+{
+    int i;
+    int j;
+    int val;
+    uint8_t * scan = picture->scan;
+    uint8_t * quant_matrix = picture->intra_quantizer_matrix;
+    int quantizer_scale = slice->quantizer_scale;
+    int mismatch;
+    DCTtab * tab;
+    uint32_t bit_buf;
+    int bits;
+    uint8_t * bit_ptr;
+
+    i = 0;
+    mismatch = ~dest[0];
+
+    bit_buf = slice->bitstream_buf;
+    bits = slice->bitstream_bits;
+    bit_ptr = slice->bitstream_ptr;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+
+    while (1) {
+	if (bit_buf >= 0x04000000) {
+
+	    tab = DCT_B15_8 - 4 + UBITS (bit_buf, 8);
+
+	    i += tab->run;
+	    if (i < 64) {
+
+	    normal_code:
+		j = scan[i];
+		bit_buf <<= tab->len;
+		bits += tab->len + 1;
+		val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4;
+
+		// if (bitstream_get (1)) val = -val;
+		val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
+
+		SATURATE (val);
+		dest[j] = val;
+		mismatch ^= val;
+
+		bit_buf <<= 1;
+		NEEDBITS (bit_buf, bits, bit_ptr);
+
+		continue;
+
+	    } else {
+
+		// end of block. I commented out this code because if we
+		// dont exit here we will still exit at the later test :)
+
+		//if (i >= 128) break;	// end of block
+
+		// escape code
+
+		i += UBITS (bit_buf << 6, 6) - 64;
+		if (i >= 64)
+		    break;	// illegal, but check against buffer overflow
+
+		j = scan[i];
+
+		DUMPBITS (bit_buf, bits, 12);
+		NEEDBITS (bit_buf, bits, bit_ptr);
+		val = (SBITS (bit_buf, 12) *
+		       quantizer_scale * quant_matrix[j]) / 16;
+
+		SATURATE (val);
+		dest[j] = val;
+		mismatch ^= val;
+
+		DUMPBITS (bit_buf, bits, 12);
+		NEEDBITS (bit_buf, bits, bit_ptr);
+
+		continue;
+
+	    }
+	} else if (bit_buf >= 0x02000000) {
+	    tab = DCT_B15_10 - 8 + UBITS (bit_buf, 10);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	} else if (bit_buf >= 0x00800000) {
+	    tab = DCT_13 - 16 + UBITS (bit_buf, 13);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	} else if (bit_buf >= 0x00200000) {
+	    tab = DCT_15 - 16 + UBITS (bit_buf, 15);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	} else {
+	    tab = DCT_16 + UBITS (bit_buf, 16);
+	    bit_buf <<= 16;
+	    GETWORD (bit_buf, bits + 16, bit_ptr);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	}
+	break;	// illegal, but check needed to avoid buffer overflow
+    }
+    dest[63] ^= mismatch & 1;
+    DUMPBITS (bit_buf, bits, 4);	// dump end of block code
+    slice->bitstream_buf = bit_buf;
+    slice->bitstream_bits = bits;
+    slice->bitstream_ptr = bit_ptr;
+}
+
+static void get_non_intra_block (picture_t * picture, slice_t * slice,
+				 int16_t * dest)
+{
+    int i;
+    int j;
+    int val;
+    uint8_t * scan = picture->scan;
+    uint8_t * quant_matrix = picture->non_intra_quantizer_matrix;
+    int quantizer_scale = slice->quantizer_scale;
+    int mismatch;
+    DCTtab * tab;
+    uint32_t bit_buf;
+    int bits;
+    uint8_t * bit_ptr;
+
+    i = -1;
+    mismatch = 1;
+
+    bit_buf = slice->bitstream_buf;
+    bits = slice->bitstream_bits;
+    bit_ptr = slice->bitstream_ptr;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    if (bit_buf >= 0x28000000) {
+	tab = DCT_B14DC_5 - 5 + UBITS (bit_buf, 5);
+	goto entry_1;
+    } else
+	goto entry_2;
+
+    while (1) {
+	if (bit_buf >= 0x28000000) {
+
+	    tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5);
+
+	entry_1:
+	    i += tab->run;
+	    if (i >= 64)
+		break;	// end of block
+
+	normal_code:
+	    j = scan[i];
+	    bit_buf <<= tab->len;
+	    bits += tab->len + 1;
+	    val = ((2*tab->level+1) * quantizer_scale * quant_matrix[j]) >> 5;
+
+	    // if (bitstream_get (1)) val = -val;
+	    val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
+
+	    SATURATE (val);
+	    dest[j] = val;
+	    mismatch ^= val;
+
+	    bit_buf <<= 1;
+	    NEEDBITS (bit_buf, bits, bit_ptr);
+
+	    continue;
+
+	}
+
+    entry_2:
+	if (bit_buf >= 0x04000000) {
+
+	    tab = DCT_B14_8 - 4 + UBITS (bit_buf, 8);
+
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+
+	    // escape code
+
+	    i += UBITS (bit_buf << 6, 6) - 64;
+	    if (i >= 64)
+		break;	// illegal, but check needed to avoid buffer overflow
+
+	    j = scan[i];
+
+	    DUMPBITS (bit_buf, bits, 12);
+	    NEEDBITS (bit_buf, bits, bit_ptr);
+	    val = 2 * (SBITS (bit_buf, 12) + SBITS (bit_buf, 1)) + 1;
+	    val = (val * quantizer_scale * quant_matrix[j]) / 32;
+
+	    SATURATE (val);
+	    dest[j] = val;
+	    mismatch ^= val;
+
+	    DUMPBITS (bit_buf, bits, 12);
+	    NEEDBITS (bit_buf, bits, bit_ptr);
+
+	    continue;
+
+	} else if (bit_buf >= 0x02000000) {
+	    tab = DCT_B14_10 - 8 + UBITS (bit_buf, 10);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	} else if (bit_buf >= 0x00800000) {
+	    tab = DCT_13 - 16 + UBITS (bit_buf, 13);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	} else if (bit_buf >= 0x00200000) {
+	    tab = DCT_15 - 16 + UBITS (bit_buf, 15);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	} else {
+	    tab = DCT_16 + UBITS (bit_buf, 16);
+	    bit_buf <<= 16;
+	    GETWORD (bit_buf, bits + 16, bit_ptr);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	}
+	break;	// illegal, but check needed to avoid buffer overflow
+    }
+    dest[63] ^= mismatch & 1;
+    DUMPBITS (bit_buf, bits, 2);	// dump end of block code
+    slice->bitstream_buf = bit_buf;
+    slice->bitstream_bits = bits;
+    slice->bitstream_ptr = bit_ptr;
+}
+
+static void get_mpeg1_intra_block (picture_t * picture, slice_t * slice,
+				   int16_t * dest)
+{
+    int i;
+    int j;
+    int val;
+    uint8_t * scan = picture->scan;
+    uint8_t * quant_matrix = picture->intra_quantizer_matrix;
+    int quantizer_scale = slice->quantizer_scale;
+    DCTtab * tab;
+    uint32_t bit_buf;
+    int bits;
+    uint8_t * bit_ptr;
+
+    i = 0;
+
+    bit_buf = slice->bitstream_buf;
+    bits = slice->bitstream_bits;
+    bit_ptr = slice->bitstream_ptr;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+
+    while (1) {
+	if (bit_buf >= 0x28000000) {
+
+	    tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5);
+
+	    i += tab->run;
+	    if (i >= 64)
+		break;	// end of block
+
+	normal_code:
+	    j = scan[i];
+	    bit_buf <<= tab->len;
+	    bits += tab->len + 1;
+	    val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4;
+
+	    // oddification
+	    val = (val - 1) | 1;
+
+	    // if (bitstream_get (1)) val = -val;
+	    val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
+
+	    SATURATE (val);
+	    dest[j] = val;
+
+	    bit_buf <<= 1;
+	    NEEDBITS (bit_buf, bits, bit_ptr);
+
+	    continue;
+
+	} else if (bit_buf >= 0x04000000) {
+
+	    tab = DCT_B14_8 - 4 + UBITS (bit_buf, 8);
+
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+
+	    // escape code
+
+	    i += UBITS (bit_buf << 6, 6) - 64;
+	    if (i >= 64)
+		break;	// illegal, but check needed to avoid buffer overflow
+
+	    j = scan[i];
+
+	    DUMPBITS (bit_buf, bits, 12);
+	    NEEDBITS (bit_buf, bits, bit_ptr);
+	    val = SBITS (bit_buf, 8);
+	    if (! (val & 0x7f)) {
+		DUMPBITS (bit_buf, bits, 8);
+		val = UBITS (bit_buf, 8) + 2 * val;
+	    }
+	    val = (val * quantizer_scale * quant_matrix[j]) / 16;
+
+	    // oddification
+	    val = (val + ~SBITS (val, 1)) | 1;
+
+	    SATURATE (val);
+	    dest[j] = val;
+
+	    DUMPBITS (bit_buf, bits, 8);
+	    NEEDBITS (bit_buf, bits, bit_ptr);
+
+	    continue;
+
+	} else if (bit_buf >= 0x02000000) {
+	    tab = DCT_B14_10 - 8 + UBITS (bit_buf, 10);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	} else if (bit_buf >= 0x00800000) {
+	    tab = DCT_13 - 16 + UBITS (bit_buf, 13);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	} else if (bit_buf >= 0x00200000) {
+	    tab = DCT_15 - 16 + UBITS (bit_buf, 15);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	} else {
+	    tab = DCT_16 + UBITS (bit_buf, 16);
+	    bit_buf <<= 16;
+	    GETWORD (bit_buf, bits + 16, bit_ptr);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	}
+	break;	// illegal, but check needed to avoid buffer overflow
+    }
+    DUMPBITS (bit_buf, bits, 2);	// dump end of block code
+    slice->bitstream_buf = bit_buf;
+    slice->bitstream_bits = bits;
+    slice->bitstream_ptr = bit_ptr;
+}
+
+static void get_mpeg1_non_intra_block (picture_t * picture, slice_t * slice,
+				       int16_t * dest)
+{
+    int i;
+    int j;
+    int val;
+    uint8_t * scan = picture->scan;
+    uint8_t * quant_matrix = picture->non_intra_quantizer_matrix;
+    int quantizer_scale = slice->quantizer_scale;
+    DCTtab * tab;
+    uint32_t bit_buf;
+    int bits;
+    uint8_t * bit_ptr;
+
+    i = -1;
+
+    bit_buf = slice->bitstream_buf;
+    bits = slice->bitstream_bits;
+    bit_ptr = slice->bitstream_ptr;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    if (bit_buf >= 0x28000000) {
+	tab = DCT_B14DC_5 - 5 + UBITS (bit_buf, 5);
+	goto entry_1;
+    } else
+	goto entry_2;
+
+    while (1) {
+	if (bit_buf >= 0x28000000) {
+
+	    tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5);
+
+	entry_1:
+	    i += tab->run;
+	    if (i >= 64)
+		break;	// end of block
+
+	normal_code:
+	    j = scan[i];
+	    bit_buf <<= tab->len;
+	    bits += tab->len + 1;
+	    val = ((2*tab->level+1) * quantizer_scale * quant_matrix[j]) >> 5;
+
+	    // oddification
+	    val = (val - 1) | 1;
+
+	    // if (bitstream_get (1)) val = -val;
+	    val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
+
+	    SATURATE (val);
+	    dest[j] = val;
+
+	    bit_buf <<= 1;
+	    NEEDBITS (bit_buf, bits, bit_ptr);
+
+	    continue;
+
+	}
+
+    entry_2:
+	if (bit_buf >= 0x04000000) {
+
+	    tab = DCT_B14_8 - 4 + UBITS (bit_buf, 8);
+
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+
+	    // escape code
+
+	    i += UBITS (bit_buf << 6, 6) - 64;
+	    if (i >= 64)
+		break;	// illegal, but check needed to avoid buffer overflow
+
+	    j = scan[i];
+
+	    DUMPBITS (bit_buf, bits, 12);
+	    NEEDBITS (bit_buf, bits, bit_ptr);
+	    val = SBITS (bit_buf, 8);
+	    if (! (val & 0x7f)) {
+		DUMPBITS (bit_buf, bits, 8);
+		val = UBITS (bit_buf, 8) + 2 * val;
+	    }
+	    val = 2 * (val + SBITS (val, 1)) + 1;
+	    val = (val * quantizer_scale * quant_matrix[j]) / 32;
+
+	    // oddification
+	    val = (val + ~SBITS (val, 1)) | 1;
+
+	    SATURATE (val);
+	    dest[j] = val;
+
+	    DUMPBITS (bit_buf, bits, 8);
+	    NEEDBITS (bit_buf, bits, bit_ptr);
+
+	    continue;
+
+	} else if (bit_buf >= 0x02000000) {
+	    tab = DCT_B14_10 - 8 + UBITS (bit_buf, 10);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	} else if (bit_buf >= 0x00800000) {
+	    tab = DCT_13 - 16 + UBITS (bit_buf, 13);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	} else if (bit_buf >= 0x00200000) {
+	    tab = DCT_15 - 16 + UBITS (bit_buf, 15);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	} else {
+	    tab = DCT_16 + UBITS (bit_buf, 16);
+	    bit_buf <<= 16;
+	    GETWORD (bit_buf, bits + 16, bit_ptr);
+	    i += tab->run;
+	    if (i < 64)
+		goto normal_code;
+	}
+	break;	// illegal, but check needed to avoid buffer overflow
+    }
+    DUMPBITS (bit_buf, bits, 2);	// dump end of block code
+    slice->bitstream_buf = bit_buf;
+    slice->bitstream_bits = bits;
+    slice->bitstream_ptr = bit_ptr;
+}
+
+static inline int get_macroblock_address_increment (slice_t * slice)
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)
+#define bit_ptr (slice->bitstream_ptr)
+
+    MBAtab * tab;
+    int mba;
+
+    mba = 0;
+
+    while (1) {
+	if (bit_buf >= 0x10000000) {
+	    tab = MBA_5 - 2 + UBITS (bit_buf, 5);
+	    DUMPBITS (bit_buf, bits, tab->len);
+	    return mba + tab->mba;
+	} else if (bit_buf >= 0x03000000) {
+	    tab = MBA_11 - 24 + UBITS (bit_buf, 11);
+	    DUMPBITS (bit_buf, bits, tab->len);
+	    return mba + tab->mba;
+	} else switch (UBITS (bit_buf, 11)) {
+	case 8:		// macroblock_escape
+	    mba += 33;
+	    // no break here on purpose
+	case 15:	// macroblock_stuffing (MPEG1 only)
+	    DUMPBITS (bit_buf, bits, 11);
+	    NEEDBITS (bit_buf, bits, bit_ptr);
+	    break;
+	default:	// end of slice, or error
+	    return 0;
+	}
+    }
+
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static inline void slice_intra_DCT (picture_t * picture, slice_t * slice,
+				    int cc, uint8_t * dest, int stride)
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)  
+#define bit_ptr (slice->bitstream_ptr)
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    //Get the intra DC coefficient and inverse quantize it
+    if (cc == 0)
+	slice->dc_dct_pred[0] += get_luma_dc_dct_diff (slice);
+    else
+	slice->dc_dct_pred[cc] += get_chroma_dc_dct_diff (slice);
+    DCTblock[0] = slice->dc_dct_pred[cc] << (3 - picture->intra_dc_precision);
+
+    if (picture->mpeg1) {
+	if (picture->picture_coding_type != D_TYPE)
+	    get_mpeg1_intra_block (picture, slice, DCTblock);
+    } else if (picture->intra_vlc_format)
+	get_intra_block_B15 (picture, slice, DCTblock);
+    else
+	get_intra_block_B14 (picture, slice, DCTblock);
+    idct_block_copy (DCTblock, dest, stride);
+    memset (DCTblock, 0, sizeof (DCTblock));
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static inline void slice_non_intra_DCT (picture_t * picture, slice_t * slice,
+					uint8_t * dest, int stride)
+{
+    if (picture->mpeg1)
+	get_mpeg1_non_intra_block (picture, slice, DCTblock);
+    else
+	get_non_intra_block (picture, slice, DCTblock);
+    idct_block_add (DCTblock, dest, stride);
+    memset (DCTblock, 0, sizeof (DCTblock));
+}
+
+static inline void motion_block (void (** table) (uint8_t *, uint8_t *,
+						  int32_t, int32_t), 
+				 int x_pred, int y_pred,
+				 uint8_t * dest[3], int dest_offset,
+				 uint8_t * src[3], int src_offset,
+				 int stride, int height, int second_half)
+{
+    int xy_half;
+    uint8_t * src1;
+    uint8_t * src2;
+
+    xy_half = ((y_pred & 1) << 1) | (x_pred & 1);
+
+    src1 = src[0] + src_offset + (x_pred >> 1) + (y_pred >> 1) * stride +
+	second_half * (stride << 3);
+
+    table[xy_half] (dest[0] + dest_offset + second_half * (stride << 3),
+		    src1, stride, height);
+
+    x_pred /= 2;
+    y_pred /= 2;
+
+    xy_half = ((y_pred & 1) << 1) | (x_pred & 1);
+    stride >>= 1;
+    height >>= 1;
+    src_offset >>= 1;	src_offset += second_half * (stride << 2);
+    dest_offset >>= 1;	dest_offset += second_half * (stride << 2);
+
+    src1 = src[1] + src_offset + (x_pred >> 1) + (y_pred >> 1) * stride;
+    src2 = src[2] + src_offset + (x_pred >> 1) + (y_pred >> 1) * stride;
+
+    table[4+xy_half] (dest[1] + dest_offset, src1, stride, height);
+    table[4+xy_half] (dest[2] + dest_offset, src2, stride, height);
+}
+
+
+static void motion_mp1 (slice_t * slice, motion_t * motion,
+			uint8_t * dest[3], int offset, int width,
+			void (** table) (uint8_t *, uint8_t *, int, int))
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)
+#define bit_ptr (slice->bitstream_ptr)
+    int motion_x, motion_y;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]);
+    motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+    motion->pmv[0][0] = motion_x;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    motion_y = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[0]);
+    motion_y = bound_motion_vector (motion_y, motion->f_code[0]);
+    motion->pmv[0][1] = motion_y;
+
+    if (motion->f_code[1]) {
+	motion_x <<= 1;
+	motion_y <<= 1;
+    }
+
+    motion_block (table, motion_x, motion_y, dest, offset,
+		  motion->ref[0], offset, width, 16, 0);
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static void motion_mp1_reuse (slice_t * slice, motion_t * motion,
+			      uint8_t * dest[3], int offset, int width,
+			      void (** table) (uint8_t *, uint8_t *, int, int))
+{
+    int motion_x, motion_y;
+
+    motion_x = motion->pmv[0][0];
+    motion_y = motion->pmv[0][1];
+
+    if (motion->f_code[1]) {
+	motion_x <<= 1;
+	motion_y <<= 1;
+    }
+
+    motion_block (table, motion_x, motion_y, dest, offset,
+		  motion->ref[0], offset, width, 16, 0);
+}
+
+static void motion_fr_frame (slice_t * slice, motion_t * motion,
+			     uint8_t * dest[3], int offset, int width,
+			     void (** table) (uint8_t *, uint8_t *, int, int))
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)
+#define bit_ptr (slice->bitstream_ptr)
+    int motion_x, motion_y;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]);
+    motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+    motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    motion_y = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]);
+    motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
+    motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
+
+    motion_block (table, motion_x, motion_y, dest, offset,
+		  motion->ref[0], offset, width, 16, 0);
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static void motion_fr_field (slice_t * slice, motion_t * motion,
+			     uint8_t * dest[3], int offset, int width,
+			     void (** table) (uint8_t *, uint8_t *, int, int))
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)
+#define bit_ptr (slice->bitstream_ptr)
+    int motion_x, motion_y;
+    int field_select;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    field_select = SBITS (bit_buf, 1);
+    DUMPBITS (bit_buf, bits, 1);
+
+    motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]);
+    motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+    motion->pmv[0][0] = motion_x;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (slice,
+							    motion->f_code[1]);
+    //motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
+    motion->pmv[0][1] = motion_y << 1;
+
+    motion_block (table, motion_x, motion_y, dest, offset,
+		  motion->ref[0], offset + (field_select & width),
+		  width * 2, 8, 0);
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    field_select = SBITS (bit_buf, 1);
+    DUMPBITS (bit_buf, bits, 1);
+
+    motion_x = motion->pmv[1][0] + get_motion_delta (slice, motion->f_code[0]);
+    motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+    motion->pmv[1][0] = motion_x;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    motion_y = (motion->pmv[1][1] >> 1) + get_motion_delta (slice,
+							    motion->f_code[1]);
+    //motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
+    motion->pmv[1][1] = motion_y << 1;
+
+    motion_block (table, motion_x, motion_y, dest, offset + width,
+		  motion->ref[0], offset + (field_select & width),
+		  width * 2, 8, 0);
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static int motion_dmv_top_field_first;
+static void motion_fr_dmv (slice_t * slice, motion_t * motion,
+			   uint8_t * dest[3], int offset, int width,
+			   void (** table) (uint8_t *, uint8_t *, int, int))
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)
+#define bit_ptr (slice->bitstream_ptr)
+    int motion_x, motion_y;
+    int dmv_x, dmv_y;
+    int m;
+    int other_x, other_y;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]);
+    motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+    motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    dmv_x = get_dmv (slice);
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (slice,
+							    motion->f_code[1]);
+    //motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
+    motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    dmv_y = get_dmv (slice);
+
+    motion_block (mc_functions.put, motion_x, motion_y, dest, offset,
+		  motion->ref[0], offset, width * 2, 8, 0);
+
+    m = motion_dmv_top_field_first ? 1 : 3;
+    other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x;
+    other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1;
+    motion_block (mc_functions.avg, other_x, other_y, dest, offset,
+		  motion->ref[0], offset + width, width * 2, 8, 0);
+
+    motion_block (mc_functions.put, motion_x, motion_y, dest, offset + width,
+		  motion->ref[0], offset + width, width * 2, 8, 0);
+
+    m = motion_dmv_top_field_first ? 3 : 1;
+    other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x;
+    other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1;
+    motion_block (mc_functions.avg, other_x, other_y, dest, offset + width,
+		  motion->ref[0], offset, width * 2, 8, 0);
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+// like motion_frame, but reuse previous motion vectors
+static void motion_fr_reuse (slice_t * slice, motion_t * motion,
+			     uint8_t * dest[3], int offset, int width,
+			     void (** table) (uint8_t *, uint8_t *, int, int))
+{
+    motion_block (table, motion->pmv[0][0], motion->pmv[0][1], dest, offset,
+		  motion->ref[0], offset, width, 16, 0);
+}
+
+// like motion_frame, but use null motion vectors
+static void motion_fr_zero (slice_t * slice, motion_t * motion,
+			    uint8_t * dest[3], int offset, int width,
+			    void (** table) (uint8_t *, uint8_t *, int, int))
+{
+    motion_block (table, 0, 0, dest, offset,
+		  motion->ref[0], offset, width, 16, 0);
+}
+
+// like motion_frame, but parsing without actual motion compensation
+static void motion_fr_conceal (slice_t * slice, motion_t * motion)
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)
+#define bit_ptr (slice->bitstream_ptr)
+    int tmp;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    tmp = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]);
+    tmp = bound_motion_vector (tmp, motion->f_code[0]);
+    motion->pmv[1][0] = motion->pmv[0][0] = tmp;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    tmp = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]);
+    tmp = bound_motion_vector (tmp, motion->f_code[1]);
+    motion->pmv[1][1] = motion->pmv[0][1] = tmp;
+
+    DUMPBITS (bit_buf, bits, 1); // remove marker_bit
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static void motion_fi_field (slice_t * slice, motion_t * motion,
+			     uint8_t * dest[3], int offset, int width,
+			     void (** table) (uint8_t *, uint8_t *, int, int))
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)
+#define bit_ptr (slice->bitstream_ptr)
+    int motion_x, motion_y;
+    int field_select;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    field_select = UBITS (bit_buf, 1);
+    DUMPBITS (bit_buf, bits, 1);
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]);
+    motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+    motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    motion_y = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]);
+    motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
+    motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
+
+    motion_block (table, motion_x, motion_y, dest, offset,
+		  motion->ref[field_select], offset, width, 16, 0);
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static void motion_fi_16x8 (slice_t * slice, motion_t * motion,
+			    uint8_t * dest[3], int offset, int width,
+			    void (** table) (uint8_t *, uint8_t *, int, int))
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)
+#define bit_ptr (slice->bitstream_ptr)
+    int motion_x, motion_y;
+    int field_select;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    field_select = UBITS (bit_buf, 1);
+    DUMPBITS (bit_buf, bits, 1);
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]);
+    motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+    motion->pmv[0][0] = motion_x;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    motion_y = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]);
+    motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
+    motion->pmv[0][1] = motion_y;
+
+    motion_block (table, motion_x, motion_y, dest, offset,
+		  motion->ref[field_select], offset, width, 8, 0);
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    field_select = UBITS (bit_buf, 1);
+    DUMPBITS (bit_buf, bits, 1);
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    motion_x = motion->pmv[1][0] + get_motion_delta (slice, motion->f_code[0]);
+    motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+    motion->pmv[1][0] = motion_x;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    motion_y = motion->pmv[1][1] + get_motion_delta (slice, motion->f_code[1]);
+    motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
+    motion->pmv[1][1] = motion_y;
+
+    motion_block (table, motion_x, motion_y, dest, offset,
+		  motion->ref[field_select], offset, width, 8, 1);
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static int current_field = 0;
+static void motion_fi_dmv (slice_t * slice, motion_t * motion,
+			   uint8_t * dest[3], int offset, int width,
+			   void (** table) (uint8_t *, uint8_t *, int, int))
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)
+#define bit_ptr (slice->bitstream_ptr)
+    int motion_x, motion_y;
+    int dmv_x, dmv_y;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]);
+    motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
+    motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    dmv_x = get_dmv (slice);
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    motion_y = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]);
+    motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
+    motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    dmv_y = get_dmv (slice);
+
+    motion_block (mc_functions.put, motion_x, motion_y, dest, offset,
+		  motion->ref[current_field], offset, width, 16, 0);
+
+    motion_x = ((motion_x + (motion_x > 0)) >> 1) + dmv_x;
+    motion_y = ((motion_y + (motion_y > 0)) >> 1) + dmv_y +
+	2 * current_field - 1;
+    motion_block (mc_functions.avg, motion_x, motion_y, dest, offset,
+		  motion->ref[!current_field], offset, width, 16, 0);
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+static void motion_fi_reuse (slice_t * slice, motion_t * motion,
+			     uint8_t * dest[3], int offset, int width,
+			     void (** table) (uint8_t *, uint8_t *, int, int))
+{
+    motion_block (table, motion->pmv[0][0], motion->pmv[0][1], dest, offset,
+		  motion->ref[current_field], offset, width, 16, 0);
+}
+
+static void motion_fi_zero (slice_t * slice, motion_t * motion,
+			    uint8_t * dest[3], int offset, int width,
+			    void (** table) (uint8_t *, uint8_t *, int, int))
+{
+    motion_block (table, 0, 0, dest, offset,
+		  motion->ref[current_field], offset, width, 16, 0);
+}
+
+static void motion_fi_conceal (slice_t * slice, motion_t * motion)
+{
+#define bit_buf (slice->bitstream_buf)
+#define bits (slice->bitstream_bits)
+#define bit_ptr (slice->bitstream_ptr)
+    int tmp;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    DUMPBITS (bit_buf, bits, 1); // remove field_select
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    tmp = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]);
+    tmp = bound_motion_vector (tmp, motion->f_code[0]);
+    motion->pmv[1][0] = motion->pmv[0][0] = tmp;
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    tmp = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]);
+    tmp = bound_motion_vector (tmp, motion->f_code[1]);
+    motion->pmv[1][1] = motion->pmv[0][1] = tmp;
+
+    DUMPBITS (bit_buf, bits, 1); // remove marker_bit
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
+
+#define MOTION(routine,direction,slice,dest,offset,stride)		\
+do {									\
+    if ((direction) & MACROBLOCK_MOTION_FORWARD)			\
+	routine (&slice, &((slice).f_motion), dest, offset, stride,	\
+		 mc_functions.put);					\
+    if ((direction) & MACROBLOCK_MOTION_BACKWARD)			\
+	routine (&slice, &((slice).b_motion), dest, offset, stride,	\
+		 ((direction) & MACROBLOCK_MOTION_FORWARD ?		\
+		  mc_functions.avg : mc_functions.put));		\
+} while (0)
+
+#define CHECK_DISPLAY					\
+do {							\
+    if (offset == width) {				\
+	slice.f_motion.ref[0][0] += 16 * offset;	\
+	slice.f_motion.ref[0][1] += 4 * offset;		\
+	slice.f_motion.ref[0][2] += 4 * offset;		\
+	slice.b_motion.ref[0][0] += 16 * offset;	\
+	slice.b_motion.ref[0][1] += 4 * offset;		\
+	slice.b_motion.ref[0][2] += 4 * offset;		\
+	dest[0] += 16 * offset;				\
+	dest[1] += 4 * offset;				\
+	dest[2] += 4 * offset;				\
+	offset = 0; ++ypos;				\
+    }							\
+} while (0)
+
+int slice_process (picture_t * picture, uint8_t code, uint8_t * buffer)
+{
+#define bit_buf (slice.bitstream_buf)
+#define bits (slice.bitstream_bits)
+#define bit_ptr (slice.bitstream_ptr)
+    slice_t slice;
+    int macroblock_modes;
+    int width;
+    int ypos=code-1;
+    uint8_t * dest[3];
+    int offset;
+    uint8_t ** forward_ref[2];
+
+    width = picture->coded_picture_width;
+    offset = ypos * width * 4;
+
+    forward_ref[0] = picture->forward_reference_frame;
+    if (picture->picture_structure != FRAME_PICTURE) {
+	offset <<= 1;
+	forward_ref[1] = picture->forward_reference_frame;
+	current_field = (picture->picture_structure == BOTTOM_FIELD);
+	if ((picture->second_field) &&
+	    (picture->picture_coding_type != B_TYPE))
+	    forward_ref[picture->picture_structure == TOP_FIELD] =
+		picture->current_frame;
+	slice.f_motion.ref[1][0] = forward_ref[1][0] + offset * 4 + width;
+	slice.f_motion.ref[1][1] = forward_ref[1][1] + offset + (width >> 1);
+	slice.f_motion.ref[1][2] = forward_ref[1][2] + offset + (width >> 1);
+	slice.b_motion.ref[1][0] =
+	    picture->backward_reference_frame[0] + offset * 4 + width;
+	slice.b_motion.ref[1][1] =
+	    picture->backward_reference_frame[1] + offset + (width >> 1);
+	slice.b_motion.ref[1][2] =
+	    picture->backward_reference_frame[2] + offset + (width >> 1);
+    }
+
+    slice.f_motion.ref[0][0] = forward_ref[0][0] + offset * 4;
+    slice.f_motion.ref[0][1] = forward_ref[0][1] + offset;
+    slice.f_motion.ref[0][2] = forward_ref[0][2] + offset;
+    slice.f_motion.f_code[0] = picture->f_code[0][0];
+    slice.f_motion.f_code[1] = picture->f_code[0][1];
+    slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0;
+    slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0;
+    slice.b_motion.ref[0][0] =
+	picture->backward_reference_frame[0] + offset * 4;
+    slice.b_motion.ref[0][1] =
+	picture->backward_reference_frame[1] + offset;
+    slice.b_motion.ref[0][2] =
+	picture->backward_reference_frame[2] + offset;
+    slice.b_motion.f_code[0] = picture->f_code[1][0];
+    slice.b_motion.f_code[1] = picture->f_code[1][1];
+    slice.b_motion.pmv[0][0] = slice.b_motion.pmv[0][1] = 0;
+    slice.b_motion.pmv[1][0] = slice.b_motion.pmv[1][1] = 0;
+
+    if ((! HACK_MODE) && (!picture->mpeg1) &&
+	(picture->picture_coding_type == B_TYPE))
+	offset = 0;
+
+    dest[0] = picture->current_frame[0] + offset * 4;
+    dest[1] = picture->current_frame[1] + offset;
+    dest[2] = picture->current_frame[2] + offset;
+
+    switch (picture->picture_structure) {
+    case BOTTOM_FIELD:
+	dest[0] += width;
+	dest[1] += width >> 1;
+	dest[2] += width >> 1;
+	// follow thru
+    case TOP_FIELD:
+	width <<= 1;
+    }
+
+    //reset intra dc predictor
+    slice.dc_dct_pred[0]=slice.dc_dct_pred[1]=slice.dc_dct_pred[2]= 
+	1<< (picture->intra_dc_precision + 7) ;
+
+    bitstream_init (&slice, buffer);
+
+    slice.quantizer_scale = get_quantizer_scale (&slice,
+						 picture->q_scale_type);
+
+    //Ignore intra_slice and all the extra data
+    while (bit_buf & 0x80000000) {
+	DUMPBITS (bit_buf, bits, 9);
+	NEEDBITS (bit_buf, bits, bit_ptr);
+    }
+    DUMPBITS (bit_buf, bits, 1);
+
+    NEEDBITS (bit_buf, bits, bit_ptr);
+    offset = get_macroblock_address_increment (&slice) << 4;
+
+    while (1) {
+	NEEDBITS (bit_buf, bits, bit_ptr);
+
+	macroblock_modes =
+	    get_macroblock_modes (&slice, picture->picture_structure,
+				  picture->picture_coding_type,
+				  picture->frame_pred_frame_dct);
+
+	// maybe integrate MACROBLOCK_QUANT test into get_macroblock_modes ?
+	if (macroblock_modes & MACROBLOCK_QUANT)
+	    slice.quantizer_scale =
+		get_quantizer_scale (&slice, picture->q_scale_type);
+
+	if (macroblock_modes & MACROBLOCK_INTRA) {
+
+	    int DCT_offset, DCT_stride;
+
+	    if (picture->concealment_motion_vectors) {
+		if (picture->picture_structure == FRAME_PICTURE)
+		    motion_fr_conceal (&slice, &slice.f_motion);
+		else
+		    motion_fi_conceal (&slice, &slice.f_motion);
+	    } else {
+		slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0;
+		slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0;
+		slice.b_motion.pmv[0][0] = slice.b_motion.pmv[0][1] = 0;
+		slice.b_motion.pmv[1][0] = slice.b_motion.pmv[1][1] = 0;
+	    }
+
+	    if (macroblock_modes & DCT_TYPE_INTERLACED) {
+		DCT_offset = width;
+		DCT_stride = width * 2;
+	    } else {
+		DCT_offset = width * 8;
+		DCT_stride = width;
+	    }
+
+	    // Decode lum blocks
+	    slice_intra_DCT (picture, &slice, 0,
+			     dest[0] + offset, DCT_stride);
+	    slice_intra_DCT (picture, &slice, 0,
+			     dest[0] + offset + 8, DCT_stride);
+	    slice_intra_DCT (picture, &slice, 0,
+			     dest[0] + offset + DCT_offset, DCT_stride);
+	    slice_intra_DCT (picture, &slice, 0,
+			     dest[0] + offset + DCT_offset + 8, DCT_stride);
+
+	    // Decode chroma blocks
+	    slice_intra_DCT (picture, &slice, 1,
+			     dest[1] + (offset>>1), width>>1);
+	    slice_intra_DCT (picture, &slice, 2,
+			     dest[2] + (offset>>1), width>>1);
+
+	    if (picture->picture_coding_type == D_TYPE) {
+		NEEDBITS (bit_buf, bits, bit_ptr);
+		DUMPBITS (bit_buf, bits, 1);
+	    }
+	} else {
+
+	    if (picture->mpeg1) {
+		if ((macroblock_modes & MOTION_TYPE_MASK) == MC_FRAME)
+		    MOTION (motion_mp1, macroblock_modes, slice,
+			    dest, offset,width);
+		else {
+		    // non-intra mb without forward mv in a P picture
+		    slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0;
+		    slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0;
+
+		    MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD, slice,
+			    dest, offset, width);
+		}
+	    } else if (picture->picture_structure == FRAME_PICTURE)
+		switch (macroblock_modes & MOTION_TYPE_MASK) {
+		case MC_FRAME:
+		    MOTION (motion_fr_frame, macroblock_modes, slice,
+			    dest, offset, width);
+		    break;
+
+		case MC_FIELD:
+		    MOTION (motion_fr_field, macroblock_modes, slice,
+			    dest, offset, width);
+		    break;
+
+		case MC_DMV:
+		    motion_dmv_top_field_first = picture->top_field_first;
+		    MOTION (motion_fr_dmv, MACROBLOCK_MOTION_FORWARD, slice,
+			    dest, offset, width);
+		    break;
+
+		case 0:
+		    // non-intra mb without forward mv in a P picture
+		    slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0;
+		    slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0;
+
+		    MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD, slice,
+			    dest, offset, width);
+		    break;
+		}
+	    else
+		switch (macroblock_modes & MOTION_TYPE_MASK) {
+		case MC_FIELD:
+		    MOTION (motion_fi_field, macroblock_modes, slice,
+			    dest, offset, width);
+		    break;
+
+		case MC_16X8:
+		    MOTION (motion_fi_16x8, macroblock_modes, slice,
+			    dest, offset, width);
+		    break;
+
+		case MC_DMV:
+		    motion_dmv_top_field_first = picture->top_field_first;
+		    MOTION (motion_fi_dmv, MACROBLOCK_MOTION_FORWARD, slice,
+			    dest, offset, width);
+		    break;
+
+		case 0:
+		    // non-intra mb without forward mv in a P picture
+		    slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0;
+		    slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0;
+
+		    MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD, slice,
+			    dest, offset, width);
+		    break;
+		}
+
+	    //6.3.17.4 Coded block pattern
+	    if (macroblock_modes & MACROBLOCK_PATTERN) {
+		int coded_block_pattern;
+		int DCT_offset, DCT_stride;
+
+		if (macroblock_modes & DCT_TYPE_INTERLACED) {
+		    DCT_offset = width;
+		    DCT_stride = width * 2;
+		} else {
+		    DCT_offset = width * 8;
+		    DCT_stride = width;
+		}
+
+		coded_block_pattern = get_coded_block_pattern (&slice);
+
+		// Decode lum blocks
+
+		if (coded_block_pattern & 0x20)
+		    slice_non_intra_DCT (picture, &slice,
+					 dest[0] + offset, DCT_stride);
+		if (coded_block_pattern & 0x10)
+		    slice_non_intra_DCT (picture, &slice,
+					 dest[0] + offset + 8, DCT_stride);
+		if (coded_block_pattern & 0x08)
+		    slice_non_intra_DCT (picture, &slice,
+					 dest[0] + offset + DCT_offset,
+					 DCT_stride);
+		if (coded_block_pattern & 0x04)
+		    slice_non_intra_DCT (picture, &slice,
+					 dest[0] + offset + DCT_offset + 8,
+					 DCT_stride);
+
+		// Decode chroma blocks
+
+		if (coded_block_pattern & 0x2)
+		    slice_non_intra_DCT (picture, &slice,
+					 dest[1] + (offset>>1), width >> 1);
+		if (coded_block_pattern & 0x1)
+		    slice_non_intra_DCT (picture, &slice,
+					 dest[2] + (offset>>1), width >> 1);
+	    }
+
+	    slice.dc_dct_pred[0]=slice.dc_dct_pred[1]=slice.dc_dct_pred[2]=
+		1 << (picture->intra_dc_precision + 7);
+	}
+
+//        printf("[%d]",slice.quantizer_scale);
+//        printf("[%d,%d]",offset>>4,ypos);
+	quant_store[ypos+1][(offset>>4)+1] = slice.quantizer_scale;
+
+	offset += 16;
+	CHECK_DISPLAY;
+
+	NEEDBITS (bit_buf, bits, bit_ptr);
+
+	if (bit_buf & 0x80000000) {
+	    DUMPBITS (bit_buf, bits, 1);
+	} else {
+	    int mba_inc;
+
+	    mba_inc = get_macroblock_address_increment (&slice);
+	    if (!mba_inc)
+		break;
+
+	    //reset intra dc predictor on skipped block
+	    slice.dc_dct_pred[0]=slice.dc_dct_pred[1]=slice.dc_dct_pred[2]=
+		1<< (picture->intra_dc_precision + 7);
+
+	    //handling of skipped mb's differs between P_TYPE and B_TYPE
+	    //pictures
+	    if (picture->picture_coding_type == P_TYPE) {
+		slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0;
+		slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0;
+
+		do {
+		    if (picture->picture_structure == FRAME_PICTURE)
+			MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD,
+				slice, dest, offset, width);
+		    else
+			MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD,
+				slice, dest, offset, width);
+
+	quant_store[ypos+1][(offset>>4)+1] = slice.quantizer_scale;
+//        printf("[%d,%d]",offset>>4,ypos);
+		    offset += 16;
+		    CHECK_DISPLAY;
+		} while (--mba_inc);
+	    } else {
+		do {
+		    if (picture->mpeg1)
+			MOTION (motion_mp1_reuse, macroblock_modes,
+				slice, dest, offset, width);
+		    else if (picture->picture_structure == FRAME_PICTURE)
+			MOTION (motion_fr_reuse, macroblock_modes,
+				slice, dest, offset, width);
+		    else
+			MOTION (motion_fi_reuse, macroblock_modes,
+				slice, dest, offset, width);
+
+	quant_store[ypos+1][(offset>>4)+1] = slice.quantizer_scale;
+//        printf("[%d,%d]",offset>>4,ypos);
+		    offset += 16;
+		    CHECK_DISPLAY;
+		} while (--mba_inc);
+	    }
+	}
+    }
+
+    return 0;
+#undef bit_buf
+#undef bits
+#undef bit_ptr
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/sse.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,256 @@
+/*
+ * sse.h
+ * Copyright (C) 1999 R. Fisher
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *
+ * mpeg2dec 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.
+ *
+ * mpeg2dec 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+typedef	union {
+	float			sf[4];	/* Single-precision (32-bit) value */
+} ATTR_ALIGN(16) sse_t;	/* On a 16 byte (128-bit) boundary */
+
+
+#define	sse_i2r(op, imm, reg) \
+	__asm__ __volatile__ (#op " %0, %%" #reg \
+			      : /* nothing */ \
+			      : "X" (imm) )
+
+#define	sse_m2r(op, mem, reg) \
+	__asm__ __volatile__ (#op " %0, %%" #reg \
+			      : /* nothing */ \
+			      : "X" (mem))
+
+#define	sse_r2m(op, reg, mem) \
+	__asm__ __volatile__ (#op " %%" #reg ", %0" \
+			      : "=X" (mem) \
+			      : /* nothing */ )
+
+#define	sse_r2r(op, regs, regd) \
+	__asm__ __volatile__ (#op " %" #regs ", %" #regd)
+
+#define	sse_r2ri(op, regs, regd, imm) \
+	__asm__ __volatile__ (#op " %0, %%" #regs ", %%" #regd \
+			      : /* nothing */ \
+			      : "X" (imm) )
+
+#define	sse_m2ri(op, mem, reg, subop) \
+	__asm__ __volatile__ (#op " %0, %%" #reg ", " #subop \
+			      : /* nothing */ \
+			      : "X" (mem))
+
+
+#define	movaps_m2r(var, reg)	sse_m2r(movaps, var, reg)
+#define	movaps_r2m(reg, var)	sse_r2m(movaps, reg, var)
+#define	movaps_r2r(regs, regd)	sse_r2r(movaps, regs, regd)
+
+#define	movntps_r2m(xmmreg, var)	sse_r2m(movntps, xmmreg, var)
+
+#define	movups_m2r(var, reg)	sse_m2r(movups, var, reg)
+#define	movups_r2m(reg, var)	sse_r2m(movups, reg, var)
+#define	movups_r2r(regs, regd)	sse_r2r(movups, regs, regd)
+
+#define	movhlps_r2r(regs, regd)	sse_r2r(movhlps, regs, regd)
+
+#define	movlhps_r2r(regs, regd)	sse_r2r(movlhps, regs, regd)
+
+#define	movhps_m2r(var, reg)	sse_m2r(movhps, var, reg)
+#define	movhps_r2m(reg, var)	sse_r2m(movhps, reg, var)
+
+#define	movlps_m2r(var, reg)	sse_m2r(movlps, var, reg)
+#define	movlps_r2m(reg, var)	sse_r2m(movlps, reg, var)
+
+#define	movss_m2r(var, reg)	sse_m2r(movss, var, reg)
+#define	movss_r2m(reg, var)	sse_r2m(movss, reg, var)
+#define	movss_r2r(regs, regd)	sse_r2r(movss, regs, regd)
+
+#define	shufps_m2r(var, reg, index)	sse_m2ri(shufps, var, reg, index)
+#define	shufps_r2r(regs, regd, index)	sse_r2ri(shufps, regs, regd, index)
+
+#define	cvtpi2ps_m2r(var, xmmreg)	sse_m2r(cvtpi2ps, var, xmmreg)
+#define	cvtpi2ps_r2r(mmreg, xmmreg)	sse_r2r(cvtpi2ps, mmreg, xmmreg)
+
+#define	cvtps2pi_m2r(var, mmreg)	sse_m2r(cvtps2pi, var, mmreg)
+#define	cvtps2pi_r2r(xmmreg, mmreg)	sse_r2r(cvtps2pi, mmreg, xmmreg)
+
+#define	cvttps2pi_m2r(var, mmreg)	sse_m2r(cvttps2pi, var, mmreg)
+#define	cvttps2pi_r2r(xmmreg, mmreg)	sse_r2r(cvttps2pi, mmreg, xmmreg)
+
+#define	cvtsi2ss_m2r(var, xmmreg)	sse_m2r(cvtsi2ss, var, xmmreg)
+#define	cvtsi2ss_r2r(reg, xmmreg)	sse_r2r(cvtsi2ss, reg, xmmreg)
+
+#define	cvtss2si_m2r(var, reg)		sse_m2r(cvtss2si, var, reg)
+#define	cvtss2si_r2r(xmmreg, reg)	sse_r2r(cvtss2si, xmmreg, reg)
+
+#define	cvttss2si_m2r(var, reg)		sse_m2r(cvtss2si, var, reg)
+#define	cvttss2si_r2r(xmmreg, reg)	sse_r2r(cvtss2si, xmmreg, reg)
+
+#define	movmskps(xmmreg, reg) \
+	__asm__ __volatile__ ("movmskps %" #xmmreg ", %" #reg)
+
+#define	addps_m2r(var, reg)		sse_m2r(addps, var, reg)
+#define	addps_r2r(regs, regd)		sse_r2r(addps, regs, regd)
+
+#define	addss_m2r(var, reg)		sse_m2r(addss, var, reg)
+#define	addss_r2r(regs, regd)		sse_r2r(addss, regs, regd)
+
+#define	subps_m2r(var, reg)		sse_m2r(subps, var, reg)
+#define	subps_r2r(regs, regd)		sse_r2r(subps, regs, regd)
+
+#define	subss_m2r(var, reg)		sse_m2r(subss, var, reg)
+#define	subss_r2r(regs, regd)		sse_r2r(subss, regs, regd)
+
+#define	mulps_m2r(var, reg)		sse_m2r(mulps, var, reg)
+#define	mulps_r2r(regs, regd)		sse_r2r(mulps, regs, regd)
+
+#define	mulss_m2r(var, reg)		sse_m2r(mulss, var, reg)
+#define	mulss_r2r(regs, regd)		sse_r2r(mulss, regs, regd)
+
+#define	divps_m2r(var, reg)		sse_m2r(divps, var, reg)
+#define	divps_r2r(regs, regd)		sse_r2r(divps, regs, regd)
+
+#define	divss_m2r(var, reg)		sse_m2r(divss, var, reg)
+#define	divss_r2r(regs, regd)		sse_r2r(divss, regs, regd)
+
+#define	rcpps_m2r(var, reg)		sse_m2r(rcpps, var, reg)
+#define	rcpps_r2r(regs, regd)		sse_r2r(rcpps, regs, regd)
+
+#define	rcpss_m2r(var, reg)		sse_m2r(rcpss, var, reg)
+#define	rcpss_r2r(regs, regd)		sse_r2r(rcpss, regs, regd)
+
+#define	rsqrtps_m2r(var, reg)		sse_m2r(rsqrtps, var, reg)
+#define	rsqrtps_r2r(regs, regd)		sse_r2r(rsqrtps, regs, regd)
+
+#define	rsqrtss_m2r(var, reg)		sse_m2r(rsqrtss, var, reg)
+#define	rsqrtss_r2r(regs, regd)		sse_r2r(rsqrtss, regs, regd)
+
+#define	sqrtps_m2r(var, reg)		sse_m2r(sqrtps, var, reg)
+#define	sqrtps_r2r(regs, regd)		sse_r2r(sqrtps, regs, regd)
+
+#define	sqrtss_m2r(var, reg)		sse_m2r(sqrtss, var, reg)
+#define	sqrtss_r2r(regs, regd)		sse_r2r(sqrtss, regs, regd)
+
+#define	andps_m2r(var, reg)		sse_m2r(andps, var, reg)
+#define	andps_r2r(regs, regd)		sse_r2r(andps, regs, regd)
+
+#define	andnps_m2r(var, reg)		sse_m2r(andnps, var, reg)
+#define	andnps_r2r(regs, regd)		sse_r2r(andnps, regs, regd)
+
+#define	orps_m2r(var, reg)		sse_m2r(orps, var, reg)
+#define	orps_r2r(regs, regd)		sse_r2r(orps, regs, regd)
+
+#define	xorps_m2r(var, reg)		sse_m2r(xorps, var, reg)
+#define	xorps_r2r(regs, regd)		sse_r2r(xorps, regs, regd)
+
+#define	maxps_m2r(var, reg)		sse_m2r(maxps, var, reg)
+#define	maxps_r2r(regs, regd)		sse_r2r(maxps, regs, regd)
+
+#define	maxss_m2r(var, reg)		sse_m2r(maxss, var, reg)
+#define	maxss_r2r(regs, regd)		sse_r2r(maxss, regs, regd)
+
+#define	minps_m2r(var, reg)		sse_m2r(minps, var, reg)
+#define	minps_r2r(regs, regd)		sse_r2r(minps, regs, regd)
+
+#define	minss_m2r(var, reg)		sse_m2r(minss, var, reg)
+#define	minss_r2r(regs, regd)		sse_r2r(minss, regs, regd)
+
+#define	cmpps_m2r(var, reg, op)		sse_m2ri(cmpps, var, reg, op)
+#define	cmpps_r2r(regs, regd, op)	sse_r2ri(cmpps, regs, regd, op)
+
+#define	cmpeqps_m2r(var, reg)		sse_m2ri(cmpps, var, reg, 0)
+#define	cmpeqps_r2r(regs, regd)		sse_r2ri(cmpps, regs, regd, 0)
+
+#define	cmpltps_m2r(var, reg)		sse_m2ri(cmpps, var, reg, 1)
+#define	cmpltps_r2r(regs, regd)		sse_r2ri(cmpps, regs, regd, 1)
+
+#define	cmpleps_m2r(var, reg)		sse_m2ri(cmpps, var, reg, 2)
+#define	cmpleps_r2r(regs, regd)		sse_r2ri(cmpps, regs, regd, 2)
+
+#define	cmpunordps_m2r(var, reg)	sse_m2ri(cmpps, var, reg, 3)
+#define	cmpunordps_r2r(regs, regd)	sse_r2ri(cmpps, regs, regd, 3)
+
+#define	cmpneqps_m2r(var, reg)		sse_m2ri(cmpps, var, reg, 4)
+#define	cmpneqps_r2r(regs, regd)	sse_r2ri(cmpps, regs, regd, 4)
+
+#define	cmpnltps_m2r(var, reg)		sse_m2ri(cmpps, var, reg, 5)
+#define	cmpnltps_r2r(regs, regd)	sse_r2ri(cmpps, regs, regd, 5)
+
+#define	cmpnleps_m2r(var, reg)		sse_m2ri(cmpps, var, reg, 6)
+#define	cmpnleps_r2r(regs, regd)	sse_r2ri(cmpps, regs, regd, 6)
+
+#define	cmpordps_m2r(var, reg)		sse_m2ri(cmpps, var, reg, 7)
+#define	cmpordps_r2r(regs, regd)	sse_r2ri(cmpps, regs, regd, 7)
+
+#define	cmpss_m2r(var, reg, op)		sse_m2ri(cmpss, var, reg, op)
+#define	cmpss_r2r(regs, regd, op)	sse_r2ri(cmpss, regs, regd, op)
+
+#define	cmpeqss_m2r(var, reg)		sse_m2ri(cmpss, var, reg, 0)
+#define	cmpeqss_r2r(regs, regd)		sse_r2ri(cmpss, regs, regd, 0)
+
+#define	cmpltss_m2r(var, reg)		sse_m2ri(cmpss, var, reg, 1)
+#define	cmpltss_r2r(regs, regd)		sse_r2ri(cmpss, regs, regd, 1)
+
+#define	cmpless_m2r(var, reg)		sse_m2ri(cmpss, var, reg, 2)
+#define	cmpless_r2r(regs, regd)		sse_r2ri(cmpss, regs, regd, 2)
+
+#define	cmpunordss_m2r(var, reg)	sse_m2ri(cmpss, var, reg, 3)
+#define	cmpunordss_r2r(regs, regd)	sse_r2ri(cmpss, regs, regd, 3)
+
+#define	cmpneqss_m2r(var, reg)		sse_m2ri(cmpss, var, reg, 4)
+#define	cmpneqss_r2r(regs, regd)	sse_r2ri(cmpss, regs, regd, 4)
+
+#define	cmpnltss_m2r(var, reg)		sse_m2ri(cmpss, var, reg, 5)
+#define	cmpnltss_r2r(regs, regd)	sse_r2ri(cmpss, regs, regd, 5)
+
+#define	cmpnless_m2r(var, reg)		sse_m2ri(cmpss, var, reg, 6)
+#define	cmpnless_r2r(regs, regd)	sse_r2ri(cmpss, regs, regd, 6)
+
+#define	cmpordss_m2r(var, reg)		sse_m2ri(cmpss, var, reg, 7)
+#define	cmpordss_r2r(regs, regd)	sse_r2ri(cmpss, regs, regd, 7)
+
+#define	comiss_m2r(var, reg)		sse_m2r(comiss, var, reg)
+#define	comiss_r2r(regs, regd)		sse_r2r(comiss, regs, regd)
+
+#define	ucomiss_m2r(var, reg)		sse_m2r(ucomiss, var, reg)
+#define	ucomiss_r2r(regs, regd)		sse_r2r(ucomiss, regs, regd)
+
+#define	unpcklps_m2r(var, reg)		sse_m2r(unpcklps, var, reg)
+#define	unpcklps_r2r(regs, regd)	sse_r2r(unpcklps, regs, regd)
+
+#define	unpckhps_m2r(var, reg)		sse_m2r(unpckhps, var, reg)
+#define	unpckhps_r2r(regs, regd)	sse_r2r(unpckhps, regs, regd)
+
+#define	fxrstor(mem) \
+	__asm__ __volatile__ ("fxrstor %0" \
+			      : /* nothing */ \
+			      : "X" (mem))
+
+#define	fxsave(mem) \
+	__asm__ __volatile__ ("fxsave %0" \
+			      : /* nothing */ \
+			      : "X" (mem))
+
+#define	stmxcsr(mem) \
+	__asm__ __volatile__ ("stmxcsr %0" \
+			      : /* nothing */ \
+			      : "X" (mem))
+
+#define	ldmxcsr(mem) \
+	__asm__ __volatile__ ("ldmxcsr %0" \
+			      : /* nothing */ \
+			      : "X" (mem))
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/stats.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,316 @@
+/*
+ * stats.c
+ * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *
+ * mpeg2dec 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.
+ *
+ * mpeg2dec 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+#include "mpeg2_internal.h"
+
+static int debug_level = -1;
+
+// Determine is debug output is required.
+// We could potentially have multiple levels of debug info
+static int debug_is_on (void)
+{
+    char * env_var;
+	
+    if (debug_level < 0) {
+	env_var = getenv ("MPEG2_DEBUG");
+
+	if (env_var)
+	    debug_level = 1;
+	else
+	    debug_level = 0;
+    }
+	
+    return debug_level;
+}
+
+static void stats_picture (uint8_t * buffer)
+{
+    static char * picture_coding_type_str [8] = {
+	"Invalid picture type",
+	"I-type",
+	"P-type",
+	"B-type",
+	"D (very bad)",
+	"Invalid","Invalid","Invalid"
+    };
+
+    int picture_coding_type;
+    int temporal_reference;
+    int vbv_delay;
+
+    temporal_reference = (buffer[0] << 2) | (buffer[1] >> 6);
+    picture_coding_type = (buffer [1] >> 3) & 7;
+    vbv_delay = ((buffer[1] << 13) | (buffer[2] << 5) |
+		 (buffer[3] >> 3)) & 0xffff;
+
+    fprintf (stderr, " (picture) %s temporal_reference %d, vbv_delay %d\n",
+	     picture_coding_type_str [picture_coding_type],
+	     temporal_reference, vbv_delay);
+}
+
+static void stats_user_data (uint8_t * buffer)
+{
+    fprintf (stderr, " (user_data)\n");
+}
+
+static void stats_sequence (uint8_t * buffer)
+{
+    static char * aspect_ratio_information_str[8] = {
+	"Invalid Aspect Ratio",
+	"1:1",
+	"4:3",
+	"16:9",
+	"2.21:1",
+	"Invalid Aspect Ratio",
+	"Invalid Aspect Ratio",
+	"Invalid Aspect Ratio"
+    };
+    static char * frame_rate_str[16] = {
+	"Invalid frame_rate_code",
+	"23.976", "24", "25" , "29.97",
+	"30" , "50", "59.94", "60" ,
+	"Invalid frame_rate_code", "Invalid frame_rate_code",
+	"Invalid frame_rate_code", "Invalid frame_rate_code",
+	"Invalid frame_rate_code", "Invalid frame_rate_code",
+	"Invalid frame_rate_code"
+    };
+
+    int horizontal_size;
+    int vertical_size;
+    int aspect_ratio_information;
+    int frame_rate_code;
+    int bit_rate_value;
+    int vbv_buffer_size_value;
+    int constrained_parameters_flag;
+    int load_intra_quantizer_matrix;
+    int load_non_intra_quantizer_matrix;
+
+    vertical_size = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
+    horizontal_size = vertical_size >> 12;
+    vertical_size &= 0xfff;
+    aspect_ratio_information = buffer[3] >> 4;
+    frame_rate_code = buffer[3] & 15;
+    bit_rate_value = (buffer[4] << 10) | (buffer[5] << 2) | (buffer[6] >> 6);
+    vbv_buffer_size_value = ((buffer[6] << 5) | (buffer[7] >> 3)) & 0x3ff;
+    constrained_parameters_flag = buffer[7] & 4;
+    load_intra_quantizer_matrix = buffer[7] & 2;
+    if (load_intra_quantizer_matrix)
+	buffer += 64;
+    load_non_intra_quantizer_matrix = buffer[7] & 1;
+
+    fprintf (stderr, " (seq) %dx%d %s, %s fps, %5.0f kbps, VBV %d kB%s%s%s\n",
+	     horizontal_size, vertical_size,
+	     aspect_ratio_information_str [aspect_ratio_information],
+	     frame_rate_str [frame_rate_code],
+	     bit_rate_value * 400.0 / 1000.0,
+	     2 * vbv_buffer_size_value,
+	     constrained_parameters_flag ? " , CP":"",
+	     load_intra_quantizer_matrix ? " , Custom Intra Matrix":"",
+	     load_non_intra_quantizer_matrix ? " , Custom Non-Intra Matrix":"");
+}
+
+static void stats_sequence_error (uint8_t * buffer)
+{
+    fprintf (stderr, " (sequence_error)\n");
+}
+
+static void stats_sequence_end (uint8_t * buffer)
+{
+    fprintf (stderr, " (sequence_end)\n");
+}
+
+static void stats_group (uint8_t * buffer)
+{
+    fprintf (stderr, " (group)%s%s\n",
+	     (buffer[4] & 0x40) ? " closed_gop" : "",
+	     (buffer[4] & 0x20) ? " broken_link" : "");
+}
+
+static void stats_slice (uint8_t code, uint8_t * buffer)
+{
+    //fprintf (stderr, " (slice %d)\n", code);
+}
+
+static void stats_sequence_extension (uint8_t * buffer)
+{
+    static char * chroma_format_str[4] = {
+	"Invalid Chroma Format",
+	"4:2:0 Chroma",
+	"4:2:2 Chroma",
+	"4:4:4 Chroma"
+    };
+
+    int progressive_sequence;
+    int chroma_format;
+
+    progressive_sequence = (buffer[1] >> 3) & 1;
+    chroma_format = (buffer[1] >> 1) & 3;
+
+    fprintf (stderr, " (seq_ext) progressive_sequence %d, %s\n",
+	     progressive_sequence, chroma_format_str [chroma_format]);
+}
+
+static void stats_sequence_display_extension (uint8_t * buffer)
+{
+    fprintf (stderr, " (sequence_display_extension)\n");
+}
+
+static void stats_quant_matrix_extension (uint8_t * buffer)
+{
+    fprintf (stderr, " (quant_matrix_extension)\n");
+}
+
+static void stats_copyright_extension (uint8_t * buffer)
+{
+    fprintf (stderr, " (copyright_extension)\n");
+}
+
+
+static void stats_sequence_scalable_extension (uint8_t * buffer)
+{
+    fprintf (stderr, " (sequence_scalable_extension)\n");
+}
+
+static void stats_picture_display_extension (uint8_t * buffer)
+{
+    fprintf (stderr, " (picture_display_extension)\n");
+}
+
+static void stats_picture_coding_extension (uint8_t * buffer)
+{
+    static char * picture_structure_str[4] = {
+	"Invalid Picture Structure",
+	"Top field",
+	"Bottom field",
+	"Frame Picture"
+    };
+
+    int f_code[2][2];
+    int intra_dc_precision;
+    int picture_structure;
+    int top_field_first;
+    int frame_pred_frame_dct;
+    int concealment_motion_vectors;
+    int q_scale_type;
+    int intra_vlc_format;
+    int alternate_scan;
+    int repeat_first_field;
+    int progressive_frame;
+
+    f_code[0][0] = buffer[0] & 15;
+    f_code[0][1] = buffer[1] >> 4;
+    f_code[1][0] = buffer[1] & 15;
+    f_code[1][1] = buffer[2] >> 4;
+    intra_dc_precision = (buffer[2] >> 2) & 3;
+    picture_structure = buffer[2] & 3;
+    top_field_first = buffer[3] >> 7;
+    frame_pred_frame_dct = (buffer[3] >> 6) & 1;
+    concealment_motion_vectors = (buffer[3] >> 5) & 1;
+    q_scale_type = (buffer[3] >> 4) & 1;
+    intra_vlc_format = (buffer[3] >> 3) & 1;
+    alternate_scan = (buffer[3] >> 2) & 1;
+    repeat_first_field = (buffer[3] >> 1) & 1;
+    progressive_frame = buffer[4] >> 7;
+
+    fprintf (stderr,
+	     " (pic_ext) %s\n", picture_structure_str [picture_structure]);
+    fprintf (stderr,
+	     " (pic_ext) forward horizontal f_code % d, forward vertical f_code % d\n",
+	     f_code[0][0], f_code[0][1]);
+    fprintf (stderr,
+	     " (pic_ext) backward horizontal f_code % d, backward vertical f_code % d\n", 
+	     f_code[1][0], f_code[1][1]);
+    fprintf (stderr,
+	     " (pic_ext) intra_dc_precision %d, top_field_first %d, frame_pred_frame_dct %d\n",
+	     intra_dc_precision, top_field_first, frame_pred_frame_dct);
+    fprintf (stderr,
+	     " (pic_ext) concealment_motion_vectors %d, q_scale_type %d, intra_vlc_format %d\n",
+	     concealment_motion_vectors, q_scale_type, intra_vlc_format);
+    fprintf (stderr,
+	     " (pic_ext) alternate_scan %d, repeat_first_field %d, progressive_frame %d\n",
+	     alternate_scan, repeat_first_field, progressive_frame);
+}
+
+void stats_header (uint8_t code, uint8_t * buffer)
+{
+    if (! (debug_is_on ()))
+	return;
+
+    switch (code) {
+    case 0x00:
+	stats_picture (buffer);
+	break;
+    case 0xb2:
+	stats_user_data (buffer);
+	break;
+    case 0xb3:
+	stats_sequence (buffer);
+	break;
+    case 0xb4:
+	stats_sequence_error (buffer);
+	break;
+    case 0xb5:
+	//stats_extension (buffer);
+	switch (buffer[0] >> 4) {
+	case 1:
+	    stats_sequence_extension (buffer);
+	    break;
+	case 2:
+	    stats_sequence_display_extension (buffer);
+	    break;
+	case 3:
+	    stats_quant_matrix_extension (buffer);
+	    break;
+	case 4:
+	    stats_copyright_extension (buffer);
+	    break;
+	case 5:
+	    stats_sequence_scalable_extension (buffer);
+	    break;
+	case 7:
+	    stats_picture_display_extension (buffer);
+	    break;
+	case 8:
+	    stats_picture_coding_extension (buffer);
+	    break;
+	default:
+	    fprintf (stderr, " (unknown extension %#x)\n", buffer[0] >> 4);
+	}
+	break;
+    case 0xb7:
+	stats_sequence_end (buffer);
+	break;
+    case 0xb8:
+	stats_group (buffer);
+	break;
+    default:
+	if (code < 0xb0)
+	    stats_slice (code, buffer);
+	else
+	    fprintf (stderr, " (unknown start code %#02x)\n", code);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpeg2/vlc.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,425 @@
+/*
+ * vlc.h
+ * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *
+ * mpeg2dec 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.
+ *
+ * mpeg2dec 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#define GETWORD(bit_buf,shift,bit_ptr)				\
+do {								\
+    bit_buf |= ((bit_ptr[0] << 8) | bit_ptr[1]) << (shift);	\
+    bit_ptr += 2;						\
+} while (0)
+
+static inline void bitstream_init (slice_t * slice, uint8_t * start)
+{
+    slice->bitstream_buf = 0;    GETWORD (slice->bitstream_buf, 16, start);
+    slice->bitstream_ptr = start;
+    slice->bitstream_bits = 0;
+}
+
+// make sure that there are at least 16 valid bits in bit_buf
+#define NEEDBITS(bit_buf,bits,bit_ptr)		\
+do {						\
+    if (bits > 0) {				\
+	GETWORD (bit_buf, bits, bit_ptr);	\
+	bits -= 16;				\
+    }						\
+} while (0)
+
+// remove num valid bits from bit_buf
+#define DUMPBITS(bit_buf,bits,num)	\
+do {					\
+    bit_buf <<= (num);			\
+    bits += (num);			\
+} while (0)
+
+// take num bits from the high part of bit_buf and zero extend them
+#define UBITS(bit_buf,num) (((uint32_t)(bit_buf)) >> (32 - (num)))
+
+// take num bits from the high part of bit_buf and sign extend them
+#define SBITS(bit_buf,num) (((int32_t)(bit_buf)) >> (32 - (num)))
+
+typedef struct {
+    uint8_t modes;
+    uint8_t len;
+} MBtab;
+
+typedef struct {
+    uint8_t delta;
+    uint8_t len;
+} MVtab;
+
+typedef struct {
+    int8_t dmv;
+    uint8_t len;
+} DMVtab;
+
+typedef struct {
+    uint8_t cbp;
+    uint8_t len;
+} CBPtab;
+
+typedef struct {
+    uint8_t size;
+    uint8_t len;
+} DCtab;
+
+typedef struct {
+    uint8_t run;
+    uint8_t level;
+    uint8_t len;
+} DCTtab;
+
+typedef struct {
+    uint8_t mba;
+    uint8_t len;
+} MBAtab;
+
+
+#define INTRA MACROBLOCK_INTRA
+#define QUANT MACROBLOCK_QUANT
+
+static MBtab MB_I [] = {
+    {INTRA|QUANT, 2}, {INTRA, 1}
+};
+
+#define MC MACROBLOCK_MOTION_FORWARD
+#define CODED MACROBLOCK_PATTERN
+
+static MBtab MB_P [] = {
+    {INTRA|QUANT, 6}, {CODED|QUANT, 5}, {MC|CODED|QUANT, 5}, {INTRA,    5},
+    {MC,          3}, {MC,          3}, {MC,             3}, {MC,       3},
+    {CODED,       2}, {CODED,       2}, {CODED,          2}, {CODED,    2},
+    {CODED,       2}, {CODED,       2}, {CODED,          2}, {CODED,    2},
+    {MC|CODED,    1}, {MC|CODED,    1}, {MC|CODED,       1}, {MC|CODED, 1},
+    {MC|CODED,    1}, {MC|CODED,    1}, {MC|CODED,       1}, {MC|CODED, 1},
+    {MC|CODED,    1}, {MC|CODED,    1}, {MC|CODED,       1}, {MC|CODED, 1},
+    {MC|CODED,    1}, {MC|CODED,    1}, {MC|CODED,       1}, {MC|CODED, 1}
+};
+
+#define FWD MACROBLOCK_MOTION_FORWARD
+#define BWD MACROBLOCK_MOTION_BACKWARD
+#define INTER MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD
+
+static MBtab MB_B [] = {
+    {0,                 0}, {INTRA|QUANT,       6},
+    {BWD|CODED|QUANT,   6}, {FWD|CODED|QUANT,   6},
+    {INTER|CODED|QUANT, 5}, {INTER|CODED|QUANT, 5},
+					{INTRA,       5}, {INTRA,       5},
+    {FWD,         4}, {FWD,         4}, {FWD,         4}, {FWD,         4},
+    {FWD|CODED,   4}, {FWD|CODED,   4}, {FWD|CODED,   4}, {FWD|CODED,   4},
+    {BWD,         3}, {BWD,         3}, {BWD,         3}, {BWD,         3},
+    {BWD,         3}, {BWD,         3}, {BWD,         3}, {BWD,         3},
+    {BWD|CODED,   3}, {BWD|CODED,   3}, {BWD|CODED,   3}, {BWD|CODED,   3},
+    {BWD|CODED,   3}, {BWD|CODED,   3}, {BWD|CODED,   3}, {BWD|CODED,   3},
+    {INTER,       2}, {INTER,       2}, {INTER,       2}, {INTER,       2},
+    {INTER,       2}, {INTER,       2}, {INTER,       2}, {INTER,       2},
+    {INTER,       2}, {INTER,       2}, {INTER,       2}, {INTER,       2},
+    {INTER,       2}, {INTER,       2}, {INTER,       2}, {INTER,       2},
+    {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2},
+    {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2},
+    {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2},
+    {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}, {INTER|CODED, 2}
+};
+
+#undef INTRA
+#undef QUANT
+#undef MC
+#undef CODED
+#undef FWD
+#undef BWD
+#undef INTER
+
+
+static MVtab MV_4 [] = {
+    { 3, 6}, { 2, 4}, { 1, 3}, { 1, 3}, { 0, 2}, { 0, 2}, { 0, 2}, { 0, 2}
+};
+
+static MVtab MV_10 [] = {
+    { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10}, { 0,10},
+    { 0,10}, { 0,10}, { 0,10}, { 0,10}, {15,10}, {14,10}, {13,10}, {12,10},
+    {11,10}, {10,10}, { 9, 9}, { 9, 9}, { 8, 9}, { 8, 9}, { 7, 9}, { 7, 9},
+    { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7}, { 6, 7},
+    { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7}, { 5, 7},
+    { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}, { 4, 7}
+};
+
+
+static DMVtab DMV_2 [] = {
+    { 0, 1}, { 0, 1}, { 1, 2}, {-1, 2}
+};
+
+
+static CBPtab CBP_7 [] = {
+    {0x22, 7}, {0x12, 7}, {0x0a, 7}, {0x06, 7},
+    {0x21, 7}, {0x11, 7}, {0x09, 7}, {0x05, 7},
+    {0x3f, 6}, {0x3f, 6}, {0x03, 6}, {0x03, 6},
+    {0x24, 6}, {0x24, 6}, {0x18, 6}, {0x18, 6},
+    {0x3e, 5}, {0x3e, 5}, {0x3e, 5}, {0x3e, 5},
+    {0x02, 5}, {0x02, 5}, {0x02, 5}, {0x02, 5},
+    {0x3d, 5}, {0x3d, 5}, {0x3d, 5}, {0x3d, 5},
+    {0x01, 5}, {0x01, 5}, {0x01, 5}, {0x01, 5},
+    {0x38, 5}, {0x38, 5}, {0x38, 5}, {0x38, 5},
+    {0x34, 5}, {0x34, 5}, {0x34, 5}, {0x34, 5},
+    {0x2c, 5}, {0x2c, 5}, {0x2c, 5}, {0x2c, 5},
+    {0x1c, 5}, {0x1c, 5}, {0x1c, 5}, {0x1c, 5},
+    {0x28, 5}, {0x28, 5}, {0x28, 5}, {0x28, 5},
+    {0x14, 5}, {0x14, 5}, {0x14, 5}, {0x14, 5},
+    {0x30, 5}, {0x30, 5}, {0x30, 5}, {0x30, 5},
+    {0x0c, 5}, {0x0c, 5}, {0x0c, 5}, {0x0c, 5},
+    {0x20, 4}, {0x20, 4}, {0x20, 4}, {0x20, 4},
+    {0x20, 4}, {0x20, 4}, {0x20, 4}, {0x20, 4},
+    {0x10, 4}, {0x10, 4}, {0x10, 4}, {0x10, 4},
+    {0x10, 4}, {0x10, 4}, {0x10, 4}, {0x10, 4},
+    {0x08, 4}, {0x08, 4}, {0x08, 4}, {0x08, 4},
+    {0x08, 4}, {0x08, 4}, {0x08, 4}, {0x08, 4},
+    {0x04, 4}, {0x04, 4}, {0x04, 4}, {0x04, 4},
+    {0x04, 4}, {0x04, 4}, {0x04, 4}, {0x04, 4},
+    {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3},
+    {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3},
+    {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3},
+    {0x3c, 3}, {0x3c, 3}, {0x3c, 3}, {0x3c, 3}
+};
+
+static CBPtab CBP_9 [] = {
+    {0,    0}, {0x00, 9}, {0x27, 9}, {0x1b, 9},
+    {0x3b, 9}, {0x37, 9}, {0x2f, 9}, {0x1f, 9},
+    {0x3a, 8}, {0x3a, 8}, {0x36, 8}, {0x36, 8},
+    {0x2e, 8}, {0x2e, 8}, {0x1e, 8}, {0x1e, 8},
+    {0x39, 8}, {0x39, 8}, {0x35, 8}, {0x35, 8},
+    {0x2d, 8}, {0x2d, 8}, {0x1d, 8}, {0x1d, 8},
+    {0x26, 8}, {0x26, 8}, {0x1a, 8}, {0x1a, 8},
+    {0x25, 8}, {0x25, 8}, {0x19, 8}, {0x19, 8},
+    {0x2b, 8}, {0x2b, 8}, {0x17, 8}, {0x17, 8},
+    {0x33, 8}, {0x33, 8}, {0x0f, 8}, {0x0f, 8},
+    {0x2a, 8}, {0x2a, 8}, {0x16, 8}, {0x16, 8},
+    {0x32, 8}, {0x32, 8}, {0x0e, 8}, {0x0e, 8},
+    {0x29, 8}, {0x29, 8}, {0x15, 8}, {0x15, 8},
+    {0x31, 8}, {0x31, 8}, {0x0d, 8}, {0x0d, 8},
+    {0x23, 8}, {0x23, 8}, {0x13, 8}, {0x13, 8},
+    {0x0b, 8}, {0x0b, 8}, {0x07, 8}, {0x07, 8}
+};
+
+
+static DCtab DC_lum_5 [] = {
+    {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
+    {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
+    {0, 3}, {0, 3}, {0, 3}, {0, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3},
+    {4, 3}, {4, 3}, {4, 3}, {4, 3}, {5, 4}, {5, 4}, {6, 5}
+};
+
+static DCtab DC_chrom_5 [] = {
+    {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2},
+    {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
+    {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2},
+    {3, 3}, {3, 3}, {3, 3}, {3, 3}, {4, 4}, {4, 4}, {5, 5}
+};
+
+static DCtab DC_long [] = {
+    {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, { 6, 5}, { 6, 5},
+    {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, {6, 5}, { 6, 5}, { 6, 5},
+    {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, { 7, 6}, { 7, 6},
+    {8, 7}, {8, 7}, {8, 7}, {8, 7}, {9, 8}, {9, 8}, {10, 9}, {11, 9}
+};
+
+
+static DCTtab DCT_16 [] = {
+    {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0},
+    {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0},
+    {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0},
+    {129, 0, 0}, {129, 0, 0}, {129, 0, 0}, {129, 0, 0},
+    {  2,18, 0}, {  2,17, 0}, {  2,16, 0}, {  2,15, 0},
+    {  7, 3, 0}, { 17, 2, 0}, { 16, 2, 0}, { 15, 2, 0},
+    { 14, 2, 0}, { 13, 2, 0}, { 12, 2, 0}, { 32, 1, 0},
+    { 31, 1, 0}, { 30, 1, 0}, { 29, 1, 0}, { 28, 1, 0}
+};
+
+static DCTtab DCT_15 [] = {
+    {  1,40,15}, {  1,39,15}, {  1,38,15}, {  1,37,15},
+    {  1,36,15}, {  1,35,15}, {  1,34,15}, {  1,33,15},
+    {  1,32,15}, {  2,14,15}, {  2,13,15}, {  2,12,15},
+    {  2,11,15}, {  2,10,15}, {  2, 9,15}, {  2, 8,15},
+    {  1,31,14}, {  1,31,14}, {  1,30,14}, {  1,30,14},
+    {  1,29,14}, {  1,29,14}, {  1,28,14}, {  1,28,14},
+    {  1,27,14}, {  1,27,14}, {  1,26,14}, {  1,26,14},
+    {  1,25,14}, {  1,25,14}, {  1,24,14}, {  1,24,14},
+    {  1,23,14}, {  1,23,14}, {  1,22,14}, {  1,22,14},
+    {  1,21,14}, {  1,21,14}, {  1,20,14}, {  1,20,14},
+    {  1,19,14}, {  1,19,14}, {  1,18,14}, {  1,18,14},
+    {  1,17,14}, {  1,17,14}, {  1,16,14}, {  1,16,14}
+};
+
+static DCTtab DCT_13 [] = {
+    { 11, 2,13}, { 10, 2,13}, {  6, 3,13}, {  4, 4,13},
+    {  3, 5,13}, {  2, 7,13}, {  2, 6,13}, {  1,15,13},
+    {  1,14,13}, {  1,13,13}, {  1,12,13}, { 27, 1,13},
+    { 26, 1,13}, { 25, 1,13}, { 24, 1,13}, { 23, 1,13},
+    {  1,11,12}, {  1,11,12}, {  9, 2,12}, {  9, 2,12},
+    {  5, 3,12}, {  5, 3,12}, {  1,10,12}, {  1,10,12},
+    {  3, 4,12}, {  3, 4,12}, {  8, 2,12}, {  8, 2,12},
+    { 22, 1,12}, { 22, 1,12}, { 21, 1,12}, { 21, 1,12},
+    {  1, 9,12}, {  1, 9,12}, { 20, 1,12}, { 20, 1,12},
+    { 19, 1,12}, { 19, 1,12}, {  2, 5,12}, {  2, 5,12},
+    {  4, 3,12}, {  4, 3,12}, {  1, 8,12}, {  1, 8,12},
+    {  7, 2,12}, {  7, 2,12}, { 18, 1,12}, { 18, 1,12}
+};
+
+static DCTtab DCT_B14_10 [] = {
+    { 17, 1,10}, {  6, 2,10}, {  1, 7,10}, {  3, 3,10},
+    {  2, 4,10}, { 16, 1,10}, { 15, 1,10}, {  5, 2,10}
+};
+
+static DCTtab DCT_B14_8 [] = {
+    { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6},
+    {  3, 2, 7}, {  3, 2, 7}, { 10, 1, 7}, { 10, 1, 7},
+    {  1, 4, 7}, {  1, 4, 7}, {  9, 1, 7}, {  9, 1, 7},
+    {  8, 1, 6}, {  8, 1, 6}, {  8, 1, 6}, {  8, 1, 6},
+    {  7, 1, 6}, {  7, 1, 6}, {  7, 1, 6}, {  7, 1, 6},
+    {  2, 2, 6}, {  2, 2, 6}, {  2, 2, 6}, {  2, 2, 6},
+    {  6, 1, 6}, {  6, 1, 6}, {  6, 1, 6}, {  6, 1, 6},
+    { 14, 1, 8}, {  1, 6, 8}, { 13, 1, 8}, { 12, 1, 8},
+    {  4, 2, 8}, {  2, 3, 8}, {  1, 5, 8}, { 11, 1, 8}
+};
+
+static DCTtab DCT_B14AC_5 [] = {
+		 {  1, 3, 5}, {  5, 1, 5}, {  4, 1, 5},
+    {  1, 2, 4}, {  1, 2, 4}, {  3, 1, 4}, {  3, 1, 4},
+    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
+    {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, {129, 0, 2},
+    {129, 0, 2}, {129, 0, 2}, {129, 0, 2}, {129, 0, 2},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}
+};
+
+static DCTtab DCT_B14DC_5 [] = {
+		 {  1, 3, 5}, {  5, 1, 5}, {  4, 1, 5},
+    {  1, 2, 4}, {  1, 2, 4}, {  3, 1, 4}, {  3, 1, 4},
+    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
+    {  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, 1}, {  1, 1, 1}, {  1, 1, 1}, {  1, 1, 1},
+    {  1, 1, 1}, {  1, 1, 1}, {  1, 1, 1}, {  1, 1, 1}
+};
+
+static DCTtab DCT_B15_10 [] = {
+    {  6, 2, 9}, {  6, 2, 9}, { 15, 1, 9}, { 15, 1, 9},
+    {  3, 4,10}, { 17, 1,10}, { 16, 1, 9}, { 16, 1, 9}
+};
+
+static DCTtab DCT_B15_8 [] = {
+    { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6}, { 65, 0, 6},
+    {  8, 1, 7}, {  8, 1, 7}, {  9, 1, 7}, {  9, 1, 7},
+    {  7, 1, 7}, {  7, 1, 7}, {  3, 2, 7}, {  3, 2, 7},
+    {  1, 7, 6}, {  1, 7, 6}, {  1, 7, 6}, {  1, 7, 6},
+    {  1, 6, 6}, {  1, 6, 6}, {  1, 6, 6}, {  1, 6, 6},
+    {  5, 1, 6}, {  5, 1, 6}, {  5, 1, 6}, {  5, 1, 6},
+    {  6, 1, 6}, {  6, 1, 6}, {  6, 1, 6}, {  6, 1, 6},
+    {  2, 5, 8}, { 12, 1, 8}, {  1,11, 8}, {  1,10, 8},
+    { 14, 1, 8}, { 13, 1, 8}, {  4, 2, 8}, {  2, 4, 8},
+    {  3, 1, 5}, {  3, 1, 5}, {  3, 1, 5}, {  3, 1, 5},
+    {  3, 1, 5}, {  3, 1, 5}, {  3, 1, 5}, {  3, 1, 5},
+    {  2, 2, 5}, {  2, 2, 5}, {  2, 2, 5}, {  2, 2, 5},
+    {  2, 2, 5}, {  2, 2, 5}, {  2, 2, 5}, {  2, 2, 5},
+    {  4, 1, 5}, {  4, 1, 5}, {  4, 1, 5}, {  4, 1, 5},
+    {  4, 1, 5}, {  4, 1, 5}, {  4, 1, 5}, {  4, 1, 5},
+    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
+    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
+    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
+    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
+    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
+    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
+    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
+    {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3}, {  2, 1, 3},
+    {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4},
+    {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4},
+    {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4},
+    {129, 0, 4}, {129, 0, 4}, {129, 0, 4}, {129, 0, 4},
+    {  1, 3, 4}, {  1, 3, 4}, {  1, 3, 4}, {  1, 3, 4},
+    {  1, 3, 4}, {  1, 3, 4}, {  1, 3, 4}, {  1, 3, 4},
+    {  1, 3, 4}, {  1, 3, 4}, {  1, 3, 4}, {  1, 3, 4},
+    {  1, 3, 4}, {  1, 3, 4}, {  1, 3, 4}, {  1, 3, 4},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
+    {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2}, {  1, 1, 2},
+    {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3},
+    {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3},
+    {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3},
+    {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3},
+    {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3},
+    {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3},
+    {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3},
+    {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3}, {  1, 2, 3},
+    {  1, 4, 5}, {  1, 4, 5}, {  1, 4, 5}, {  1, 4, 5},
+    {  1, 4, 5}, {  1, 4, 5}, {  1, 4, 5}, {  1, 4, 5},
+    {  1, 5, 5}, {  1, 5, 5}, {  1, 5, 5}, {  1, 5, 5},
+    {  1, 5, 5}, {  1, 5, 5}, {  1, 5, 5}, {  1, 5, 5},
+    { 10, 1, 7}, { 10, 1, 7}, {  2, 3, 7}, {  2, 3, 7},
+    { 11, 1, 7}, { 11, 1, 7}, {  1, 8, 7}, {  1, 8, 7},
+    {  1, 9, 7}, {  1, 9, 7}, {  1,12, 8}, {  1,13, 8},
+    {  3, 3, 8}, {  5, 2, 8}, {  1,14, 8}, {  1,15, 8}
+};
+
+
+static MBAtab MBA_5 [] = {
+		    {6, 5}, {5, 5}, {4, 4}, {4, 4}, {3, 4}, {3, 4},
+    {2, 3}, {2, 3}, {2, 3}, {2, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
+    {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1},
+    {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}
+};
+
+static MBAtab MBA_11 [] = {
+    {32, 11}, {31, 11}, {30, 11}, {29, 11},
+    {28, 11}, {27, 11}, {26, 11}, {25, 11},
+    {24, 11}, {23, 11}, {22, 11}, {21, 11},
+    {20, 10}, {20, 10}, {19, 10}, {19, 10},
+    {18, 10}, {18, 10}, {17, 10}, {17, 10},
+    {16, 10}, {16, 10}, {15, 10}, {15, 10},
+    {14,  8}, {14,  8}, {14,  8}, {14,  8},
+    {14,  8}, {14,  8}, {14,  8}, {14,  8},
+    {13,  8}, {13,  8}, {13,  8}, {13,  8},
+    {13,  8}, {13,  8}, {13,  8}, {13,  8},
+    {12,  8}, {12,  8}, {12,  8}, {12,  8},
+    {12,  8}, {12,  8}, {12,  8}, {12,  8},
+    {11,  8}, {11,  8}, {11,  8}, {11,  8},
+    {11,  8}, {11,  8}, {11,  8}, {11,  8},
+    {10,  8}, {10,  8}, {10,  8}, {10,  8},
+    {10,  8}, {10,  8}, {10,  8}, {10,  8},
+    { 9,  8}, { 9,  8}, { 9,  8}, { 9,  8},
+    { 9,  8}, { 9,  8}, { 9,  8}, { 9,  8},
+    { 8,  7}, { 8,  7}, { 8,  7}, { 8,  7},
+    { 8,  7}, { 8,  7}, { 8,  7}, { 8,  7},
+    { 8,  7}, { 8,  7}, { 8,  7}, { 8,  7},
+    { 8,  7}, { 8,  7}, { 8,  7}, { 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}
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/Attic/SHIT/video_out_gl.c.V3-sux	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,538 @@
+#define DISP
+
+// this can be 3 or 4  (regarding 24bpp and 32bpp)
+#define BYTES_PP 3
+
+#define TEXTUREFORMAT_32BPP
+
+// Hmm. Enabling this makes about 20% speedup too! (Celeron2+G400+UtahGLX)
+//#define TEXSUBIMAGE_BUG_WORKAROUND
+
+/* 
+ * video_out_gl.c, X11/OpenGL interface
+ * based on video_out_x11 by Aaron Holtzman,
+ * and WS opengl window manager by Pontscho/Fresh!
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+
+LIBVO_EXTERN(gl)
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+//#include <X11/keysym.h>
+#include <GL/glx.h>
+#include <errno.h>
+#include "yuv2rgb.h"
+
+#include <GL/gl.h>
+
+static vo_info_t vo_info = 
+{
+	"X11 (OpenGL)",
+	"gl",
+	"Arpad Gereoffy <arpi@esp-team.scene.hu>",
+	""
+};
+
+/* private prototypes */
+static void Display_Image (unsigned char *ImageData);
+
+/* local data */
+static unsigned char *ImageData=NULL;
+
+/* X11 related variables */
+static Display *mydisplay;
+static Window mywindow;
+//static GC mygc;
+//static XImage *myximage;
+//static int depth,mode;
+static XWindowAttributes attribs;
+static int X_already_started = 0;
+
+static int texture_id=1;
+
+static GLXContext wsGLXContext;
+//XVisualInfo        * wsVisualInfo;
+int                  wsGLXAttrib[] = { GLX_RGBA,
+                                       GLX_RED_SIZE,1,
+                                       GLX_GREEN_SIZE,1,
+                                       GLX_BLUE_SIZE,1,
+//                                       GLX_DEPTH_SIZE,16,
+                                       GLX_DOUBLEBUFFER,
+                                       None };
+
+
+static uint32_t image_width;
+static uint32_t image_height;
+static uint32_t image_format;
+static uint32_t image_bpp;
+static uint32_t image_bytes;
+
+static uint32_t texture_width;
+static uint32_t texture_height;
+
+static resize(int x,int y){
+  printf("Resize: %dx%d\n",x,y);
+  glViewport( 0, 0, x, y );
+
+  glMatrixMode(GL_PROJECTION);
+  glLoadIdentity();
+  glOrtho(0, image_width, image_height, 0, -1,1);
+
+  glMatrixMode(GL_MODELVIEW);
+  glLoadIdentity();
+}
+
+/* connect to server, create and map window,
+ * allocate colors and (shared) memory
+ */
+static uint32_t 
+init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
+{
+	int screen;
+	unsigned int fg, bg;
+	char *hello = (title == NULL) ? "OpenGL rulez" : title;
+	char *name = ":0.0";
+	XSizeHints hint;
+	XVisualInfo *vinfo;
+	XEvent xev;
+
+	XGCValues xgcv;
+	XSetWindowAttributes xswa;
+	unsigned long xswamask;
+
+	image_height = height;
+	image_width = width;
+	image_format = format;
+  
+	if (X_already_started) return -1;
+
+	if(getenv("DISPLAY"))	name = getenv("DISPLAY");
+
+	mydisplay = XOpenDisplay(name);
+
+	if (mydisplay == NULL)
+	{
+		fprintf(stderr,"Can not open display\n");
+		return -1;
+	}
+
+	screen = DefaultScreen(mydisplay);
+
+	hint.x = 0;
+	hint.y = 0;
+	hint.width = d_width;
+	hint.height = d_height;
+	hint.flags = PPosition | PSize;
+
+	/* Get some colors */
+
+	bg = WhitePixel(mydisplay, screen);
+	fg = BlackPixel(mydisplay, screen);
+
+	/* Make the window */
+
+	XGetWindowAttributes(mydisplay, DefaultRootWindow(mydisplay), &attribs);
+
+#if 0
+	/*
+	 *
+	 * depth in X11 terminology land is the number of bits used to
+	 * actually represent the colour.
+   	 *
+	 * bpp in X11 land means how many bits in the frame buffer per
+	 * pixel. 
+	 *
+	 * ex. 15 bit color is 15 bit depth and 16 bpp. Also 24 bit
+	 *     color is 24 bit depth, but can be 24 bpp or 32 bpp.
+	 */
+
+	depth = attribs.depth;
+
+	if (depth != 15 && depth != 16 && depth != 24 && depth != 32) 
+	{
+		/* The root window may be 8bit but there might still be
+		* visuals with other bit depths. For example this is the 
+		* case on Sun/Solaris machines.
+		*/
+		depth = 24;
+	}
+	//BEGIN HACK
+	//mywindow = XCreateSimpleWindow(mydisplay, DefaultRootWindow(mydisplay),
+	//hint.x, hint.y, hint.width, hint.height, 4, fg, bg);
+	//
+#endif
+
+//	XMatchVisualInfo(mydisplay, screen, depth, TrueColor, &vinfo);
+  vinfo=glXChooseVisual( mydisplay,screen,wsGLXAttrib );
+
+	xswa.background_pixel = 0;
+	xswa.border_pixel     = 1;
+//	xswa.colormap         = XCreateColormap(mydisplay, RootWindow(mydisplay,screen), vinfo.visual, AllocNone);
+	xswa.colormap         = XCreateColormap(mydisplay, RootWindow(mydisplay,screen), vinfo->visual, AllocNone);
+	xswamask = CWBackPixel | CWBorderPixel | CWColormap;
+//  xswamask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWCursor | CWOverrideRedirect | CWSaveUnder | CWX | CWY | CWWidth | CWHeight;
+
+  mywindow = XCreateWindow(mydisplay, RootWindow(mydisplay,screen),
+    hint.x, hint.y, hint.width, hint.height, 4, vinfo->depth,CopyFromParent,vinfo->visual,xswamask,&xswa);
+
+  wsGLXContext=glXCreateContext( mydisplay,vinfo,NULL,True );
+//  XStoreName( wsDisplay,wsMyWin,wsSysName );
+
+  printf("GLXcontect ok\n");
+
+	XSelectInput(mydisplay, mywindow, StructureNotifyMask);
+
+	/* Tell other applications about this window */
+
+	XSetStandardProperties(mydisplay, mywindow, hello, hello, None, NULL, 0, &hint);
+
+	/* Map window. */
+
+	XMapWindow(mydisplay, mywindow);
+
+	/* Wait for map. */
+	do 
+	{
+		XNextEvent(mydisplay, &xev);
+	}
+	while (xev.type != MapNotify || xev.xmap.event != mywindow);
+
+	XSelectInput(mydisplay, mywindow, NoEventMask);
+
+  glXMakeCurrent( mydisplay,mywindow,wsGLXContext );
+
+	XFlush(mydisplay);
+	XSync(mydisplay, False);
+
+//	mygc = XCreateGC(mydisplay, mywindow, 0L, &xgcv);
+
+//		myximage = XGetImage(mydisplay, mywindow, 0, 0,
+//		width, image_height, AllPlanes, ZPixmap);
+//		ImageData = myximage->data;
+//	bpp = myximage->bits_per_pixel;
+
+	XSelectInput(mydisplay, mywindow, StructureNotifyMask); // !!!!
+
+  printf("Window setup ok\n");
+
+#if 0
+	// If we have blue in the lowest bit then obviously RGB 
+	mode = ((myximage->blue_mask & 0x01) != 0) ? MODE_RGB : MODE_BGR;
+#ifdef WORDS_BIGENDIAN 
+	if (myximage->byte_order != MSBFirst)
+#else
+	if (myximage->byte_order != LSBFirst) 
+#endif
+	{
+		fprintf( stderr, "No support fon non-native XImage byte order!\n" );
+		return -1;
+	}
+
+  printf("DEPTH=%d  BPP=%d\n",depth,bpp);
+#endif
+
+	/* 
+	 * If depth is 24 then it may either be a 3 or 4 byte per pixel
+	 * format. We can't use bpp because then we would lose the 
+	 * distinction between 15/16bit depth (2 byte formate assumed).
+	 *
+	 * FIXME - change yuv2rgb_init to take both depth and bpp
+	 * parameters
+	 */
+
+  texture_width=32;
+  while(texture_width<image_width) texture_width*=2;
+  while(texture_width<image_height) texture_width*=2;
+  if(texture_width>256)texture_width=256; // voodoo3 hack
+  texture_height=texture_width;
+
+  if(format==IMGFMT_YV12){
+    yuv2rgb_init(8*BYTES_PP, MODE_RGB);
+    printf("YUV init OK!\n");
+    image_bpp=8*BYTES_PP;
+    image_bytes=BYTES_PP;
+  } else {
+    image_bpp=format&0xFF;
+    image_bytes=(image_bpp+7)/8;
+  }
+
+  ImageData=malloc(texture_width*texture_height*image_bytes);
+  memset(ImageData,128,texture_width*texture_height*image_bytes);
+
+  glDisable(GL_BLEND); 
+  glDisable(GL_DEPTH_TEST);
+  glDepthMask(GL_FALSE);
+  glDisable(GL_CULL_FACE);
+
+  printf("Creating %dx%d texture...\n",texture_width,texture_height);
+
+#if 1
+//  glBindTexture(GL_TEXTURE_2D, texture_id);
+  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+#ifdef TEXTUREFORMAT_32BPP
+  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, texture_width, texture_height, 0,
+#else
+  glTexImage2D(GL_TEXTURE_2D, 0, BYTES_PP, texture_width, texture_height, 0,
+#endif
+       (image_bytes==4)?GL_RGBA:GL_BGR, GL_UNSIGNED_BYTE, ImageData);
+#endif
+
+  resize(d_width,d_height);
+
+  glClearColor( 1.0f,1.0f,1.0f,0.0f );
+  glClear( GL_COLOR_BUFFER_BIT );
+
+  printf("OpenGL setup OK!\n");
+
+	X_already_started++;
+	return 0;
+}
+
+static const vo_info_t*
+get_info(void)
+{
+	return &vo_info;
+}
+
+static void 
+Terminate_Display_Process(void) 
+{
+	getchar();	/* wait for enter to remove window */
+	XDestroyWindow(mydisplay, mywindow);
+	XCloseDisplay(mydisplay);
+	X_already_started = 0;
+}
+
+static void 
+FlipImage()
+{
+//		XPutImage(mydisplay, mywindow, mygc, myximage, 0, 0, 0, 0, myximage->width, myximage->height);
+//		XFlush(mydisplay);
+int i;
+XEvent wsEvent;
+XEvent xev;
+
+  while ( XPending( mydisplay ) )  {
+    XNextEvent( mydisplay,&wsEvent );
+    switch( wsEvent.type ) {
+//       case Expose:          if ( wsReDraw ) wsReDraw( wsDisplay,wsEvent.xany.window ); break;
+       case ConfigureNotify: //wsWindowWidth=wsEvent.xconfigure.width;
+                             //wsWindowHeight=wsEvent.xconfigure.height;
+#if 0
+        XUnmapWindow( mydisplay,mywindow );
+        XMapWindow( mydisplay,mywindow );
+      	/* Wait for map. */
+        do {	XNextEvent(mydisplay, &xev);}
+          while (xev.type != MapNotify || xev.xmap.event != mywindow);
+#endif
+               resize( wsEvent.xconfigure.width, wsEvent.xconfigure.height );
+               break;
+    }
+  }
+
+  glEnable(GL_TEXTURE_2D);
+//  glBindTexture(GL_TEXTURE_2D, texture_id);
+
+  glColor3f(1,1,1);
+  glBegin(GL_QUADS);
+    glTexCoord2f(0,0);glVertex2i(0,0);
+    glTexCoord2f(0,1);glVertex2i(0,texture_height);
+    glTexCoord2f(1,1);glVertex2i(texture_width,texture_height);
+    glTexCoord2f(1,0);glVertex2i(texture_width,0);
+  glEnd();
+
+//  glFlush();
+  glFinish();
+  glXSwapBuffers( mydisplay,mywindow );
+  
+}
+
+static inline void
+flip_page_x11(void)
+{
+//	Display_Image(myximage, ImageData);
+//	Display_Image(ImageData);
+  FlipImage();
+}
+
+
+static void
+flip_page(void)
+{
+		return flip_page_x11();
+}
+
+static inline uint32_t
+draw_slice_x11(uint8_t *src[], uint32_t slice_num)
+{
+	uint8_t *dst;
+  int i;
+
+	dst = ImageData;// + image_width * 16 * BYTES_PP * slice_num;
+
+	yuv2rgb(dst , src[0], src[1], src[2], 
+			image_width, 16, 
+			image_width*BYTES_PP, image_width, image_width/2 );
+
+//	emms ();
+
+#ifdef TEXSUBIMAGE_BUG_WORKAROUND
+    for(i=0;i<16;i++){
+      glTexSubImage2D( GL_TEXTURE_2D,  // target
+		       0,              // level
+		       0,              // x offset
+		       16*slice_num+i,              // y offset
+		       image_width,    // width
+		       1,              // height
+		       (BYTES_PP==4)?GL_RGBA:GL_RGB,        // format
+		       GL_UNSIGNED_BYTE, // type
+		       ImageData+i*BYTES_PP*image_width );        // *pixels
+    }
+#else
+//printf("uploading slice \n");
+      glTexSubImage2D( GL_TEXTURE_2D,  // target
+		       0,              // level
+		       0,              // x offset
+		       16*slice_num,              // y offset
+		       image_width,    // width
+		       16,              // height
+		       (BYTES_PP==4)?GL_RGBA:GL_RGB,        // format
+		       GL_UNSIGNED_BYTE, // type
+		       ImageData );        // *pixels
+#endif
+
+	return 0;
+}
+
+static uint32_t
+draw_slice(uint8_t *src[], uint32_t slice_num)
+{
+		return draw_slice_x11(src,slice_num);
+}
+
+#define MIN(a,b) (((a)<(b))?(a):(b))
+
+static inline uint32_t 
+draw_frame_x11_yv12(uint8_t *src[])
+{
+int i;
+//  printf("Converting YUV->RGB...\n");
+	yuv2rgb(ImageData, src[0], src[1], src[2],
+		image_width, image_height, 
+		image_width*BYTES_PP, image_width, image_width/2 );
+//  printf("Ready!\n");
+
+//		emms ();
+
+//    for(i=0;i<image_height;i++){
+    for(i=0;i<MIN(image_height,texture_height);i++){
+      glTexSubImage2D( GL_TEXTURE_2D,  // target
+		       0,              // level
+		       0,              // x offset
+		       i,              // y offset
+//		       image_width,    // width
+		       MIN(image_width,texture_width),    // width
+		       1,              // height
+		       (BYTES_PP==4)?GL_RGBA:GL_RGB,        // format
+		       GL_UNSIGNED_BYTE, // type
+		       ImageData+i*BYTES_PP*image_width );        // *pixels
+    }
+
+//	Display_Image(ImageData);
+//  FlipImage();
+	return 0; 
+}
+
+
+static inline uint32_t 
+draw_frame_x11_bgr(uint8_t *src[])
+{
+int i;
+uint8_t *s=src[0];
+uint8_t *de=&ImageData[3*image_width];
+
+    for(i=0;i<image_height;i++){
+      int j;
+      uint8_t *d=ImageData;
+      while(d<de){
+        d[0]=s[2];
+        d[1]=s[1];
+        d[2]=s[0];
+        s+=3;d+=3;
+      }
+      glTexSubImage2D( GL_TEXTURE_2D,  // target
+		       0,              // level
+		       0,              // x offset
+		       image_height-1-i,  // y offset
+		       image_width<texture_width?image_width:texture_width,    // width
+//		       image_width,    // width
+		       1,              // height
+		       (image_bytes==4)?GL_RGBA:GL_RGB,        // format
+		       GL_UNSIGNED_BYTE, // type
+		       ImageData);        // *pixels
+    }
+
+//	Display_Image(ImageData);
+  FlipImage();
+	return 0; 
+}
+
+static inline uint32_t 
+draw_frame_x11_rgb(uint8_t *src[])
+{
+int i;
+uint8_t *ImageData=src[0];
+
+    for(i=0;i<image_height;i++){
+      glTexSubImage2D( GL_TEXTURE_2D,  // target
+		       0,              // level
+		       0,              // x offset
+		       image_height-1-i,  // y offset
+//		       image_width,    // width
+		       image_width<texture_width?image_width:texture_width,    // width
+		       1,              // height
+		       (image_bytes==4)?GL_RGBA:GL_RGB,        // format
+		       GL_UNSIGNED_BYTE, // type
+		       ImageData+i*image_bytes*image_width );        // *pixels
+    }
+
+//	Display_Image(ImageData);
+  FlipImage();
+	return 0; 
+}
+
+
+static uint32_t
+draw_frame(uint8_t *src[])
+{
+    if(image_format==IMGFMT_YV12)
+	return draw_frame_x11_yv12(src);
+    else 
+    if((image_format&IMGFMT_RGB_MASK)==IMGFMT_RGB)
+	return draw_frame_x11_rgb(src);
+    else
+	return draw_frame_x11_bgr(src);
+}
+
+static uint32_t
+query_format(uint32_t format)
+{
+    switch(format){
+    case IMGFMT_YV12:
+    case IMGFMT_RGB|24:
+    case IMGFMT_BGR|24:
+        return 1;
+    }
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/Attic/SHIT/video_out_gl.c.diff	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,64 @@
+8,10d7
+< // Hmm. Enabling this makes about 20% speedup too! (Celeron2+G400+UtahGLX)
+< //#define TEXSUBIMAGE_BUG_WORKAROUND
+< 
+369,370c366,367
+< static inline uint32_t
+< draw_slice_x11(uint8_t *src[], uint32_t slice_num)
+---
+> //static inline uint32_t draw_slice_x11(uint8_t *src[], uint32_t slice_num)
+> static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
+372,375c369,372
+< 	uint8_t *dst;
+<   int i;
+< 
+< 	dst = ImageData;// + image_width * 16 * BYTES_PP * slice_num;
+---
+>     int i;
+>     int dstride=w*BYTES_PP;
+>     
+>     dstride=(dstride+15)&(~15);
+377,379c374,375
+< 	yuv2rgb(dst , src[0], src[1], src[2], 
+< 			image_width, 16, 
+< 			image_width*BYTES_PP, image_width, image_width/2 );
+---
+> 	yuv2rgb(ImageData, src[0], src[1], src[2], 
+> 			w,h, dstride, stride[0],stride[1]);
+383,384c379
+< #ifdef TEXSUBIMAGE_BUG_WORKAROUND
+<     for(i=0;i<16;i++){
+---
+>     for(i=0;i<h;i++){
+387,389c382,384
+< 		       0,              // x offset
+< 		       16*slice_num+i,              // y offset
+< 		       image_width,    // width
+---
+> 		       x,              // x offset
+> 		       y+i,            // y offset
+> 		       w,              // width
+393c388
+< 		       ImageData+i*BYTES_PP*image_width );        // *pixels
+---
+> 		       ImageData+i*dstride );        // *pixels
+395,406d389
+< #else
+< //printf("uploading slice \n");
+<       glTexSubImage2D( GL_TEXTURE_2D,  // target
+< 		       0,              // level
+< 		       0,              // x offset
+< 		       16*slice_num,              // y offset
+< 		       image_width,    // width
+< 		       16,              // height
+< 		       (BYTES_PP==4)?GL_RGBA:GL_RGB,        // format
+< 		       GL_UNSIGNED_BYTE, // type
+< 		       ImageData );        // *pixels
+< #endif
+409,414d391
+< }
+< 
+< static uint32_t
+< draw_slice(uint8_t *src[], uint32_t slice_num)
+< {
+< 		return draw_slice_x11(src,slice_num);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/Attic/SHIT/video_out_odivx.c.OLD	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,183 @@
+/* 
+ *  OpenDivX AVI file writer
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+LIBVO_EXTERN(odivx)
+
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+#include "../encore/encore.h"
+
+static vo_info_t vo_info = 
+{
+	"OpenDivX AVI File writer",
+	"odivx",
+	"Arpad Gereoffy <arpi@esp-team.scene.hu>",
+	""
+};
+
+static uint8_t *image=NULL;
+static int image_width=0;
+static int image_height=0;
+static char *buffer=NULL;
+static int frameno=0;
+
+extern char* encode_name;
+extern char* encode_index_name;
+
+static uint32_t
+draw_slice(uint8_t *src[], uint32_t slice_num)
+{
+    uint8_t *d;
+
+    // copy Y
+    d=image;
+    memcpy(d+(slice_num<<4)*image_width,src[0],image_width*16);
+    // copy U
+    d+=image_width*image_height;
+    memcpy(d+(slice_num<<2)*image_width,src[1],image_width*4);
+    // copy V
+    d+=image_width*image_height/4;
+    memcpy(d+(slice_num<<2)*image_width,src[2],image_width*4);
+
+    return 0;
+}
+
+static uint32_t
+draw_frame(uint8_t *src[])
+{
+    uint8_t *d;
+
+    // copy Y
+    d=image;
+    memcpy(d,src[0],image_width*image_height);
+    // copy U
+    d+=image_width*image_height;
+    memcpy(d,src[1],image_width*image_height/4);
+    // copy V
+    d+=image_width*image_height/4;
+    memcpy(d,src[2],image_width*image_height/4);
+
+    return 0;
+}
+
+typedef unsigned int DWORD;
+
+typedef struct
+{
+    DWORD               ckid;
+    DWORD               dwFlags;
+    DWORD               dwChunkOffset;          // Position of chunk
+    DWORD               dwChunkLength;          // Length of chunk
+} AVIINDEXENTRY;
+
+static void
+flip_page(void)
+{
+
+// we are rady to encode this frame
+ENC_FRAME enc_frame;
+ENC_RESULT enc_result;
+
+if(++frameno<10) return;
+
+enc_frame.bmp=image;
+enc_frame.bitstream=buffer;
+enc_frame.length=0;
+encore(0x123,0,&enc_frame,&enc_result);
+
+printf("coded length: %d  \n",enc_frame.length);
+
+if(encode_name){
+  AVIINDEXENTRY i;
+  FILE *file;
+  i.ckid=('c'<<24)|('d'<<16)|('0'<<8)|'0'; // "00dc"
+  i.dwFlags=enc_result.isKeyFrame?0x10:0;
+  i.dwChunkLength=enc_frame.length;
+  // Write AVI chunk:
+  if((file=fopen(encode_name,"ab"))){
+    unsigned char zerobyte=0;
+    i.dwChunkOffset=ftell(file);
+    fwrite(&i.ckid,4,1,file);
+    fwrite(&enc_frame.length,4,1,file);
+    fwrite(buffer,enc_frame.length,1,file);
+    if(enc_frame.length&1) fwrite(&zerobyte,1,1,file); // padding
+    fclose(file);
+  }
+  // Write AVI index:
+  if(encode_index_name && (file=fopen(encode_index_name,"ab"))){
+    fwrite(&i,sizeof(i),1,file);
+    fclose(file);
+  }
+}
+
+
+}
+
+static uint32_t
+query_format(uint32_t format)
+{
+    switch(format){
+    case IMGFMT_YV12:
+//    case IMGFMT_YUY2:
+//    case IMGFMT_RGB|24:
+//    case IMGFMT_BGR|24:
+        return 1;
+    }
+    return 0;
+}
+
+static uint32_t
+init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
+{
+	uint32_t frame_size;
+        ENC_PARAM enc_param;
+
+    buffer=malloc(0x100000);
+    if(!buffer) return -1;
+
+//	file = fopen("encoded.odvx","wb");
+//        if(!file) return -1;
+        
+        frame_size=width*height+width*height/2;
+        image_width=width;
+        image_height=height;
+        image=malloc(frame_size);
+
+	//clear the buffer
+	memset(image,0x80,frame_size);
+
+// encoding parameters:
+enc_param.framerate=25.0;
+enc_param.bitrate=400000; //780000;
+enc_param.rc_period=300;
+enc_param.max_quantizer=15;
+enc_param.min_quantizer=1;
+enc_param.search_range=128;
+
+// init codec:
+enc_param.x_dim=width;
+enc_param.y_dim=height;
+enc_param.flip=2; // 0=RGB  1=flippedRGB  2=planarYUV format
+encore(0x123,ENC_OPT_INIT,&enc_param,NULL);
+
+  return 0;
+}
+
+static const vo_info_t*
+get_info(void)
+{
+	return &vo_info;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/Attic/SHIT/video_out_sdl.c-1.1.4	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,574 @@
+/*
+ *  video_out_sdl.c
+ *
+ *  Copyright (C) Ryan C. Gordon <icculus@lokigames.com> - April 22, 2000.
+ *
+ *  A mpeg2dec display driver that does output through the
+ *  Simple DirectMedia Layer (SDL) library. This effectively gives us all
+ *  sorts of output options: X11, SVGAlib, fbcon, AAlib, GGI. Win32, MacOS
+ *  and BeOS support, too. Yay. SDL info, source, and binaries can be found
+ *  at http://slouken.devolution.com/SDL/
+ *
+ *  This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *	
+ *  mpeg2dec 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, or (at your option)
+ *  any later version.
+ *   
+ *  mpeg2dec 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 GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 
+ *
+ *  Changes:
+ *    Dominik Schnitzer <dominik@schnitzer.at> - November 08, 2000.
+ *    - Added resizing support, fullscreen: chnaged the sdlmodes selection
+ *       routine.
+ *    - SDL bugfixes: removed the atexit(SLD_Quit), SDL_Quit now resides in
+ *       the plugin_exit routine.
+ *    - Commented the source :)
+ *    - Shortcuts: for switching between Fullscreen/Windowed mode and for
+ *       cycling between the different Fullscreen modes.
+ *    - Small bugfixes: proper width/height of movie
+ *    Dominik Schnitzer <dominik@schnitzer.at> - November 11, 2000.
+ *    - Cleanup code, more comments
+ *    - Better error handling
+ *    Bruno Barreyra <barreyra@ufl.edu> - December 10, 2000.
+ *    - Eliminated memcpy's for entire frames
+ *    Arpad Gereoffy <arpi@esp-team.scene.hu> - Jan 13, 2001.
+ *    - Ported to MPlayer
+ *    - small changes about keys and fullscreen mode
+ *    Jeffrey Boser <verin@lvcm.com> - Jan 16, 2001.
+ *    - type casting fixes, clip rect fix
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+LIBVO_EXTERN(sdl)
+
+//#include "log.h"
+//#define LOG if(0)printf
+
+static vo_info_t vo_info = 
+{
+	"SDL YUV overlay",
+	"sdl",
+	"Ryan C. Gordon <icculus@lokigames.com>",
+	""
+};
+
+#include <SDL/SDL.h>
+
+/** Private SDL Data structure **/
+
+static struct sdl_priv_s {
+
+	/* SDL YUV surface & overlay */
+	SDL_Surface *surface;
+	SDL_Overlay *overlay;
+//	SDL_Overlay *current_frame;
+
+	/* available fullscreen modes */
+	SDL_Rect **fullmodes;
+
+	/* surface attributes for fullscreen and windowed mode */
+	Uint32 sdlflags, sdlfullflags;
+
+	/* save the windowed output extents */
+	SDL_Rect windowsize;
+	
+	/* Bits per Pixel */
+	Uint8 bpp;
+
+	/* current fullscreen mode, 0 = highest available fullscreen mode */
+	int fullmode;
+
+	/* YUV ints */
+	int framePlaneY, framePlaneUV;
+	int slicePlaneY, slicePlaneUV;
+        int width,height;
+        int format;
+} sdl_priv;
+
+
+/** OMS Plugin functions **/
+
+
+/**
+ * Take a null-terminated array of pointers, and find the last element.
+ *
+ *    params : array == array of which we want to find the last element.
+ *   returns : index of last NON-NULL element.
+ **/
+
+static inline int findArrayEnd (SDL_Rect **array)
+{
+	int i = 0;
+	while ( array[i++] );	/* keep loopin' ... */
+	
+	/* return the index of the last array element */
+	return i - 1;
+}
+
+
+/**
+ * Open and prepare SDL output.
+ *
+ *    params : *plugin ==
+ *             *name == 
+ *   returns : 0 on success, -1 on failure
+ **/
+
+static int sdl_open (void *plugin, void *name)
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+	const SDL_VideoInfo *vidInfo = NULL;
+	static int opened = 0;
+
+	if (opened)
+	    return 0;
+	opened = 1;
+
+//	LOG (LOG_DEBUG, "SDL video out: Opened Plugin");
+	
+	/* default to no fullscreen mode, we'll set this as soon we have the avail. mdoes */
+	priv->fullmode = -2;
+	/* other default values */
+	priv->sdlflags = SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT;
+	priv->sdlfullflags = SDL_HWSURFACE|SDL_FULLSCREEN|SDL_DOUBLEBUF|SDL_ASYNCBLIT;
+	priv->surface = NULL;
+	priv->overlay = NULL;
+	priv->fullmodes = NULL;
+
+	/* initialize the SDL Video system */
+	if (SDL_Init (SDL_INIT_VIDEO)) {
+//		LOG (LOG_ERROR, "SDL video out: Initializing of SDL failed (SDL_Init). Please use the latest version of SDL.");
+		return -1;
+	}
+	
+	/* No Keyrepeats! */
+	SDL_EnableKeyRepeat(0,0);
+
+	/* get information about the graphics adapter */
+	vidInfo = SDL_GetVideoInfo ();
+	
+	/* collect all fullscreen & hardware modes available */
+	if (!(priv->fullmodes = SDL_ListModes (vidInfo->vfmt, priv->sdlfullflags))) {
+
+		/* non hardware accelerated fullscreen modes */
+		priv->sdlfullflags &= ~SDL_HWSURFACE;
+ 		priv->fullmodes = SDL_ListModes (vidInfo->vfmt, priv->sdlfullflags);
+	}
+	
+	/* test for normal resizeable & windowed hardware accellerated surfaces */
+	if (!SDL_ListModes (vidInfo->vfmt, priv->sdlflags)) {
+		
+		/* test for NON hardware accelerated resizeable surfaces - poor you. 
+		 * That's all we have. If this fails there's nothing left.
+		 * Theoretically there could be Fullscreenmodes left - we ignore this for now.
+		 */
+		priv->sdlflags &= ~SDL_HWSURFACE;
+		if ((!SDL_ListModes (vidInfo->vfmt, priv->sdlflags)) && (!priv->fullmodes)) {
+//			LOG (LOG_ERROR, "SDL video out: Couldn't get any acceptable SDL Mode for output. (SDL_ListModes failed)");
+			return -1;
+		}
+	}
+	
+		
+   /* YUV overlays need at least 16-bit color depth, but the
+    * display might less. The SDL AAlib target says it can only do
+    * 8-bits, for example. So, if the display is less than 16-bits,
+    * we'll force the BPP to 16, and pray that SDL can emulate for us.
+	 */
+	priv->bpp = vidInfo->vfmt->BitsPerPixel;
+	if (priv->bpp < 16) {
+/*
+		LOG (LOG_WARNING, "SDL video out: Your SDL display target wants to be at a color depth of (%d), but we need it to be at\
+least 16 bits, so we need to emulate 16-bit color. This is going to slow things down; you might want to\
+increase your display's color depth, if possible", priv->bpp);
+*/
+		priv->bpp = 16;  
+	}
+	
+	/* We dont want those in out event queue */
+	SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
+	SDL_EventState(SDL_KEYUP, SDL_IGNORE);
+	SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
+	SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE);
+	SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE);
+	SDL_EventState(SDL_QUIT, SDL_IGNORE);
+	SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
+	SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
+	
+	/* Success! */
+	return 0;
+}
+
+
+/**
+ * Close SDL, Cleanups, Free Memory
+ *
+ *    params : *plugin
+ *   returns : non-zero on success, zero on error.
+ **/
+
+static int sdl_close (void *plugin)
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+	
+//	LOG (LOG_DEBUG, "SDL video out: Closed Plugin");
+//	LOG (LOG_INFO, "SDL video out: Closed Plugin");
+
+	/* Cleanup YUV Overlay structure */
+	if (priv->overlay) 
+		SDL_FreeYUVOverlay(priv->overlay);
+
+	/* Free our blitting surface */
+	if (priv->surface)
+		SDL_FreeSurface(priv->surface);
+	
+	/* TODO: cleanup the full_modes array */
+	
+	/* Cleanup SDL */
+	SDL_Quit();
+
+	return 0;
+}
+
+
+/**
+ * Sets the specified fullscreen mode.
+ *
+ *   params : mode == index of the desired fullscreen mode
+ *  returns : doesn't return
+ **/
+ 
+static void set_fullmode (int mode)
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+	SDL_Surface *newsurface = NULL;
+	
+	
+	/* if we haven't set a fullmode yet, default to the lowest res fullmode first */
+	if (mode < 0) 
+		mode = priv->fullmode = findArrayEnd(priv->fullmodes) - 1;
+
+	/* change to given fullscreen mode and hide the mouse cursor*/
+	newsurface = SDL_SetVideoMode(priv->fullmodes[mode]->w, priv->fullmodes[mode]->h, priv->bpp, priv->sdlfullflags);
+	
+	/* if we were successfull hide the mouse cursor and save the mode */
+	if (newsurface) {
+		priv->surface = newsurface;
+		SDL_ShowCursor(0);
+	}
+}
+
+
+/**
+ * Initialize an SDL surface and an SDL YUV overlay.
+ *
+ *    params : width  == width of video we'll be displaying.
+ *             height == height of video we'll be displaying.
+ *             fullscreen == want to be fullscreen?
+ *             title == Title for window titlebar.
+ *   returns : non-zero on success, zero on error.
+ **/
+
+static uint32_t
+init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
+//static int sdl_setup (int width, int height)
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+        unsigned int sdl_format;
+
+        switch(format){
+          case IMGFMT_YV12: sdl_format=SDL_YV12_OVERLAY;break;
+          case IMGFMT_YUY2: sdl_format=SDL_YUY2_OVERLAY;break;
+          default:
+            printf("SDL: Unsupported image format (0x%X)\n",format);
+            return -1;
+        }
+
+	sdl_open (NULL, NULL);
+
+	/* Save the original Image size */
+
+	priv->width  = width;
+	priv->height = height;
+        priv->format = format;
+        
+        if(fullscreen){
+	    priv->windowsize.w = width;
+	    priv->windowsize.h = height;
+            priv->surface=NULL;
+            set_fullmode(priv->fullmode);
+        } else {
+	    priv->windowsize.w = d_width;
+	    priv->windowsize.h = d_height;
+            priv->surface = SDL_SetVideoMode (d_width, d_height, priv->bpp, priv->sdlflags);
+        }
+        if(!priv->surface) return -1; // cannot SetVideoMode
+
+	/* Initialize and create the YUV Overlay used for video out */
+	if (!(priv->overlay = SDL_CreateYUVOverlay (width, height, sdl_format, priv->surface))) {
+		printf ("SDL video out: Couldn't create an SDL-based YUV overlay\n");
+		return -1;
+	}
+	priv->framePlaneY = width * height;
+	priv->framePlaneUV = (width * height) >> 2;
+	priv->slicePlaneY = width << 4;
+	priv->slicePlaneUV = width << 2;
+
+	return 0;
+}
+
+
+/**
+ * Draw a frame to the SDL YUV overlay.
+ *
+ *   params : *src[] == the Y, U, and V planes that make up the frame.
+ *  returns : non-zero on success, zero on error.
+ **/
+
+//static int sdl_draw_frame (frame_t *frame)
+static uint32_t draw_frame(uint8_t *src[])
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+	uint8_t *dst;
+
+//	priv->current_frame = (SDL_Overlay*) frame->private;
+//	SDL_UnlockYUVOverlay (priv->current_frame);
+
+	if (SDL_LockYUVOverlay (priv->overlay)) {
+//		LOG (LOG_ERROR, "SDL video out: Couldn't lock SDL-based YUV overlay");
+		return -1;
+	}
+
+        switch(priv->format){
+        case IMGFMT_YV12:
+	    dst = (uint8_t *) *( (uint8_t **) priv->overlay->pixels);
+	    memcpy (dst, src[0], priv->framePlaneY);
+	    dst += priv->framePlaneY;
+	    memcpy (dst, src[2], priv->framePlaneUV);
+	    dst += priv->framePlaneUV;
+	    memcpy (dst, src[1], priv->framePlaneUV);
+            break;
+        case IMGFMT_YUY2:
+	    dst = (uint8_t *) *( (uint8_t **) priv->overlay->pixels);
+	    memcpy (dst, src[0], priv->width*priv->height*2);
+            break;
+        }
+        	
+	SDL_UnlockYUVOverlay (priv->overlay);
+
+	return 0;
+}
+
+
+/**
+ * Draw a slice (16 rows of image) to the SDL YUV overlay.
+ *
+ *   params : *src[] == the Y, U, and V planes that make up the slice.
+ *  returns : non-zero on error, zero on success.
+ **/
+
+static uint32_t draw_slice(uint8_t *src[], uint32_t slice_num)
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+	uint8_t *dst;
+
+	//priv->current_frame = priv->overlay;
+	
+	if (SDL_LockYUVOverlay (priv->overlay)) {
+//		LOG (LOG_ERROR, "SDL video out: Couldn't lock SDL-based YUV overlay");
+		return -1;
+	}
+
+	dst = (uint8_t *) *( (uint8_t **) priv->overlay->pixels) + (priv->slicePlaneY * slice_num);
+	memcpy (dst, src[0], priv->slicePlaneY);
+	dst = (uint8_t *) *( (uint8_t **) priv->overlay->pixels) + priv->framePlaneY + (priv->slicePlaneUV * slice_num);
+	memcpy (dst, src[2], priv->slicePlaneUV);
+	dst += priv->framePlaneUV;
+	memcpy (dst, src[1], priv->slicePlaneUV);
+	
+	SDL_UnlockYUVOverlay (priv->overlay);
+
+	return 0;
+}
+
+
+
+/**
+ * Checks for SDL keypress and window resize events
+ *
+ *   params : none
+ *  returns : doesn't return
+ **/
+
+#include "../linux/keycodes.h"
+extern void mplayer_put_key(int code);
+ 
+static void check_events (void)
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+	SDL_Event event;
+	SDLKey keypressed;
+	
+	/* Poll the waiting SDL Events */
+	while ( SDL_PollEvent(&event) ) {
+		switch (event.type) {
+
+			/* capture window resize events */
+			case SDL_VIDEORESIZE:
+				priv->surface = SDL_SetVideoMode(event.resize.w, event.resize.h, priv->bpp, priv->sdlflags);
+
+				/* save video extents, to restore them after going fullscreen */
+			 	//if(!(priv->surface->flags & SDL_FULLSCREEN)) {
+				    priv->windowsize.w = priv->surface->w;
+				    priv->windowsize.h = priv->surface->h;
+				//}
+//				LOG (LOG_DEBUG, "SDL video out: Window resize");
+			break;
+			
+			
+			/* graphics mode selection shortcuts */
+			case SDL_KEYDOWN:
+				keypressed = event.key.keysym.sym;
+				
+				/* plus key pressed. plus cycles through available fullscreenmodes, if we have some */
+				if ( ((keypressed == SDLK_PLUS) || (keypressed == SDLK_KP_PLUS)) && (priv->fullmodes) ) {
+					/* select next fullscreen mode */
+					priv->fullmode++;
+					if (priv->fullmode > (findArrayEnd(priv->fullmodes) - 1)) priv->fullmode = 0;
+					set_fullmode(priv->fullmode);
+	
+//					LOG (LOG_DEBUG, "SDL video out: Set next available fullscreen mode.");
+				}
+
+				/* return or escape key pressed toggles/exits fullscreenmode */
+				else if ( (keypressed == SDLK_RETURN) || (keypressed == SDLK_ESCAPE) ) {
+				 	if (priv->surface->flags & SDL_FULLSCREEN) {
+						priv->surface = SDL_SetVideoMode(priv->windowsize.w, priv->windowsize.h, priv->bpp, priv->sdlflags);
+						SDL_ShowCursor(1);
+						
+//						LOG (LOG_DEBUG, "SDL video out: Windowed mode");
+					} 
+					else if (priv->fullmodes){
+						set_fullmode(priv->fullmode);
+
+//						LOG (LOG_DEBUG, "SDL video out: Set fullscreen mode.");
+					}
+				}
+                                
+                                else switch(keypressed){
+                                case SDLK_q: if(!(priv->surface->flags & SDL_FULLSCREEN))mplayer_put_key('q');break;
+//                                case SDLK_p: mplayer_put_key('p');break;
+                                case SDLK_SPACE: mplayer_put_key(' ');break;
+                                case SDLK_UP: mplayer_put_key(KEY_UP);break;
+                                case SDLK_DOWN: mplayer_put_key(KEY_DOWN);break;
+                                case SDLK_LEFT: mplayer_put_key(KEY_LEFT);break;
+                                case SDLK_RIGHT: mplayer_put_key(KEY_RIGHT);break;
+                                case SDLK_PLUS:
+                                case SDLK_KP_PLUS: mplayer_put_key('+');break;
+                                case SDLK_MINUS:
+                                case SDLK_KP_MINUS: mplayer_put_key('-');break;
+                                }
+                                
+				break;
+		}
+	}
+}
+
+
+/**
+ * Display the surface we have written our data to and check for events.
+ *
+ *   params : mode == index of the desired fullscreen mode
+ *  returns : doesn't return
+ **/
+
+static void flip_page (void)
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+        SDL_Rect blat;
+
+	/* check and react on keypresses and window resizes */
+	check_events();
+
+	/* blit to the YUV overlay */
+	blat.x =priv->surface->clip_minx;
+        blat.y =priv->surface->clip_miny;
+        blat.w =priv->surface->clip_maxx - priv->surface->clip_minx;
+        blat.h =priv->surface->clip_maxy - priv->surface->clip_miny;
+	SDL_DisplayYUVOverlay (priv->overlay, &blat);
+
+	/* check if we have a double buffered surface and flip() if we do. */
+	if ( priv->surface->flags & SDL_DOUBLEBUF )
+        	SDL_Flip(priv->surface);
+	
+	SDL_LockYUVOverlay (priv->overlay);
+}
+
+#if 0
+static frame_t* sdl_allocate_image_buffer(int width, int height)
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+	frame_t	*frame;
+
+	if (!(frame = malloc (sizeof (frame_t))))
+		return NULL;
+
+	if (!(frame->private = (void*) SDL_CreateYUVOverlay (width, height, 
+			SDL_IYUV_OVERLAY, priv->surface)))
+	{
+//		LOG (LOG_ERROR, "SDL video out: Couldn't create an SDL-based YUV overlay");
+		return NULL;
+	}
+	
+	frame->base[0] = (uint8_t*) ((SDL_Overlay*) (frame->private))->pixels[0];
+	frame->base[1] = (uint8_t*) ((SDL_Overlay*) (frame->private))->pixels[1];
+	frame->base[2] = (uint8_t*) ((SDL_Overlay*) (frame->private))->pixels[2];
+	
+	SDL_LockYUVOverlay ((SDL_Overlay*) frame->private);
+	return frame;
+}
+
+static void sdl_free_image_buffer(frame_t* frame)
+{
+	SDL_FreeYUVOverlay((SDL_Overlay*) frame->private);
+	free(frame);
+}
+#endif
+
+static uint32_t
+query_format(uint32_t format)
+{
+    switch(format){
+    case IMGFMT_YV12:
+    case IMGFMT_YUY2:
+//    case IMGFMT_RGB|24:
+//    case IMGFMT_BGR|24:
+        return 1;
+    }
+    return 0;
+}
+
+static const vo_info_t*
+get_info(void)
+{
+	return &vo_info;
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/Attic/SHIT/video_out_x11.c.OLD	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,518 @@
+#define DISP
+
+/* 
+ * video_out_x11.c, X11 interface
+ *
+ *
+ * Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. 
+ *
+ * Hacked into mpeg2dec by
+ * 
+ * Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * 15 & 16 bpp support added by Franck Sicard <Franck.Sicard@solsoft.fr>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+LIBVO_EXTERN(x11)
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/XShm.h>
+#include <errno.h>
+#include "yuv2rgb.h"
+
+static vo_info_t vo_info = 
+{
+	"X11 (XImage/Shm)",
+	"x11",
+	"Aaron Holtzman <aholtzma@ess.engr.uvic.ca>",
+	""
+};
+
+/* private prototypes */
+static void Display_Image (XImage * myximage, unsigned char *ImageData);
+
+/* since it doesn't seem to be defined on some platforms */
+int XShmGetEventBase(Display*);
+
+/* local data */
+static unsigned char *ImageData;
+
+/* X11 related variables */
+static Display *mydisplay;
+static Window mywindow;
+static GC mygc;
+static XImage *myximage;
+static int depth, bpp, mode;
+static XWindowAttributes attribs;
+static int X_already_started = 0;
+
+#define SH_MEM
+
+#ifdef SH_MEM
+
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <X11/extensions/XShm.h>
+
+//static int HandleXError _ANSI_ARGS_((Display * dpy, XErrorEvent * event));
+static void InstallXErrorHandler (void);
+static void DeInstallXErrorHandler (void);
+
+static int Shmem_Flag;
+static int Quiet_Flag;
+static XShmSegmentInfo Shminfo[1];
+static int gXErrorFlag;
+static int CompletionType = -1;
+
+static void InstallXErrorHandler()
+{
+	//XSetErrorHandler(HandleXError);
+	XFlush(mydisplay);
+}
+
+static void DeInstallXErrorHandler()
+{
+	XSetErrorHandler(NULL);
+	XFlush(mydisplay);
+}
+
+#endif
+
+static uint32_t image_width;
+static uint32_t image_height;
+static uint32_t image_format;
+
+extern void vo_decoration( Display * vo_Display,Window w,int d );
+
+/* connect to server, create and map window,
+ * allocate colors and (shared) memory
+ */
+static uint32_t 
+init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
+{
+	int screen;
+	unsigned int fg, bg;
+	char *hello = (title == NULL) ? "I hate X11" : title;
+	char *name = ":0.0";
+	XSizeHints hint;
+	XVisualInfo vinfo;
+	XEvent xev;
+	XGCValues xgcv;
+	Colormap theCmap;
+	XSetWindowAttributes xswa;
+	unsigned long xswamask;
+
+	image_height = height;
+	image_width = width;
+        image_format=format;
+
+	if (X_already_started) return -1;
+        if(!vo_init()) return 0; // Can't open X11
+
+	if(getenv("DISPLAY")) name = getenv("DISPLAY");
+
+	mydisplay = XOpenDisplay(name);
+
+	if (mydisplay == NULL)
+	{
+		fprintf(stderr,"Can not open display\n");
+		return -1;
+	}
+
+	screen = DefaultScreen(mydisplay);
+
+	hint.x = 0;
+	hint.y = 0;
+	hint.width = image_width;
+	hint.height = image_height;
+	hint.flags = PPosition | PSize;
+
+	/* Get some colors */
+
+	bg = WhitePixel(mydisplay, screen);
+	fg = BlackPixel(mydisplay, screen);
+
+	XGetWindowAttributes(mydisplay, DefaultRootWindow(mydisplay), &attribs);
+	depth = attribs.depth;
+//        depth = vo_depthonscreen;
+        
+	if (depth != 15 && depth != 16 && depth != 24 && depth != 32) 
+	{
+		/* The root window may be 8bit but there might still be
+		* visuals with other bit depths. For example this is the 
+		* case on Sun/Solaris machines.
+		*/
+		depth = 24;
+	}
+	//BEGIN HACK
+	//mywindow = XCreateSimpleWindow(mydisplay, DefaultRootWindow(mydisplay),
+	//hint.x, hint.y, hint.width, hint.height, 4, fg, bg);
+	//
+	XMatchVisualInfo(mydisplay, screen, depth, TrueColor, &vinfo);
+
+	theCmap   = XCreateColormap(mydisplay, RootWindow(mydisplay,screen), 
+	vinfo.visual, AllocNone);
+
+	xswa.background_pixel = 0;
+	xswa.border_pixel     = 1;
+	xswa.colormap         = theCmap;
+	xswamask = CWBackPixel | CWBorderPixel |CWColormap;
+
+
+	mywindow = XCreateWindow(mydisplay, RootWindow(mydisplay,screen),
+	hint.x, hint.y, hint.width, hint.height, 4, depth,CopyFromParent,vinfo.visual,xswamask,&xswa);
+
+        if ( fullscreen ) vo_decoration( mydisplay,mywindow,0 );
+
+	XSelectInput(mydisplay, mywindow, StructureNotifyMask);
+
+	/* Tell other applications about this window */
+
+	XSetStandardProperties(mydisplay, mywindow, hello, hello, None, NULL, 0, &hint);
+
+	/* Map window. */
+
+	XMapWindow(mydisplay, mywindow);
+
+	/* Wait for map. */
+	do 
+	{
+		XNextEvent(mydisplay, &xev);
+	}
+	while (xev.type != MapNotify || xev.xmap.event != mywindow);
+
+	XSelectInput(mydisplay, mywindow, NoEventMask);
+
+	XFlush(mydisplay);
+	XSync(mydisplay, False);
+
+	mygc = XCreateGC(mydisplay, mywindow, 0L, &xgcv);
+
+#ifdef SH_MEM
+	if (XShmQueryExtension(mydisplay))
+		Shmem_Flag = 1;
+	else 
+	{
+		Shmem_Flag = 0;
+		if (!Quiet_Flag)
+			fprintf(stderr, "Shared memory not supported\nReverting to normal Xlib\n");
+	}
+	if (Shmem_Flag)
+		CompletionType = XShmGetEventBase(mydisplay) + ShmCompletion;
+
+	InstallXErrorHandler();
+
+	if (Shmem_Flag) 
+	{
+		myximage = XShmCreateImage(mydisplay, vinfo.visual, 
+		depth, ZPixmap, NULL, &Shminfo[0], width, image_height);
+
+		/* If no go, then revert to normal Xlib calls. */
+
+		if (myximage == NULL ) 
+		{
+			if (myximage != NULL)
+				XDestroyImage(myximage);
+			if (!Quiet_Flag)
+				fprintf(stderr, "Shared memory error, disabling (Ximage error)\n");
+
+			goto shmemerror;
+		}
+		/* Success here, continue. */
+
+		Shminfo[0].shmid = shmget(IPC_PRIVATE, 
+		myximage->bytes_per_line * myximage->height ,
+		IPC_CREAT | 0777);
+		if (Shminfo[0].shmid < 0 ) 
+		{
+			XDestroyImage(myximage);
+			if (!Quiet_Flag)
+			{
+				printf("%s\n",strerror(errno));
+				perror(strerror(errno));
+				fprintf(stderr, "Shared memory error, disabling (seg id error)\n");
+			}
+			goto shmemerror;
+		}
+		Shminfo[0].shmaddr = (char *) shmat(Shminfo[0].shmid, 0, 0);
+
+		if (Shminfo[0].shmaddr == ((char *) -1)) 
+		{
+			XDestroyImage(myximage);
+			if (Shminfo[0].shmaddr != ((char *) -1))
+				shmdt(Shminfo[0].shmaddr);
+			if (!Quiet_Flag) 
+				fprintf(stderr, "Shared memory error, disabling (address error)\n");
+			goto shmemerror;
+		}
+		myximage->data = Shminfo[0].shmaddr;
+		ImageData = (unsigned char *) myximage->data;
+		Shminfo[0].readOnly = False;
+		XShmAttach(mydisplay, &Shminfo[0]);
+
+		XSync(mydisplay, False);
+
+		if (gXErrorFlag) 
+		{
+			/* Ultimate failure here. */
+			XDestroyImage(myximage);
+			shmdt(Shminfo[0].shmaddr);
+			if (!Quiet_Flag)
+				fprintf(stderr, "Shared memory error, disabling.\n");
+			gXErrorFlag = 0;
+			goto shmemerror;
+		} 
+		else 
+		{
+			shmctl(Shminfo[0].shmid, IPC_RMID, 0);
+		}
+
+		if (!Quiet_Flag) 
+		{
+			fprintf(stderr, "Sharing memory.\n");
+		}
+	} 
+	else 
+	{
+		shmemerror:
+		Shmem_Flag = 0;
+#endif
+		myximage = XGetImage(mydisplay, mywindow, 0, 0,
+		width, image_height, AllPlanes, ZPixmap);
+		ImageData = myximage->data;
+#ifdef SH_MEM
+	}
+
+	DeInstallXErrorHandler();
+#endif
+
+	bpp = myximage->bits_per_pixel;
+        
+        printf("X11 color mask:  R:%X  G:%X  B:%X\n",
+             myximage->red_mask,myximage->green_mask,myximage->blue_mask);
+
+	// If we have blue in the lowest bit then obviously RGB 
+	mode = ((myximage->blue_mask & 0x01) != 0) ? MODE_RGB : MODE_BGR;
+//	mode = ((myximage->blue_mask & 0x01) == 0) ? MODE_RGB : MODE_BGR;
+#ifdef WORDS_BIGENDIAN 
+	if (myximage->byte_order != MSBFirst)
+#else
+	if (myximage->byte_order != LSBFirst) 
+#endif
+	{
+		fprintf( stderr, "No support fon non-native XImage byte order!\n" );
+		return -1;
+	}
+
+	/* 
+	 * If depth is 24 then it may either be a 3 or 4 byte per pixel
+	 * format. We can't use bpp because then we would lose the 
+	 * distinction between 15/16bit depth (2 byte formate assumed).
+	 *
+	 * FIXME - change yuv2rgb_init to take both depth and bpp
+	 * parameters
+	 */
+	if(format==IMGFMT_YV12) yuv2rgb_init((depth == 24) ? bpp : depth, mode);
+
+        XSelectInput(mydisplay, mywindow, StructureNotifyMask | KeyPressMask );
+	X_already_started++;
+	return 0;
+}
+
+static const vo_info_t*
+get_info(void)
+{
+	return &vo_info;
+}
+
+
+static void 
+Terminate_Display_Process(void) 
+{
+	getchar();	/* wait for enter to remove window */
+#ifdef SH_MEM
+	if (Shmem_Flag) 
+	{
+		XShmDetach(mydisplay, &Shminfo[0]);
+		XDestroyImage(myximage);
+		shmdt(Shminfo[0].shmaddr);
+	}
+#endif
+	XDestroyWindow(mydisplay, mywindow);
+	XCloseDisplay(mydisplay);
+	X_already_started = 0;
+}
+
+static void 
+Display_Image(XImage *myximage, uint8_t *ImageData)
+{
+#ifdef DISP
+#ifdef SH_MEM
+	if (Shmem_Flag) 
+	{
+		XShmPutImage(mydisplay, mywindow, mygc, myximage, 
+				0, 0, 0, 0, myximage->width, myximage->height, True); 
+		XFlush(mydisplay);
+	} 
+	else
+#endif
+	{
+		XPutImage(mydisplay, mywindow, mygc, myximage, 0, 0, 0, 0, 
+				myximage->width, myximage->height);
+		XFlush(mydisplay);
+	}
+#endif
+}
+
+
+static void
+flip_page(void)
+{
+
+ int            i;
+ XEvent         Event;
+ char           buf[100];
+ KeySym         keySym;
+ XComposeStatus stat;
+ unsigned long  vo_KeyTable[512];
+
+ while ( XPending( mydisplay ) )
+  {
+   XNextEvent( mydisplay,&Event );
+   switch( Event.type )
+    {
+       case ConfigureNotify:
+//             windowwidth = Event.xconfigure.width;
+//             windowheight = Event.xconfigure.height;
+             break;
+       case KeyPress:
+             XLookupString( &Event.xkey,buf,sizeof(buf),&keySym,&stat );
+             vo_keyboard( ( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ) );
+             break;
+    }
+  }
+
+  Display_Image(myximage, ImageData);
+}
+
+
+static uint32_t
+draw_slice(uint8_t *src[], uint32_t slice_num)
+{
+	uint8_t *dst;
+
+	dst = ImageData + image_width * 16 * (bpp/8) * slice_num;
+
+	yuv2rgb(dst , src[0], src[1], src[2], 
+			image_width, 16, 
+			image_width*(bpp/8), image_width, image_width/2 );
+	return 0;
+}
+
+void rgb15to16_mmx(char* s0,char* d0,int count);
+
+#if 1
+static uint32_t
+draw_frame(uint8_t *src[])
+{
+    if(image_format==IMGFMT_YV12){
+	yuv2rgb(ImageData, src[0], src[1], src[2],
+		image_width, image_height, 
+		image_width*(bpp/8), image_width, image_width/2 );
+    } else {
+        int sbpp=((image_format&0xFF)+7)/8;
+        int dbpp=(bpp+7)/8;
+        char *d=ImageData;
+        char *s=src[0];
+        //printf("sbpp=%d  dbpp=%d  depth=%d  bpp=%d\n",sbpp,dbpp,depth,bpp);
+#if 0
+        // flipped BGR
+        int i;
+//        printf("Rendering flipped BGR frame  bpp=%d  src=%d  dst=%d\n",bpp,sbpp,dbpp);
+        s+=sbpp*image_width*image_height;
+        for(i=0;i<image_height;i++){
+          s-=sbpp*image_width;
+          if(sbpp==dbpp)
+            memcpy(d,s,sbpp*image_width);
+          else {
+            char *s2=s;
+            char *d2=d;
+            char *e=s2+sbpp*image_width;
+            while(s2<e){
+              d2[0]=s2[0];
+              d2[1]=s2[1];
+              d2[2]=s2[2];
+              s2+=sbpp;d2+=dbpp;
+            }
+          }
+          d+=dbpp*image_width;
+        }
+#else
+//        memcpy(ImageData,src[0],image_width*image_height*bpp);
+          if(sbpp==dbpp){
+  	    //Display_Image(myximage, s);return 0;
+#if 1
+            if(depth==16 && image_format==(IMGFMT_BGR|15)){
+              // do 15bpp->16bpp
+#ifdef HAVE_MMX
+              rgb15to16_mmx(s,d,2*image_width*image_height);
+#else
+              unsigned short *s1=(unsigned short *)s;
+              unsigned short *d1=(unsigned short *)d;
+              unsigned short *e=s1+image_width*image_height;
+              while(s1<e){
+                register int x=*(s1++);
+                // rrrrrggggggbbbbb
+                // 0rrrrrgggggbbbbb
+                // 0111 1111 1110 0000 = 0x7FE0
+                // 00000000000001 1111 = 0x001F
+                *(d1++)=(x&0x001F)|((x&0x7FE0)<<1);
+              }
+#endif
+            } else
+#endif
+            {
+              memcpy(d,s,sbpp*image_width*image_height);
+            }
+          } else {
+            char *e=s+sbpp*image_width*image_height;
+            //printf("libvo: using C 24->32bpp conversion\n");
+            while(s<e){
+              d[0]=s[0];
+              d[1]=s[1];
+              d[2]=s[2];
+              s+=sbpp;d+=dbpp;
+            }
+          }
+#endif
+    }
+	//Display_Image(myximage, ImageData);
+	return 0; 
+}
+#endif
+
+
+
+static uint32_t
+query_format(uint32_t format)
+{
+    if(!vo_init()) return 0; // Can't open X11
+    
+    if((format&IMGFMT_BGR_MASK)==IMGFMT_BGR && (format&0xFF)==vo_depthonscreen) return 1;
+    
+    switch(format){
+    case IMGFMT_YV12:
+        return 1;
+    }
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/Attic/SHIT/video_out_x11.c.thread	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,466 @@
+#define DISP
+
+/*
+ * video_out_x11.c,X11 interface
+ *
+ *
+ * Copyright ( C ) 1996,MPEG Software Simulation Group. All Rights Reserved.
+ *
+ * Hacked into mpeg2dec by
+ *
+ * Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * 15 & 16 bpp support added by Franck Sicard <Franck.Sicard@solsoft.fr>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+LIBVO_EXTERN( x11 )
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/XShm.h>
+#include <errno.h>
+#include "yuv2rgb.h"
+
+static vo_info_t vo_info =
+{
+        "X11 ( XImage/Shm )",
+        "x11",
+        "Aaron Holtzman <aholtzma@ess.engr.uvic.ca>",
+        ""
+};
+
+/* private prototypes */
+static void Display_Image ( XImage * myximage,unsigned char *ImageData );
+
+/* since it doesn't seem to be defined on some platforms */
+int XShmGetEventBase( Display* );
+
+/* local data */
+static unsigned char *ImageData;
+
+/* X11 related variables */
+static Display *mDisplay;
+static Window mywindow;
+static GC mygc;
+static XImage *myximage;
+static int depth,bpp,mode;
+static XWindowAttributes attribs;
+static int X_already_started=0;
+
+static int windowwidth,windowheight;
+
+#define SH_MEM
+
+#ifdef SH_MEM
+
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <X11/extensions/XShm.h>
+
+//static int HandleXError _ANSI_ARGS_( ( Display * dpy,XErrorEvent * event ) );
+static void InstallXErrorHandler ( void );
+static void DeInstallXErrorHandler ( void );
+
+static int Shmem_Flag;
+static int Quiet_Flag;
+static XShmSegmentInfo Shminfo[1];
+static int gXErrorFlag;
+static int CompletionType=-1;
+
+static void InstallXErrorHandler()
+{
+        //XSetErrorHandler( HandleXError );
+        XFlush( mDisplay );
+}
+
+static void DeInstallXErrorHandler()
+{
+        XSetErrorHandler( NULL );
+        XFlush( mDisplay );
+}
+
+#endif
+
+static uint32_t image_width;
+static uint32_t image_height;
+static uint32_t image_format;
+
+extern void vo_decoration( Display * vo_Display,Window w,int d );
+
+static Bool mEvents( Display * display,XEvent * Event,XPointer arg )
+{
+ int            i;
+ char           buf[100];
+ KeySym         keySym;
+ XComposeStatus stat;
+ unsigned long  vo_KeyTable[512];
+
+ switch( Event->type )
+  {
+   case ConfigureNotify:
+         windowwidth=Event->xconfigure.width;
+         windowheight=Event->xconfigure.height;
+         break;
+   case KeyPress:
+         XLookupString( &Event->xkey,buf,sizeof(buf),&keySym,&stat );
+         vo_keyboard( ( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ) );
+         break;
+  }
+ return 0;
+}
+
+static XEvent mEvent;
+
+static void mThread( void )
+{
+printf("thread okey!\n");
+ XIfEvent( mDisplay,&mEvent,mEvents,NULL ); 
+}
+
+static uint32_t init( uint32_t width,uint32_t height,uint32_t d_width,uint32_t d_height,uint32_t fullscreen,char *title,uint32_t format )
+{
+ int screen;
+ unsigned int fg,bg;
+ char *hello=( title == NULL ) ? "X11 render" : title;
+ char *name=":0.0";
+ XSizeHints hint;
+ XVisualInfo vinfo;
+ XEvent xev;
+ XGCValues xgcv;
+ Colormap theCmap;
+ XSetWindowAttributes xswa;
+ unsigned long xswamask;
+
+ image_height=height;
+ image_width=width;
+ image_format=format;
+
+ if ( X_already_started ) return -1;
+ if( !vo_init() ) return 0; // Can't open X11
+
+ if( getenv( "DISPLAY" ) ) name=getenv( "DISPLAY" );
+
+ mDisplay=XOpenDisplay( name );
+
+ if ( mDisplay == NULL )
+  {
+   fprintf( stderr,"Can not open display\n" );
+   return -1;
+  }
+
+ screen=DefaultScreen( mDisplay );
+
+ hint.x=0;
+ hint.y=0;
+ hint.width=image_width;
+ hint.height=image_height;
+ if ( fullscreen )
+  {
+   hint.width=vo_screenwidth;
+   hint.height=vo_screenheight;
+  }
+ windowwidth=hint.width;
+ windowheight=hint.height;
+ hint.flags=PPosition | PSize;
+
+ bg=WhitePixel( mDisplay,screen );
+ fg=BlackPixel( mDisplay,screen );
+
+ XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs );
+ depth=attribs.depth;
+
+ if ( depth != 15 && depth != 16 && depth != 24 && depth != 32 ) depth=24;
+ XMatchVisualInfo( mDisplay,screen,depth,TrueColor,&vinfo );
+
+ theCmap  =XCreateColormap( mDisplay,RootWindow( mDisplay,screen ),
+ vinfo.visual,AllocNone );
+
+ xswa.background_pixel=0;
+ xswa.border_pixel=1;
+ xswa.colormap=theCmap;
+ xswamask=CWBackPixel | CWBorderPixel |CWColormap;
+
+ mywindow=XCreateWindow( mDisplay,RootWindow( mDisplay,screen ),
+                         hint.x,hint.y,
+                         hint.width,hint.height,
+                         xswa.border_pixel,depth,CopyFromParent,vinfo.visual,xswamask,&xswa );
+
+ if ( fullscreen ) vo_decoration( mDisplay,mywindow,0 );
+ XSelectInput( mDisplay,mywindow,StructureNotifyMask );
+ XSetStandardProperties( mDisplay,mywindow,hello,hello,None,NULL,0,&hint );
+ XMapWindow( mDisplay,mywindow );
+ do { XNextEvent( mDisplay,&xev ); } while ( xev.type != MapNotify || xev.xmap.event != mywindow );
+
+ XSelectInput( mDisplay,mywindow,NoEventMask );
+
+ XFlush( mDisplay );
+ XSync( mDisplay,False );
+
+ mygc=XCreateGC( mDisplay,mywindow,0L,&xgcv );
+
+#ifdef SH_MEM
+ if ( XShmQueryExtension( mDisplay ) ) Shmem_Flag=1;
+  else
+   {
+    Shmem_Flag=0;
+    if ( !Quiet_Flag ) fprintf( stderr,"Shared memory not supported\nReverting to normal Xlib\n" );
+   }
+ if ( Shmem_Flag ) CompletionType=XShmGetEventBase( mDisplay ) + ShmCompletion;
+
+ InstallXErrorHandler();
+
+ if ( Shmem_Flag )
+  {
+   myximage=XShmCreateImage( mDisplay,vinfo.visual,depth,ZPixmap,NULL,&Shminfo[0],width,image_height );
+   if ( myximage == NULL )
+    {
+     if ( myximage != NULL ) XDestroyImage( myximage );
+     if ( !Quiet_Flag ) fprintf( stderr,"Shared memory error,disabling ( Ximage error )\n" );
+     goto shmemerror;
+    }
+   Shminfo[0].shmid=shmget( IPC_PRIVATE,
+   myximage->bytes_per_line * myximage->height ,
+   IPC_CREAT | 0777 );
+   if ( Shminfo[0].shmid < 0 )
+   {
+    XDestroyImage( myximage );
+    if ( !Quiet_Flag )
+     {
+      printf( "%s\n",strerror( errno ) );
+      perror( strerror( errno ) );
+      fprintf( stderr,"Shared memory error,disabling ( seg id error )\n" );
+     }
+    goto shmemerror;
+   }
+   Shminfo[0].shmaddr=( char * ) shmat( Shminfo[0].shmid,0,0 );
+
+   if ( Shminfo[0].shmaddr == ( ( char * ) -1 ) )
+   {
+    XDestroyImage( myximage );
+    if ( Shminfo[0].shmaddr != ( ( char * ) -1 ) ) shmdt( Shminfo[0].shmaddr );
+    if ( !Quiet_Flag ) fprintf( stderr,"Shared memory error,disabling ( address error )\n" );
+    goto shmemerror;
+   }
+   myximage->data=Shminfo[0].shmaddr;
+   ImageData=( unsigned char * ) myximage->data;
+   Shminfo[0].readOnly=False;
+   XShmAttach( mDisplay,&Shminfo[0] );
+
+   XSync( mDisplay,False );
+
+   if ( gXErrorFlag )
+   {
+    XDestroyImage( myximage );
+    shmdt( Shminfo[0].shmaddr );
+    if ( !Quiet_Flag ) fprintf( stderr,"Shared memory error,disabling.\n" );
+    gXErrorFlag=0;
+    goto shmemerror;
+   }
+   else
+    shmctl( Shminfo[0].shmid,IPC_RMID,0 );
+
+   if ( !Quiet_Flag ) fprintf( stderr,"Sharing memory.\n" );
+ }
+ else
+  {
+   shmemerror:
+   Shmem_Flag=0;
+#endif
+   myximage=XGetImage( mDisplay,mywindow,0,0,
+   width,image_height,AllPlanes,ZPixmap );
+   ImageData=myximage->data;
+#ifdef SH_MEM
+  }
+
+  DeInstallXErrorHandler();
+#endif
+
+  bpp=myximage->bits_per_pixel;
+
+  fprintf( stderr,"X11 color mask:  R:%X  G:%X  B:%X\n",myximage->red_mask,myximage->green_mask,myximage->blue_mask );
+
+  // If we have blue in the lowest bit then obviously RGB
+  mode=( ( myximage->blue_mask & 0x01 ) != 0 ) ? MODE_RGB : MODE_BGR;
+#ifdef WORDS_BIGENDIAN
+  if ( myximage->byte_order != MSBFirst )
+#else
+  if ( myximage->byte_order != LSBFirst )
+#endif
+  {
+   fprintf( stderr,"No support fon non-native XImage byte order!\n" );
+   return -1;
+  }
+
+ if( format==IMGFMT_YV12 ) yuv2rgb_init( ( depth == 24 ) ? bpp : depth,mode );
+
+ XSelectInput( mDisplay,mywindow,StructureNotifyMask | KeyPressMask );
+ X_already_started++;
+
+ printf("init thread!\n");
+ vo_initthread( mThread );
+
+ return 0;
+}
+
+static const vo_info_t* get_info( void )
+{ return &vo_info; }
+
+static void Terminate_Display_Process( void )
+{
+ getchar();      /* wait for enter to remove window */
+#ifdef SH_MEM
+ if ( Shmem_Flag )
+  {
+   XShmDetach( mDisplay,&Shminfo[0] );
+   XDestroyImage( myximage );
+   shmdt( Shminfo[0].shmaddr );
+  }
+#endif
+ XDestroyWindow( mDisplay,mywindow );
+ XCloseDisplay( mDisplay );
+ X_already_started=0;
+}
+
+static void Display_Image( XImage *myximage,uint8_t *ImageData )
+{
+#ifdef DISP
+#ifdef SH_MEM
+ if ( Shmem_Flag )
+  {
+   XShmPutImage( mDisplay,mywindow,mygc,myximage,
+                 0,0,
+                 ( windowwidth - myximage->width ) / 2,( windowheight - myximage->height ) / 2,
+                 myximage->width,myximage->height,True );
+   XFlush( mDisplay );
+  }
+  else
+#endif
+   {
+    XPutImage( mDisplay,mywindow,mygc,myximage,
+               0,0,
+               ( windowwidth - myximage->width ) / 2,( windowheight - myximage->height ) / 2,
+               myximage->width,myximage->height );
+    XFlush( mDisplay );
+  }
+#endif
+}
+
+static void flip_page( void )
+{ Display_Image( myximage,ImageData ); }
+
+static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y )
+{
+ uint8_t *dst;
+
+ dst=ImageData + ( image_width * y + x ) * ( bpp/8 );
+ yuv2rgb( dst,src[0],src[1],src[2],w,h,image_width*( bpp/8 ),stride[0],stride[1] );
+ return 0;
+}
+
+void rgb15to16_mmx( char* s0,char* d0,int count );
+
+#if 1
+static uint32_t draw_frame( uint8_t *src[] )
+{
+ if( image_format==IMGFMT_YV12 )
+  {
+   yuv2rgb( ImageData,src[0],src[1],src[2],image_width,image_height,image_width*( bpp/8 ),image_width,image_width/2 );
+  }
+  else
+   {
+    int sbpp=( ( image_format&0xFF )+7 )/8;
+    int dbpp=( bpp+7 )/8;
+    char *d=ImageData;
+    char *s=src[0];
+    //printf( "sbpp=%d  dbpp=%d  depth=%d  bpp=%d\n",sbpp,dbpp,depth,bpp );
+#if 0
+    // flipped BGR
+    int i;
+    //printf( "Rendering flipped BGR frame  bpp=%d  src=%d  dst=%d\n",bpp,sbpp,dbpp );
+    s+=sbpp*image_width*image_height;
+    for( i=0;i<image_height;i++ )
+     {
+      s-=sbpp*image_width;
+      if( sbpp==dbpp ) memcpy( d,s,sbpp*image_width );
+       else
+        {
+         char *s2=s;
+         char *d2=d;
+         char *e=s2+sbpp*image_width;
+         while( s2<e )
+          {
+           d2[0]=s2[0];
+           d2[1]=s2[1];
+           d2[2]=s2[2];
+           s2+=sbpp;d2+=dbpp;
+          }
+        }
+      d+=dbpp*image_width;
+     }
+#else
+//   memcpy( ImageData,src[0],image_width*image_height*bpp );
+     if( sbpp==dbpp )
+      {
+       //Display_Image( myximage,s );return 0;
+#if 1
+       if( depth==16 && image_format==( IMGFMT_BGR|15 ) ){
+       // do 15bpp->16bpp
+#ifdef HAVE_MMX
+       rgb15to16_mmx( s,d,2*image_width*image_height );
+#else
+       unsigned short *s1=( unsigned short * )s;
+       unsigned short *d1=( unsigned short * )d;
+       unsigned short *e=s1+image_width*image_height;
+       while( s1<e )
+        {
+         register int x=*( s1++ );
+         // rrrrrggggggbbbbb
+         // 0rrrrrgggggbbbbb
+         // 0111 1111 1110 0000=0x7FE0
+         // 00000000000001 1111=0x001F
+         *( d1++ )=( x&0x001F )|( ( x&0x7FE0 )<<1 );
+        }
+#endif
+      }
+      else
+#endif
+       { memcpy( d,s,sbpp*image_width*image_height ); }
+   }
+   else
+    {
+     char *e=s+sbpp*image_width*image_height;
+     //printf( "libvo: using C 24->32bpp conversion\n" );
+     while( s<e )
+      {
+       d[0]=s[0];
+       d[1]=s[1];
+       d[2]=s[2];
+       s+=sbpp;d+=dbpp;
+      }
+   }
+#endif
+  }
+ //Display_Image( myximage,ImageData );
+ return 0;
+}
+#endif
+
+static uint32_t query_format( uint32_t format )
+{
+ if( !vo_init() ) return 0; // Can't open X11
+ if( ( format&IMGFMT_BGR_MASK )==IMGFMT_BGR && ( format&0xFF )==vo_depthonscreen ) return 1;
+ switch( format )
+  {
+   case IMGFMT_YV12: return 1;
+  }
+ return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/Makefile	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,37 @@
+
+include config.mak
+
+LIBNAME = libvo.a
+
+SRCS=rgb15to16mmx.c yuv2rgb_mmx.c yuv2rgb.c video_out.c vo_null.c vo_pgm.c vo_md5.c vo_odivx.c $(OPTIONAL_SRCS)
+OBJS=rgb15to16mmx.o yuv2rgb_mmx.o yuv2rgb.o video_out.o vo_null.o vo_pgm.o vo_md5.o vo_odivx.o $(OPTIONAL_OBJS)
+
+CFLAGS  = $(OPTFLAGS) -DMPG12PLAY
+INCLUDE = -I. -I..
+# -I/usr/X11R6/include/
+
+.SUFFIXES: .c .o
+
+# .PHONY: all clean
+
+.c.o:
+	$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $<
+
+$(LIBNAME):     $(OBJS)
+	$(AR) r $(LIBNAME) $(OBJS)
+
+all:    $(LIBNAME)
+
+clean:
+	rm -f *.o *.a *~
+
+distclean:
+	makedepend
+	rm -f Makefile.bak *.o *.a *~
+
+dep:    depend
+
+depend:
+	makedepend -- $(CFLAGS) -- $(SRCS) &> /dev/null
+
+# DO NOT DELETE
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/config.mak	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,6 @@
+
+include ../config.mak
+
+OPTIONAL_SRCS= vo_gl.c vo_x11.c vo_mga.c vo_xmga.c vo_syncfb.c
+OPTIONAL_OBJS=vo_gl.o vo_x11.o vo_mga.o vo_xmga.o vo_syncfb.o
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/mga_common.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,220 @@
+
+// mga_vid drawing functions
+
+static void
+write_frame_g200(uint8_t *y,uint8_t *cr, uint8_t *cb)
+{
+	uint8_t *dest;
+	uint32_t bespitch,h,w;
+
+	dest = vid_data;
+	bespitch = (mga_vid_config.src_width + 31) & ~31;
+
+	for(h=0; h < mga_vid_config.src_height; h++)
+	{
+		memcpy(dest, y, mga_vid_config.src_width);
+		y += mga_vid_config.src_width;
+		dest += bespitch;
+	}
+
+	for(h=0; h < mga_vid_config.src_height/2; h++)
+	{
+		for(w=0; w < mga_vid_config.src_width/2; w++)
+		{
+			*dest++ = *cb++;
+			*dest++ = *cr++;
+		}
+		dest += bespitch - mga_vid_config.src_width;
+	}
+}
+
+static void
+write_frame_g400(uint8_t *y,uint8_t *cr, uint8_t *cb)
+{
+	uint8_t *dest;
+	uint32_t bespitch,h;
+
+	dest = vid_data;
+	bespitch = (mga_vid_config.src_width + 31) & ~31;
+
+	for(h=0; h < mga_vid_config.src_height; h++) 
+	{
+		memcpy(dest, y, mga_vid_config.src_width);
+		y += mga_vid_config.src_width;
+		dest += bespitch;
+	}
+
+	for(h=0; h < mga_vid_config.src_height/2; h++) 
+	{
+		memcpy(dest, cb, mga_vid_config.src_width/2);
+		cb += mga_vid_config.src_width/2;
+		dest += bespitch/2;
+	}
+
+	for(h=0; h < mga_vid_config.src_height/2; h++) 
+	{
+		memcpy(dest, cr, mga_vid_config.src_width/2);
+		cr += mga_vid_config.src_width/2;
+		dest += bespitch/2;
+	}
+}
+
+//static void
+//write_slice_g200(uint8_t *y,uint8_t *cr, uint8_t *cb,uint32_t slice_num)
+
+static void
+draw_slice_g200(uint8_t *image[], int stride[], int width,int height,int x,int y)
+{
+	uint8_t *src;
+	uint8_t *src2;
+	uint8_t *dest;
+	uint32_t bespitch,h,w;
+
+		bespitch = (mga_vid_config.src_width + 31) & ~31;
+
+		dest = vid_data + bespitch * y * x;
+        src = image[0];
+		for(h=0; h < height; h++) 
+		{
+			memcpy(dest, src, width);
+			src += stride[0];
+			dest += bespitch;
+		}
+
+        width/=2;height/=2;x/=2;y/=2;
+
+		dest = vid_data +  bespitch * mga_vid_config.src_height + 
+		bespitch * y + 2*x;
+        src = image[1];
+        src2 = image[2];
+	for(h=0; h < height; h++)
+	{
+		for(w=0; w < width; w++)
+		{
+			dest[2*w+0] = src[w];
+			dest[2*w+1] = src2[w];
+		}
+		dest += bespitch;
+        src += stride[1];
+        src2+= stride[2];
+	}
+}
+
+static void
+draw_slice_g400(uint8_t *image[], int stride[], int w,int h,int x,int y)
+{
+    uint8_t *src;
+    uint8_t *dest;
+    uint32_t bespitch,bespitch2;
+    int i;
+
+    bespitch = (mga_vid_config.src_width + 31) & ~31;
+    bespitch2 = bespitch/2;
+
+    dest = vid_data + bespitch * y + x;
+    src = image[0];
+    for(i=0;i<h;i++){
+        memcpy(dest,src,w);
+        src+=stride[0];
+        dest += bespitch;
+    }
+    
+    w/=2;h/=2;x/=2;y/=2;
+    
+    dest = vid_data + bespitch*mga_vid_config.src_height + bespitch2 * y + x;
+    src = image[1];
+    for(i=0;i<h;i++){
+        memcpy(dest,src,w);
+        src+=stride[1];
+        dest += bespitch2;
+    }
+
+    dest = vid_data + bespitch*mga_vid_config.src_height
+                    + bespitch*mga_vid_config.src_height / 4 
+                    + bespitch2 * y + x;
+    src = image[2];
+    for(i=0;i<h;i++){
+        memcpy(dest,src,w);
+        src+=stride[2];
+        dest += bespitch2;
+    }
+
+}
+
+static uint32_t
+draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
+{
+	if (mga_vid_config.card_type == MGA_G200)
+            draw_slice_g200(src,stride,w,h,x,y);
+	else
+            draw_slice_g400(src,stride,w,h,x,y);
+	return 0;
+}
+
+static void
+flip_page(void)
+{
+#if 0
+	ioctl(f,MGA_VID_FSEL,&next_frame);
+
+	if (next_frame) 
+		vid_data = frame1;
+	else
+		vid_data = frame0;
+
+	next_frame = 2 - next_frame; // switch between fields A1 and B1
+
+#endif
+}
+
+
+static void
+write_frame_yuy2(uint8_t *y)
+{
+	uint8_t *dest;
+	uint32_t bespitch,h;
+        int len=2*mga_vid_config.src_width;
+
+	dest = vid_data;
+	bespitch = (mga_vid_config.src_width + 31) & ~31;
+        
+//        y+=2*mga_vid_config.src_width*mga_vid_config.src_height;
+
+	for(h=0; h < mga_vid_config.src_height; h++) 
+	{
+//		y -= 2*mga_vid_config.src_width;
+		memcpy(dest, y, len);
+		y += len;
+		dest += 2*bespitch;
+	}
+}
+
+
+static uint32_t
+draw_frame(uint8_t *src[])
+{
+        if (mga_vid_config.format==MGA_VID_FORMAT_YUY2)
+                write_frame_yuy2(src[0]);
+        else
+	if (mga_vid_config.card_type == MGA_G200)
+		write_frame_g200(src[0], src[2], src[1]);
+	else
+		write_frame_g400(src[0], src[2], src[1]);
+
+	//flip_page();
+	return 0;
+}
+
+static uint32_t
+query_format(uint32_t format)
+{
+    switch(format){
+    case IMGFMT_YV12:
+    case IMGFMT_YUY2:
+//    case IMGFMT_RGB|24:
+//    case IMGFMT_BGR|24:
+        return 1;
+    }
+    return 0;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/mmx.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,706 @@
+/*	mmx.h
+
+	MultiMedia eXtensions GCC interface library for IA32.
+
+	To use this library, simply include this header file
+	and compile with GCC.  You MUST have inlining enabled
+	in order for mmx_ok() to work; this can be done by
+	simply using -O on the GCC command line.
+
+	Compiling with -DMMX_TRACE will cause detailed trace
+	output to be sent to stderr for each mmx operation.
+	This adds lots of code, and obviously slows execution to
+	a crawl, but can be very useful for debugging.
+
+	THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY
+	EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
+	LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+	AND FITNESS FOR ANY PARTICULAR PURPOSE.
+
+	1997-99 by H. Dietz and R. Fisher
+
+ Notes:
+	It appears that the latest gas has the pand problem fixed, therefore
+	  I'll undefine BROKEN_PAND by default.
+*/
+
+#ifndef _MMX_H
+#define _MMX_H
+
+
+/*	Warning:  at this writing, the version of GAS packaged
+	with most Linux distributions does not handle the
+	parallel AND operation mnemonic correctly.  If the
+	symbol BROKEN_PAND is defined, a slower alternative
+	coding will be used.  If execution of mmxtest results
+	in an illegal instruction fault, define this symbol.
+*/
+#undef	BROKEN_PAND
+
+
+/*	The type of an value that fits in an MMX register
+	(note that long long constant values MUST be suffixed
+	 by LL and unsigned long long values by ULL, lest
+	 they be truncated by the compiler)
+*/
+typedef	union {
+	long long		q;	/* Quadword (64-bit) value */
+	unsigned long long	uq;	/* Unsigned Quadword */
+	int			d[2];	/* 2 Doubleword (32-bit) values */
+	unsigned int		ud[2];	/* 2 Unsigned Doubleword */
+	short			w[4];	/* 4 Word (16-bit) values */
+	unsigned short		uw[4];	/* 4 Unsigned Word */
+	char			b[8];	/* 8 Byte (8-bit) values */
+	unsigned char		ub[8];	/* 8 Unsigned Byte */
+	float			s[2];	/* Single-precision (32-bit) value */
+} __attribute__ ((aligned (8))) mmx_t;	/* On an 8-byte (64-bit) boundary */
+
+
+
+/*	Function to test if multimedia instructions are supported...
+*/
+inline extern int
+mm_support(void)
+{
+	/* Returns 1 if MMX instructions are supported,
+	   3 if Cyrix MMX and Extended MMX instructions are supported
+	   5 if AMD MMX and 3DNow! instructions are supported
+	   0 if hardware does not support any of these
+	*/
+	register int rval = 0;
+
+	__asm__ __volatile__ (
+		/* See if CPUID instruction is supported ... */
+		/* ... Get copies of EFLAGS into eax and ecx */
+		"pushf\n\t"
+		"popl %%eax\n\t"
+		"movl %%eax, %%ecx\n\t"
+
+		/* ... Toggle the ID bit in one copy and store */
+		/*     to the EFLAGS reg */
+		"xorl $0x200000, %%eax\n\t"
+		"push %%eax\n\t"
+		"popf\n\t"
+
+		/* ... Get the (hopefully modified) EFLAGS */
+		"pushf\n\t"
+		"popl %%eax\n\t"
+
+		/* ... Compare and test result */
+		"xorl %%eax, %%ecx\n\t"
+		"testl $0x200000, %%ecx\n\t"
+		"jz NotSupported1\n\t"		/* CPUID not supported */
+
+
+		/* Get standard CPUID information, and
+		       go to a specific vendor section */
+		"movl $0, %%eax\n\t"
+		"cpuid\n\t"
+
+		/* Check for Intel */
+		"cmpl $0x756e6547, %%ebx\n\t"
+		"jne TryAMD\n\t"
+		"cmpl $0x49656e69, %%edx\n\t"
+		"jne TryAMD\n\t"
+		"cmpl $0x6c65746e, %%ecx\n"
+		"jne TryAMD\n\t"
+		"jmp Intel\n\t"
+
+		/* Check for AMD */
+		"\nTryAMD:\n\t"
+		"cmpl $0x68747541, %%ebx\n\t"
+		"jne TryCyrix\n\t"
+		"cmpl $0x69746e65, %%edx\n\t"
+		"jne TryCyrix\n\t"
+		"cmpl $0x444d4163, %%ecx\n"
+		"jne TryCyrix\n\t"
+		"jmp AMD\n\t"
+
+		/* Check for Cyrix */
+		"\nTryCyrix:\n\t"
+		"cmpl $0x69727943, %%ebx\n\t"
+		"jne NotSupported2\n\t"
+		"cmpl $0x736e4978, %%edx\n\t"
+		"jne NotSupported3\n\t"
+		"cmpl $0x64616574, %%ecx\n\t"
+		"jne NotSupported4\n\t"
+		/* Drop through to Cyrix... */
+
+
+		/* Cyrix Section */
+		/* See if extended CPUID level 80000001 is supported */
+		/* The value of CPUID/80000001 for the 6x86MX is undefined
+		   according to the Cyrix CPU Detection Guide (Preliminary
+		   Rev. 1.01 table 1), so we'll check the value of eax for
+		   CPUID/0 to see if standard CPUID level 2 is supported.
+		   According to the table, the only CPU which supports level
+		   2 is also the only one which supports extended CPUID levels.
+		*/
+		"cmpl $0x2, %%eax\n\t"
+		"jne MMXtest\n\t"	/* Use standard CPUID instead */
+
+		/* Extended CPUID supported (in theory), so get extended
+		   features */
+		"movl $0x80000001, %%eax\n\t"
+		"cpuid\n\t"
+		"testl $0x00800000, %%eax\n\t"	/* Test for MMX */
+		"jz NotSupported5\n\t"		/* MMX not supported */
+		"testl $0x01000000, %%eax\n\t"	/* Test for Ext'd MMX */
+		"jnz EMMXSupported\n\t"
+		"movl $1, %0:\n\n\t"		/* MMX Supported */
+		"jmp Return\n\n"
+		"EMMXSupported:\n\t"
+		"movl $3, %0:\n\n\t"		/* EMMX and MMX Supported */
+		"jmp Return\n\t"
+
+
+		/* AMD Section */
+		"AMD:\n\t"
+
+		/* See if extended CPUID is supported */
+		"movl $0x80000000, %%eax\n\t"
+		"cpuid\n\t"
+		"cmpl $0x80000000, %%eax\n\t"
+		"jl MMXtest\n\t"	/* Use standard CPUID instead */
+
+		/* Extended CPUID supported, so get extended features */
+		"movl $0x80000001, %%eax\n\t"
+		"cpuid\n\t"
+		"testl $0x00800000, %%edx\n\t"	/* Test for MMX */
+		"jz NotSupported6\n\t"		/* MMX not supported */
+		"testl $0x80000000, %%edx\n\t"	/* Test for 3DNow! */
+		"jnz ThreeDNowSupported\n\t"
+		"movl $1, %0:\n\n\t"		/* MMX Supported */
+		"jmp Return\n\n"
+		"ThreeDNowSupported:\n\t"
+		"movl $5, %0:\n\n\t"		/* 3DNow! and MMX Supported */
+		"jmp Return\n\t"
+
+
+		/* Intel Section */
+		"Intel:\n\t"
+
+		/* Check for MMX */
+		"MMXtest:\n\t"
+		"movl $1, %%eax\n\t"
+		"cpuid\n\t"
+		"testl $0x00800000, %%edx\n\t"	/* Test for MMX */
+		"jz NotSupported7\n\t"		/* MMX Not supported */
+		"movl $1, %0:\n\n\t"		/* MMX Supported */
+		"jmp Return\n\t"
+
+		/* Nothing supported */
+		"\nNotSupported1:\n\t"
+		"#movl $101, %0:\n\n\t"
+		"\nNotSupported2:\n\t"
+		"#movl $102, %0:\n\n\t"
+		"\nNotSupported3:\n\t"
+		"#movl $103, %0:\n\n\t"
+		"\nNotSupported4:\n\t"
+		"#movl $104, %0:\n\n\t"
+		"\nNotSupported5:\n\t"
+		"#movl $105, %0:\n\n\t"
+		"\nNotSupported6:\n\t"
+		"#movl $106, %0:\n\n\t"
+		"\nNotSupported7:\n\t"
+		"#movl $107, %0:\n\n\t"
+		"movl $0, %0:\n\n\t"
+
+		"Return:\n\t"
+		: "=a" (rval)
+		: /* no input */
+		: "eax", "ebx", "ecx", "edx"
+	);
+
+	/* Return */
+	return(rval);
+}
+
+/*	Function to test if mmx instructions are supported...
+*/
+inline extern int
+mmx_ok(void)
+{
+	/* Returns 1 if MMX instructions are supported, 0 otherwise */
+	return ( mm_support() & 0x1 );
+}
+
+
+/*	Helper functions for the instruction macros that follow...
+	(note that memory-to-register, m2r, instructions are nearly
+	 as efficient as register-to-register, r2r, instructions;
+	 however, memory-to-memory instructions are really simulated
+	 as a convenience, and are only 1/3 as efficient)
+*/
+#ifdef	MMX_TRACE
+
+/*	Include the stuff for printing a trace to stderr...
+*/
+
+#include <stdio.h>
+
+#define	mmx_i2r(op, imm, reg) \
+	{ \
+		mmx_t mmx_trace; \
+		mmx_trace.uq = (imm); \
+		fprintf(stderr, #op "_i2r(" #imm "=0x%08x%08x, ", \
+			mmx_trace.d[1], mmx_trace.d[0]); \
+		__asm__ __volatile__ ("movq %%" #reg ", %0" \
+				      : "=X" (mmx_trace) \
+				      : /* nothing */ ); \
+		fprintf(stderr, #reg "=0x%08x%08x) => ", \
+			mmx_trace.d[1], mmx_trace.d[0]); \
+		__asm__ __volatile__ (#op " %0, %%" #reg \
+				      : /* nothing */ \
+				      : "X" (imm)); \
+		__asm__ __volatile__ ("movq %%" #reg ", %0" \
+				      : "=X" (mmx_trace) \
+				      : /* nothing */ ); \
+		fprintf(stderr, #reg "=0x%08x%08x\n", \
+			mmx_trace.d[1], mmx_trace.d[0]); \
+	}
+
+#define	mmx_m2r(op, mem, reg) \
+	{ \
+		mmx_t mmx_trace; \
+		mmx_trace = (mem); \
+		fprintf(stderr, #op "_m2r(" #mem "=0x%08x%08x, ", \
+			mmx_trace.d[1], mmx_trace.d[0]); \
+		__asm__ __volatile__ ("movq %%" #reg ", %0" \
+				      : "=X" (mmx_trace) \
+				      : /* nothing */ ); \
+		fprintf(stderr, #reg "=0x%08x%08x) => ", \
+			mmx_trace.d[1], mmx_trace.d[0]); \
+		__asm__ __volatile__ (#op " %0, %%" #reg \
+				      : /* nothing */ \
+				      : "X" (mem)); \
+		__asm__ __volatile__ ("movq %%" #reg ", %0" \
+				      : "=X" (mmx_trace) \
+				      : /* nothing */ ); \
+		fprintf(stderr, #reg "=0x%08x%08x\n", \
+			mmx_trace.d[1], mmx_trace.d[0]); \
+	}
+
+#define	mmx_r2m(op, reg, mem) \
+	{ \
+		mmx_t mmx_trace; \
+		__asm__ __volatile__ ("movq %%" #reg ", %0" \
+				      : "=X" (mmx_trace) \
+				      : /* nothing */ ); \
+		fprintf(stderr, #op "_r2m(" #reg "=0x%08x%08x, ", \
+			mmx_trace.d[1], mmx_trace.d[0]); \
+		mmx_trace = (mem); \
+		fprintf(stderr, #mem "=0x%08x%08x) => ", \
+			mmx_trace.d[1], mmx_trace.d[0]); \
+		__asm__ __volatile__ (#op " %%" #reg ", %0" \
+				      : "=X" (mem) \
+				      : /* nothing */ ); \
+		mmx_trace = (mem); \
+		fprintf(stderr, #mem "=0x%08x%08x\n", \
+			mmx_trace.d[1], mmx_trace.d[0]); \
+	}
+
+#define	mmx_r2r(op, regs, regd) \
+	{ \
+		mmx_t mmx_trace; \
+		__asm__ __volatile__ ("movq %%" #regs ", %0" \
+				      : "=X" (mmx_trace) \
+				      : /* nothing */ ); \
+		fprintf(stderr, #op "_r2r(" #regs "=0x%08x%08x, ", \
+			mmx_trace.d[1], mmx_trace.d[0]); \
+		__asm__ __volatile__ ("movq %%" #regd ", %0" \
+				      : "=X" (mmx_trace) \
+				      : /* nothing */ ); \
+		fprintf(stderr, #regd "=0x%08x%08x) => ", \
+			mmx_trace.d[1], mmx_trace.d[0]); \
+		__asm__ __volatile__ (#op " %" #regs ", %" #regd); \
+		__asm__ __volatile__ ("movq %%" #regd ", %0" \
+				      : "=X" (mmx_trace) \
+				      : /* nothing */ ); \
+		fprintf(stderr, #regd "=0x%08x%08x\n", \
+			mmx_trace.d[1], mmx_trace.d[0]); \
+	}
+
+#define	mmx_m2m(op, mems, memd) \
+	{ \
+		mmx_t mmx_trace; \
+		mmx_trace = (mems); \
+		fprintf(stderr, #op "_m2m(" #mems "=0x%08x%08x, ", \
+			mmx_trace.d[1], mmx_trace.d[0]); \
+		mmx_trace = (memd); \
+		fprintf(stderr, #memd "=0x%08x%08x) => ", \
+			mmx_trace.d[1], mmx_trace.d[0]); \
+		__asm__ __volatile__ ("movq %0, %%mm0\n\t" \
+				      #op " %1, %%mm0\n\t" \
+				      "movq %%mm0, %0" \
+				      : "=X" (memd) \
+				      : "X" (mems)); \
+		mmx_trace = (memd); \
+		fprintf(stderr, #memd "=0x%08x%08x\n", \
+			mmx_trace.d[1], mmx_trace.d[0]); \
+	}
+
+#else
+
+/*	These macros are a lot simpler without the tracing...
+*/
+
+#define	mmx_i2r(op, imm, reg) \
+	__asm__ __volatile__ (#op " %0, %%" #reg \
+			      : /* nothing */ \
+			      : "X" (imm) )
+
+#define	mmx_m2r(op, mem, reg) \
+	__asm__ __volatile__ (#op " %0, %%" #reg \
+			      : /* nothing */ \
+			      : "X" (mem))
+
+#define	mmx_r2m(op, reg, mem) \
+	__asm__ __volatile__ (#op " %%" #reg ", %0" \
+			      : "=X" (mem) \
+			      : /* nothing */ )
+
+#define	mmx_r2r(op, regs, regd) \
+	__asm__ __volatile__ (#op " %" #regs ", %" #regd)
+
+#define	mmx_m2m(op, mems, memd) \
+	__asm__ __volatile__ ("movq %0, %%mm0\n\t" \
+			      #op " %1, %%mm0\n\t" \
+			      "movq %%mm0, %0" \
+			      : "=X" (memd) \
+			      : "X" (mems))
+
+#endif
+
+
+/*	1x64 MOVe Quadword
+	(this is both a load and a store...
+	 in fact, it is the only way to store)
+*/
+#define	movq_m2r(var, reg)	mmx_m2r(movq, var, reg)
+#define	movq_r2m(reg, var)	mmx_r2m(movq, reg, var)
+#define	movq_r2r(regs, regd)	mmx_r2r(movq, regs, regd)
+#define	movq(vars, vard) \
+	__asm__ __volatile__ ("movq %1, %%mm0\n\t" \
+			      "movq %%mm0, %0" \
+			      : "=X" (vard) \
+			      : "X" (vars))
+
+
+/*	1x32 MOVe Doubleword
+	(like movq, this is both load and store...
+	 but is most useful for moving things between
+	 mmx registers and ordinary registers)
+*/
+#define	movd_m2r(var, reg)	mmx_m2r(movd, var, reg)
+#define	movd_r2m(reg, var)	mmx_r2m(movd, reg, var)
+#define	movd_r2r(regs, regd)	mmx_r2r(movd, regs, regd)
+#define	movd(vars, vard) \
+	__asm__ __volatile__ ("movd %1, %%mm0\n\t" \
+			      "movd %%mm0, %0" \
+			      : "=X" (vard) \
+			      : "X" (vars))
+
+
+/*	2x32, 4x16, and 8x8 Parallel ADDs
+*/
+#define	paddd_m2r(var, reg)	mmx_m2r(paddd, var, reg)
+#define	paddd_r2r(regs, regd)	mmx_r2r(paddd, regs, regd)
+#define	paddd(vars, vard)	mmx_m2m(paddd, vars, vard)
+
+#define	paddw_m2r(var, reg)	mmx_m2r(paddw, var, reg)
+#define	paddw_r2r(regs, regd)	mmx_r2r(paddw, regs, regd)
+#define	paddw(vars, vard)	mmx_m2m(paddw, vars, vard)
+
+#define	paddb_m2r(var, reg)	mmx_m2r(paddb, var, reg)
+#define	paddb_r2r(regs, regd)	mmx_r2r(paddb, regs, regd)
+#define	paddb(vars, vard)	mmx_m2m(paddb, vars, vard)
+
+
+/*	4x16 and 8x8 Parallel ADDs using Saturation arithmetic
+*/
+#define	paddsw_m2r(var, reg)	mmx_m2r(paddsw, var, reg)
+#define	paddsw_r2r(regs, regd)	mmx_r2r(paddsw, regs, regd)
+#define	paddsw(vars, vard)	mmx_m2m(paddsw, vars, vard)
+
+#define	paddsb_m2r(var, reg)	mmx_m2r(paddsb, var, reg)
+#define	paddsb_r2r(regs, regd)	mmx_r2r(paddsb, regs, regd)
+#define	paddsb(vars, vard)	mmx_m2m(paddsb, vars, vard)
+
+
+/*	4x16 and 8x8 Parallel ADDs using Unsigned Saturation arithmetic
+*/
+#define	paddusw_m2r(var, reg)	mmx_m2r(paddusw, var, reg)
+#define	paddusw_r2r(regs, regd)	mmx_r2r(paddusw, regs, regd)
+#define	paddusw(vars, vard)	mmx_m2m(paddusw, vars, vard)
+
+#define	paddusb_m2r(var, reg)	mmx_m2r(paddusb, var, reg)
+#define	paddusb_r2r(regs, regd)	mmx_r2r(paddusb, regs, regd)
+#define	paddusb(vars, vard)	mmx_m2m(paddusb, vars, vard)
+
+
+/*	2x32, 4x16, and 8x8 Parallel SUBs
+*/
+#define	psubd_m2r(var, reg)	mmx_m2r(psubd, var, reg)
+#define	psubd_r2r(regs, regd)	mmx_r2r(psubd, regs, regd)
+#define	psubd(vars, vard)	mmx_m2m(psubd, vars, vard)
+
+#define	psubw_m2r(var, reg)	mmx_m2r(psubw, var, reg)
+#define	psubw_r2r(regs, regd)	mmx_r2r(psubw, regs, regd)
+#define	psubw(vars, vard)	mmx_m2m(psubw, vars, vard)
+
+#define	psubb_m2r(var, reg)	mmx_m2r(psubb, var, reg)
+#define	psubb_r2r(regs, regd)	mmx_r2r(psubb, regs, regd)
+#define	psubb(vars, vard)	mmx_m2m(psubb, vars, vard)
+
+
+/*	4x16 and 8x8 Parallel SUBs using Saturation arithmetic
+*/
+#define	psubsw_m2r(var, reg)	mmx_m2r(psubsw, var, reg)
+#define	psubsw_r2r(regs, regd)	mmx_r2r(psubsw, regs, regd)
+#define	psubsw(vars, vard)	mmx_m2m(psubsw, vars, vard)
+
+#define	psubsb_m2r(var, reg)	mmx_m2r(psubsb, var, reg)
+#define	psubsb_r2r(regs, regd)	mmx_r2r(psubsb, regs, regd)
+#define	psubsb(vars, vard)	mmx_m2m(psubsb, vars, vard)
+
+
+/*	4x16 and 8x8 Parallel SUBs using Unsigned Saturation arithmetic
+*/
+#define	psubusw_m2r(var, reg)	mmx_m2r(psubusw, var, reg)
+#define	psubusw_r2r(regs, regd)	mmx_r2r(psubusw, regs, regd)
+#define	psubusw(vars, vard)	mmx_m2m(psubusw, vars, vard)
+
+#define	psubusb_m2r(var, reg)	mmx_m2r(psubusb, var, reg)
+#define	psubusb_r2r(regs, regd)	mmx_r2r(psubusb, regs, regd)
+#define	psubusb(vars, vard)	mmx_m2m(psubusb, vars, vard)
+
+
+/*	4x16 Parallel MULs giving Low 4x16 portions of results
+*/
+#define	pmullw_m2r(var, reg)	mmx_m2r(pmullw, var, reg)
+#define	pmullw_r2r(regs, regd)	mmx_r2r(pmullw, regs, regd)
+#define	pmullw(vars, vard)	mmx_m2m(pmullw, vars, vard)
+
+
+/*	4x16 Parallel MULs giving High 4x16 portions of results
+*/
+#define	pmulhw_m2r(var, reg)	mmx_m2r(pmulhw, var, reg)
+#define	pmulhw_r2r(regs, regd)	mmx_r2r(pmulhw, regs, regd)
+#define	pmulhw(vars, vard)	mmx_m2m(pmulhw, vars, vard)
+
+
+/*	4x16->2x32 Parallel Mul-ADD
+	(muls like pmullw, then adds adjacent 16-bit fields
+	 in the multiply result to make the final 2x32 result)
+*/
+#define	pmaddwd_m2r(var, reg)	mmx_m2r(pmaddwd, var, reg)
+#define	pmaddwd_r2r(regs, regd)	mmx_r2r(pmaddwd, regs, regd)
+#define	pmaddwd(vars, vard)	mmx_m2m(pmaddwd, vars, vard)
+
+
+/*	1x64 bitwise AND
+*/
+#ifdef	BROKEN_PAND
+#define	pand_m2r(var, reg) \
+	{ \
+		mmx_m2r(pandn, (mmx_t) -1LL, reg); \
+		mmx_m2r(pandn, var, reg); \
+	}
+#define	pand_r2r(regs, regd) \
+	{ \
+		mmx_m2r(pandn, (mmx_t) -1LL, regd); \
+		mmx_r2r(pandn, regs, regd) \
+	}
+#define	pand(vars, vard) \
+	{ \
+		movq_m2r(vard, mm0); \
+		mmx_m2r(pandn, (mmx_t) -1LL, mm0); \
+		mmx_m2r(pandn, vars, mm0); \
+		movq_r2m(mm0, vard); \
+	}
+#else
+#define	pand_m2r(var, reg)	mmx_m2r(pand, var, reg)
+#define	pand_r2r(regs, regd)	mmx_r2r(pand, regs, regd)
+#define	pand(vars, vard)	mmx_m2m(pand, vars, vard)
+#endif
+
+
+/*	1x64 bitwise AND with Not the destination
+*/
+#define	pandn_m2r(var, reg)	mmx_m2r(pandn, var, reg)
+#define	pandn_r2r(regs, regd)	mmx_r2r(pandn, regs, regd)
+#define	pandn(vars, vard)	mmx_m2m(pandn, vars, vard)
+
+
+/*	1x64 bitwise OR
+*/
+#define	por_m2r(var, reg)	mmx_m2r(por, var, reg)
+#define	por_r2r(regs, regd)	mmx_r2r(por, regs, regd)
+#define	por(vars, vard)	mmx_m2m(por, vars, vard)
+
+
+/*	1x64 bitwise eXclusive OR
+*/
+#define	pxor_m2r(var, reg)	mmx_m2r(pxor, var, reg)
+#define	pxor_r2r(regs, regd)	mmx_r2r(pxor, regs, regd)
+#define	pxor(vars, vard)	mmx_m2m(pxor, vars, vard)
+
+
+/*	2x32, 4x16, and 8x8 Parallel CoMPare for EQuality
+	(resulting fields are either 0 or -1)
+*/
+#define	pcmpeqd_m2r(var, reg)	mmx_m2r(pcmpeqd, var, reg)
+#define	pcmpeqd_r2r(regs, regd)	mmx_r2r(pcmpeqd, regs, regd)
+#define	pcmpeqd(vars, vard)	mmx_m2m(pcmpeqd, vars, vard)
+
+#define	pcmpeqw_m2r(var, reg)	mmx_m2r(pcmpeqw, var, reg)
+#define	pcmpeqw_r2r(regs, regd)	mmx_r2r(pcmpeqw, regs, regd)
+#define	pcmpeqw(vars, vard)	mmx_m2m(pcmpeqw, vars, vard)
+
+#define	pcmpeqb_m2r(var, reg)	mmx_m2r(pcmpeqb, var, reg)
+#define	pcmpeqb_r2r(regs, regd)	mmx_r2r(pcmpeqb, regs, regd)
+#define	pcmpeqb(vars, vard)	mmx_m2m(pcmpeqb, vars, vard)
+
+
+/*	2x32, 4x16, and 8x8 Parallel CoMPare for Greater Than
+	(resulting fields are either 0 or -1)
+*/
+#define	pcmpgtd_m2r(var, reg)	mmx_m2r(pcmpgtd, var, reg)
+#define	pcmpgtd_r2r(regs, regd)	mmx_r2r(pcmpgtd, regs, regd)
+#define	pcmpgtd(vars, vard)	mmx_m2m(pcmpgtd, vars, vard)
+
+#define	pcmpgtw_m2r(var, reg)	mmx_m2r(pcmpgtw, var, reg)
+#define	pcmpgtw_r2r(regs, regd)	mmx_r2r(pcmpgtw, regs, regd)
+#define	pcmpgtw(vars, vard)	mmx_m2m(pcmpgtw, vars, vard)
+
+#define	pcmpgtb_m2r(var, reg)	mmx_m2r(pcmpgtb, var, reg)
+#define	pcmpgtb_r2r(regs, regd)	mmx_r2r(pcmpgtb, regs, regd)
+#define	pcmpgtb(vars, vard)	mmx_m2m(pcmpgtb, vars, vard)
+
+
+/*	1x64, 2x32, and 4x16 Parallel Shift Left Logical
+*/
+#define	psllq_i2r(imm, reg)	mmx_i2r(psllq, imm, reg)
+#define	psllq_m2r(var, reg)	mmx_m2r(psllq, var, reg)
+#define	psllq_r2r(regs, regd)	mmx_r2r(psllq, regs, regd)
+#define	psllq(vars, vard)	mmx_m2m(psllq, vars, vard)
+
+#define	pslld_i2r(imm, reg)	mmx_i2r(pslld, imm, reg)
+#define	pslld_m2r(var, reg)	mmx_m2r(pslld, var, reg)
+#define	pslld_r2r(regs, regd)	mmx_r2r(pslld, regs, regd)
+#define	pslld(vars, vard)	mmx_m2m(pslld, vars, vard)
+
+#define	psllw_i2r(imm, reg)	mmx_i2r(psllw, imm, reg)
+#define	psllw_m2r(var, reg)	mmx_m2r(psllw, var, reg)
+#define	psllw_r2r(regs, regd)	mmx_r2r(psllw, regs, regd)
+#define	psllw(vars, vard)	mmx_m2m(psllw, vars, vard)
+
+
+/*	1x64, 2x32, and 4x16 Parallel Shift Right Logical
+*/
+#define	psrlq_i2r(imm, reg)	mmx_i2r(psrlq, imm, reg)
+#define	psrlq_m2r(var, reg)	mmx_m2r(psrlq, var, reg)
+#define	psrlq_r2r(regs, regd)	mmx_r2r(psrlq, regs, regd)
+#define	psrlq(vars, vard)	mmx_m2m(psrlq, vars, vard)
+
+#define	psrld_i2r(imm, reg)	mmx_i2r(psrld, imm, reg)
+#define	psrld_m2r(var, reg)	mmx_m2r(psrld, var, reg)
+#define	psrld_r2r(regs, regd)	mmx_r2r(psrld, regs, regd)
+#define	psrld(vars, vard)	mmx_m2m(psrld, vars, vard)
+
+#define	psrlw_i2r(imm, reg)	mmx_i2r(psrlw, imm, reg)
+#define	psrlw_m2r(var, reg)	mmx_m2r(psrlw, var, reg)
+#define	psrlw_r2r(regs, regd)	mmx_r2r(psrlw, regs, regd)
+#define	psrlw(vars, vard)	mmx_m2m(psrlw, vars, vard)
+
+
+/*	2x32 and 4x16 Parallel Shift Right Arithmetic
+*/
+#define	psrad_i2r(imm, reg)	mmx_i2r(psrad, imm, reg)
+#define	psrad_m2r(var, reg)	mmx_m2r(psrad, var, reg)
+#define	psrad_r2r(regs, regd)	mmx_r2r(psrad, regs, regd)
+#define	psrad(vars, vard)	mmx_m2m(psrad, vars, vard)
+
+#define	psraw_i2r(imm, reg)	mmx_i2r(psraw, imm, reg)
+#define	psraw_m2r(var, reg)	mmx_m2r(psraw, var, reg)
+#define	psraw_r2r(regs, regd)	mmx_r2r(psraw, regs, regd)
+#define	psraw(vars, vard)	mmx_m2m(psraw, vars, vard)
+
+
+/*	2x32->4x16 and 4x16->8x8 PACK and Signed Saturate
+	(packs source and dest fields into dest in that order)
+*/
+#define	packssdw_m2r(var, reg)	mmx_m2r(packssdw, var, reg)
+#define	packssdw_r2r(regs, regd) mmx_r2r(packssdw, regs, regd)
+#define	packssdw(vars, vard)	mmx_m2m(packssdw, vars, vard)
+
+#define	packsswb_m2r(var, reg)	mmx_m2r(packsswb, var, reg)
+#define	packsswb_r2r(regs, regd) mmx_r2r(packsswb, regs, regd)
+#define	packsswb(vars, vard)	mmx_m2m(packsswb, vars, vard)
+
+
+/*	4x16->8x8 PACK and Unsigned Saturate
+	(packs source and dest fields into dest in that order)
+*/
+#define	packuswb_m2r(var, reg)	mmx_m2r(packuswb, var, reg)
+#define	packuswb_r2r(regs, regd) mmx_r2r(packuswb, regs, regd)
+#define	packuswb(vars, vard)	mmx_m2m(packuswb, vars, vard)
+
+
+/*	2x32->1x64, 4x16->2x32, and 8x8->4x16 UNPaCK Low
+	(interleaves low half of dest with low half of source
+	 as padding in each result field)
+*/
+#define	punpckldq_m2r(var, reg)	mmx_m2r(punpckldq, var, reg)
+#define	punpckldq_r2r(regs, regd) mmx_r2r(punpckldq, regs, regd)
+#define	punpckldq(vars, vard)	mmx_m2m(punpckldq, vars, vard)
+
+#define	punpcklwd_m2r(var, reg)	mmx_m2r(punpcklwd, var, reg)
+#define	punpcklwd_r2r(regs, regd) mmx_r2r(punpcklwd, regs, regd)
+#define	punpcklwd(vars, vard)	mmx_m2m(punpcklwd, vars, vard)
+
+#define	punpcklbw_m2r(var, reg)	mmx_m2r(punpcklbw, var, reg)
+#define	punpcklbw_r2r(regs, regd) mmx_r2r(punpcklbw, regs, regd)
+#define	punpcklbw(vars, vard)	mmx_m2m(punpcklbw, vars, vard)
+
+
+/*	2x32->1x64, 4x16->2x32, and 8x8->4x16 UNPaCK High
+	(interleaves high half of dest with high half of source
+	 as padding in each result field)
+*/
+#define	punpckhdq_m2r(var, reg)	mmx_m2r(punpckhdq, var, reg)
+#define	punpckhdq_r2r(regs, regd) mmx_r2r(punpckhdq, regs, regd)
+#define	punpckhdq(vars, vard)	mmx_m2m(punpckhdq, vars, vard)
+
+#define	punpckhwd_m2r(var, reg)	mmx_m2r(punpckhwd, var, reg)
+#define	punpckhwd_r2r(regs, regd) mmx_r2r(punpckhwd, regs, regd)
+#define	punpckhwd(vars, vard)	mmx_m2m(punpckhwd, vars, vard)
+
+#define	punpckhbw_m2r(var, reg)	mmx_m2r(punpckhbw, var, reg)
+#define	punpckhbw_r2r(regs, regd) mmx_r2r(punpckhbw, regs, regd)
+#define	punpckhbw(vars, vard)	mmx_m2m(punpckhbw, vars, vard)
+
+
+/*	Empty MMx State
+	(used to clean-up when going from mmx to float use
+	 of the registers that are shared by both; note that
+	 there is no float-to-mmx operation needed, because
+	 only the float tag word info is corruptible)
+*/
+#ifdef	MMX_TRACE
+
+#define	emms() \
+	{ \
+		fprintf(stderr, "emms()\n"); \
+		__asm__ __volatile__ ("emms"); \
+	}
+
+#else
+
+#define	emms()			__asm__ __volatile__ ("emms")
+
+#endif
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/rgb15to16mmx.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,42 @@
+// Original by Strepto/Astral
+// ported to gcc & bugfixed : A'rpi
+
+#include <inttypes.h>
+//#include "attributes.h"
+#include "mmx.h"
+
+void rgb15to16_mmx(char* s0,char* d0,int count){
+  static uint64_t mask_b  = 0x001F001F001F001FLL; // 00000000 00011111  xxB
+  static uint64_t mask_rg = 0x7FE07FE07FE07FE0LL; // 01111111 11100000  RGx
+  register char* s=s0+count;
+  register char* d=d0+count;
+  register int offs=-count;
+  movq_m2r (mask_b,  mm4);
+  movq_m2r (mask_rg, mm5);
+  while(offs<0){
+    movq_m2r (*(s+offs), mm0);
+    movq_r2r (mm0, mm1);
+
+    movq_m2r (*(s+8+offs), mm2);
+    movq_r2r (mm2, mm3);
+    
+    pand_r2r (mm4, mm0);
+    pand_r2r (mm5, mm1);
+    
+    psllq_i2r(1,mm1);
+    pand_r2r (mm4, mm2);
+
+    pand_r2r (mm5, mm3);
+    por_r2r  (mm1, mm0);
+
+    psllq_i2r(1,mm3);
+    movq_r2m (mm0,*(d+offs));
+
+    por_r2r  (mm3,mm2);
+    movq_r2m (mm2,*(d+8+offs));
+
+    offs+=16;
+  }
+  emms();
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/video_out.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,201 @@
+/*
+ * video_out.c,
+ *
+ * Copyright (C) Aaron Holtzman - June 2000
+ *
+ *  mpeg2dec 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, or (at your option)
+ *  any later version.
+ *
+ *  mpeg2dec 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 GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <unistd.h>
+#include <sys/mman.h>
+
+#include "config.h"
+#include "video_out.h"
+
+#include "../linux/shmem.h"
+
+//
+// Externally visible list of all vo drivers
+//
+
+extern vo_functions_t video_out_mga;
+extern vo_functions_t video_out_xmga;
+extern vo_functions_t video_out_x11;
+extern vo_functions_t video_out_xv;
+extern vo_functions_t video_out_gl;
+extern vo_functions_t video_out_sdl;
+extern vo_functions_t video_out_3dfx;
+extern vo_functions_t video_out_null;
+extern vo_functions_t video_out_odivx;
+extern vo_functions_t video_out_pgm;
+extern vo_functions_t video_out_md5;
+extern vo_functions_t video_out_syncfb;
+
+vo_functions_t* video_out_drivers[] =
+{
+#ifdef HAVE_MGA
+#ifdef HAVE_X11
+        &video_out_xmga,
+#endif
+        &video_out_mga,
+#endif
+#ifdef HAVE_SYNCFB
+        &video_out_syncfb,
+#endif
+#ifdef HAVE_3DFX
+        &video_out_3dfx,
+#endif
+#ifdef HAVE_XV
+        &video_out_xv,
+#endif
+#ifdef HAVE_X11
+        &video_out_x11,
+#endif
+#ifdef HAVE_GL
+        &video_out_gl,
+#endif
+#ifdef HAVE_SDL
+        &video_out_sdl,
+#endif
+        &video_out_null,
+        &video_out_odivx,
+        &video_out_pgm,
+        &video_out_md5,
+        NULL
+};
+
+#ifdef X11_FULLSCREEN
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xatom.h>
+
+int vo_depthonscreen=0;
+int vo_screenwidth=0;
+int vo_screenheight=0;
+
+int vo_init( void )
+{
+ int       CompletionType = -1;
+ int       mScreen;
+ int bpp;
+ char    * DisplayName = ":0.0";
+ Display * mDisplay;
+ XImage  * mXImage;
+ Window    mRootWin;
+ static XWindowAttributes attribs;
+
+ if(vo_depthonscreen) return 1; // already called
+
+ if ( getenv( "DISPLAY" ) ) DisplayName=getenv( "DISPLAY" );
+ mDisplay=XOpenDisplay( DisplayName );
+ if ( !mDisplay )
+  {
+   fprintf( stderr,"vo: couldn't open the X11 display!\n" );
+   return 0;
+  }
+ mScreen=DefaultScreen( mDisplay );     // Screen ID.
+ mRootWin=RootWindow( mDisplay,mScreen );// Root window ID.
+ vo_screenwidth=DisplayWidth( mDisplay,mScreen );
+ vo_screenheight=DisplayHeight( mDisplay,mScreen );
+ // get color depth:
+// XGetWindowAttributes(mydisplay, DefaultRootWindow(mDisplay), &attribs);
+ XGetWindowAttributes(mDisplay, mRootWin, &attribs);
+ vo_depthonscreen=attribs.depth;
+ // get bits/pixel:
+   mXImage=XGetImage( mDisplay,mRootWin,0,0,1,1,AllPlanes,ZPixmap );
+   bpp=mXImage->bits_per_pixel;
+   XDestroyImage( mXImage );
+ if((vo_depthonscreen+7)/8 != (bpp+7)/8) vo_depthonscreen=bpp; // by A'rpi
+ XCloseDisplay( mDisplay );
+ printf("X11 running at %dx%d depth: %d\n",vo_screenwidth,vo_screenheight,vo_depthonscreen);
+ return 1;
+}
+
+#include "../linux/keycodes.h"
+extern void mplayer_put_key(int code);
+
+void vo_keyboard( int key )
+{
+ switch ( key )
+  {
+   case wsLeft:      mplayer_put_key(KEY_LEFT); break;
+   case wsRight:     mplayer_put_key(KEY_RIGHT); break;
+   case wsUp:        mplayer_put_key(KEY_UP); break;
+   case wsDown:      mplayer_put_key(KEY_DOWN); break;
+   case wsSpace:     mplayer_put_key(' '); break;
+   case wsEscape:    mplayer_put_key(KEY_ESC); break;
+   case wsEnter:     mplayer_put_key(KEY_ENTER); break;
+   case wsq:
+   case wsQ:         mplayer_put_key('q'); break;
+   case wsp:
+   case wsP:         mplayer_put_key('p'); break;
+   case wsMinus:
+   case wsGrayMinus: mplayer_put_key('-'); break;
+   case wsPlus:
+   case wsGrayPlus:  mplayer_put_key('+'); break;
+  }
+}
+
+
+// ----- Motif header: -------
+
+#define MWM_HINTS_DECORATIONS   2
+
+typedef struct
+{
+  long flags;
+  long functions;
+  long decorations;
+  long input_mode;
+} MotifWmHints;
+
+extern MotifWmHints vo_MotifWmHints;
+extern Atom         vo_MotifHints;
+extern int          vo_depthonscreen;
+extern int          vo_screenwidth;
+extern int          vo_screenheight;
+
+static MotifWmHints   vo_MotifWmHints;
+static Atom           vo_MotifHints  = None;
+
+void vo_decoration( Display * vo_Display,Window w,int d )
+{
+ vo_MotifHints=XInternAtom( vo_Display,"_MOTIF_WM_HINTS",0 );
+ if ( vo_MotifHints != None )
+  {
+   vo_MotifWmHints.flags=2;
+   vo_MotifWmHints.decorations=d;
+   XChangeProperty( vo_Display,w,vo_MotifHints,vo_MotifHints,32,
+                    PropModeReplace,(unsigned char *)&vo_MotifWmHints,4 );
+  }
+}
+
+#include <signal.h>
+
+int vo_eventhandler_pid=-1;
+
+void vo_kill_eventhandler(){
+	if(vo_eventhandler_pid!=-1) kill(vo_eventhandler_pid,SIGTERM);
+
+}
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/video_out.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,195 @@
+/*
+ *  video_out.h
+ *
+ *      Copyright (C) Aaron Holtzman - Aug 1999
+ *
+ *  This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *
+ *  mpeg2dec 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, or (at your option)
+ *  any later version.
+ *
+ *  mpeg2dec 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 GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <inttypes.h>
+
+#define IMGFMT_YV12 0x32315659
+//#define IMGFMT_YUY2 (('Y'<<24)|('U'<<16)|('Y'<<8)|'2')
+#define IMGFMT_YUY2 (('2'<<24)|('Y'<<16)|('U'<<8)|'Y')
+
+#define IMGFMT_RGB_MASK 0xFFFFFF00
+#define IMGFMT_RGB (('R'<<24)|('G'<<16)|('B'<<8))
+#define IMGFMT_BGR_MASK 0xFFFFFF00
+#define IMGFMT_BGR (('B'<<24)|('G'<<16)|('R'<<8))
+#define IMGFMT_RGB15 (IMGFMT_RGB|15)
+#define IMGFMT_RGB16 (IMGFMT_RGB|16)
+#define IMGFMT_RGB24 (IMGFMT_RGB|24)
+#define IMGFMT_RGB32 (IMGFMT_RGB|32)
+
+typedef struct vo_info_s
+{
+        /* driver name ("Matrox Millennium G200/G400" */
+        const char *name;
+        /* short name (for config strings) ("mga") */
+        const char *short_name;
+        /* author ("Aaron Holtzman <aholtzma@ess.engr.uvic.ca>") */
+        const char *author;
+        /* any additional comments */
+        const char *comment;
+} vo_info_t;
+
+typedef struct vo_image_buffer_s
+{
+        uint32_t height;
+        uint32_t width;
+        uint32_t format;
+        uint8_t *base;
+        void *private;
+} vo_image_buffer_t;
+
+typedef struct vo_functions_s
+{
+        /*
+         * Initialize the display driver.
+         *
+         *    params : width  == width of video to display.
+         *             height == height of video to display.
+         *             fullscreen == non-zero if driver should attempt to
+         *                           render in fullscreen mode. Zero if
+         *                           a windowed mode is requested. This is
+         *                           merely a request; if the driver can only do
+         *                           fullscreen (like fbcon) or windowed (like X11),
+         *                           than this param may be disregarded.
+         *             title == string for titlebar of window. May be disregarded
+         *                      if there is no such thing as a window to your
+         *                      driver. Make a copy of this string, if you need it.
+         *             format == desired fourCC code to use for image buffers
+         *   returns : zero on successful initialization, non-zero on error.
+         *              The program will probably respond to an error condition
+         *              by terminating.
+         */
+
+        uint32_t (*init)(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format);
+
+        uint32_t (*query_format)(uint32_t format);
+
+        /*
+         * Return driver information.
+         *
+         *    params : none.
+         *   returns : read-only pointer to a vo_info_t structure.
+         *             Fields are non-NULL.
+         *             Should not return NULL.
+         */
+
+        const vo_info_t* (*get_info)(void);
+
+        /*
+         * Display a new frame of the video to the screen. This may get called very
+         *  rapidly, so the more efficient you can make your implementation of this
+         *  function, the better.
+         *
+         *    params : *src[] == An array with three elements. This is a YUV
+         *                       stream, with the Y plane in src[0], U in src[1],
+         *                       and V in src[2]. There is enough data for an image
+         *                       that is (WxH) pixels, where W and H are the width
+         *                       and height parameters that were previously passed
+         *                       to display_init().
+         *                         Information on the YUV format can be found at:
+         *                           http://www.webartz.com/fourcc/fccyuv.htm#IYUV
+         *
+         *   returns : zero on successful rendering, non-zero on error.
+         *              The program will probably respond to an error condition
+         *              by terminating.
+         */
+
+        uint32_t (*draw_frame)(uint8_t *src[]);
+
+        /*
+         * Update a section of the offscreen buffer. A "slice" is an area of the
+         *  video image that is 16 rows of pixels at the width of the video image.
+         *  Position (0, 0) is the upper left corner of slice #0 (the first slice),
+         *  and position (0, 15) is the lower right. The next slice, #1, is bounded
+         *  by (0, 16) and (0, 31), and so on.
+         *
+         * Note that slices are not drawn directly to the screen, and should be
+         *  buffered until your implementation of display_flip_page() (see below)
+         *  is called.
+         *
+         * This may get called very rapidly, so the more efficient you can make your
+         *  implementation of this function, the better.
+         *
+         *     params : *src[] == see display_frame(), above. The data passed in this
+         *                         array is just what enough data to contain the
+         *                         new slice, and NOT the entire frame.
+         *              slice_num == The index of the slice. Starts at 0, not 1.
+         *
+         *   returns : zero on successful rendering, non-zero on error.
+         *              The program will probably respond to an error condition
+         *              by terminating.
+         */
+
+    // src[3] = source image planes (Y,U,V)
+    // stride[3] = source image planes line widths (in bytes)
+    // w,h = width*height of area to be copied (in Y pixels)
+    // x,y = position at the destination image (in Y pixels)
+
+        uint32_t (*draw_slice)(uint8_t *src[], int stride[], int w,int h, int x,int y);
+
+        /*
+         * Draw the current image buffer to the screen. There may be several
+         *  display_slice() calls before display_flip_page() is used. Note that
+         *  display_frame does an implicit page flip, so you might or might not
+         *  want to call this internally from your display_frame() implementation.
+         *
+         * This may get called very rapidly, so the more efficient you can make
+         *  your implementation of this function, the better.
+         *
+         *     params : void.
+         *    returns : void.
+         */
+
+        void (*flip_page)(void);
+
+        void (*uninit)(void);
+
+} vo_functions_t;
+
+// NULL terminated array of all drivers
+extern vo_functions_t* video_out_drivers[];
+
+
+#ifdef X11_FULLSCREEN
+
+// X11 keyboard codes
+#include "wskeys.h"
+
+extern int vo_depthonscreen;
+extern int vo_screenwidth;
+extern int vo_screenheight;
+int vo_init( void );
+//void vo_decoration( Display * vo_Display,Window w,int d );
+
+extern int vo_eventhandler_pid;
+void vo_kill_eventhandler();
+
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/video_out_internal.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,43 @@
+/*
+ *  video_out_internal.h
+ *
+ *	Copyright (C) Aaron Holtzman - Aug 1999
+ *
+ *  This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *	
+ *  mpeg2dec 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, or (at your option)
+ *  any later version.
+ *   
+ *  mpeg2dec 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 GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
+ *
+ */
+
+static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format);
+static const vo_info_t* get_info(void);
+static uint32_t draw_frame(uint8_t *src[]);
+//static uint32_t draw_slice(uint8_t *src[], uint32_t slice_num);
+static uint32_t draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y);
+static void flip_page(void);
+static void uninit(void);
+static uint32_t query_format(uint32_t format);
+
+#define LIBVO_EXTERN(x) vo_functions_t video_out_##x =\
+{\
+	init,\
+        query_format,\
+	get_info,\
+	draw_frame,\
+	draw_slice,\
+	flip_page,\
+	uninit,\
+};
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/vo_3dfx.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,478 @@
+/* 
+ *    video_out_3dfx.c
+ *
+ *	Copyright (C) Colin Cross Apr 2000
+ *
+ *  This file heavily based off of video_out_mga.c of Aaron Holtzman's
+ *  mpeg2dec
+ *	
+ *  mpeg2dec 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, or (at your option)
+ *  any later version.
+ *   
+ *  mpeg2dec 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 GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+LIBVO_EXTERN(3dfx)
+
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <wchar.h>
+#include <signal.h>
+
+#include <X11/Xlib.h>
+#include <X11/extensions/xf86dga.h>
+#include <X11/Xutil.h>
+
+//#define LOG(x) syslog(LOG_USER | LOG_DEBUG,x)
+#define LOG(x)
+
+#include "drivers/3dfx.h"
+
+static vo_info_t vo_info = 
+{
+	"3dfx (/dev/3dfx)",
+	"3dfx",
+	"Colin Cross <colin@MIT.EDU>",
+	""
+};
+
+static uint32_t is_fullscreen = 1;
+
+static uint32_t vidwidth;
+static uint32_t vidheight;
+
+static uint32_t screenwidth;
+static uint32_t screenheight;
+static uint32_t screendepth = 2; //Only 16bpp supported right now
+
+static uint32_t dispwidth = 1280; // You can change these to whatever you want
+static uint32_t dispheight = 720; // 16:9 screen ratio??
+static uint32_t dispx;
+static uint32_t dispy;
+
+static uint32_t *vidpage0;
+static uint32_t *vidpage1;
+static uint32_t *vidpage2;
+
+static uint32_t vidpage0offset;
+static uint32_t vidpage1offset;
+static uint32_t vidpage2offset;
+
+// Current pointer into framebuffer where display is located
+static uint32_t targetoffset;
+
+static uint32_t page_space;
+
+static voodoo_io_reg *reg_IO;
+static voodoo_2d_reg *reg_2d;
+static voodoo_yuv_reg *reg_YUV;
+static voodoo_yuv_fb *fb_YUV;
+
+static uint32_t *memBase0, *memBase1;
+static uint32_t baseAddr0, baseAddr1;
+
+
+/* X11 related variables */
+static Display *display;
+static Window mywindow;
+static int bpp;
+static XWindowAttributes attribs;
+static int X_already_started = 0;
+
+
+static void 
+restore(void) 
+{
+	//reg_IO->vidDesktopStartAddr = vidpage0offset;
+	XF86DGADirectVideo(display,0,0);
+}
+
+static void 
+sighup(int foo) 
+{
+	//reg_IO->vidDesktopStartAddr = vidpage0offset;
+	XF86DGADirectVideo(display,0,0);
+	exit(0);
+}
+
+static void 
+restore_regs(voodoo_2d_reg *regs) 
+{
+	reg_2d->commandExtra = regs->commandExtra;
+	reg_2d->clip0Min = regs->clip0Min;
+	reg_2d->clip0Max = regs->clip0Max;
+
+	reg_2d->srcBaseAddr = regs->srcBaseAddr;
+	reg_2d->srcXY = regs->srcXY;
+	reg_2d->srcFormat = regs->srcFormat;
+	reg_2d->srcSize = regs->srcSize;
+
+	reg_2d->dstBaseAddr = regs->dstBaseAddr;
+	reg_2d->dstXY = regs->dstXY;
+	reg_2d->dstFormat = regs->dstFormat;
+
+	reg_2d->dstSize = regs->dstSize;
+	reg_2d->command = 0;
+}
+
+static uint32_t 
+create_window(Display *display) 
+{
+	int screen;
+	unsigned int fg, bg;
+	char *hello = "I hate X11";
+	XSizeHints hint;
+	XVisualInfo vinfo;
+	XEvent xev;
+
+	Colormap theCmap;
+	XSetWindowAttributes xswa;
+	unsigned long xswamask;
+
+	if (X_already_started)
+		return -1;
+
+	screen = DefaultScreen(display);
+
+	hint.x = 0;
+	hint.y = 10;
+	hint.width = dispwidth;
+	hint.height = dispheight;
+	hint.flags = PPosition | PSize;
+
+	bg = WhitePixel(display, screen);
+	fg = BlackPixel(display, screen);
+
+	XGetWindowAttributes(display, DefaultRootWindow(display), &attribs);
+	bpp = attribs.depth;
+	if (bpp != 16) 
+	{
+		fprintf(stderr,"Only 16bpp supported!");
+		exit(-1);
+	}
+
+	XMatchVisualInfo(display,screen,bpp,TrueColor,&vinfo);
+	printf("visual id is  %lx\n",vinfo.visualid);
+
+	theCmap = XCreateColormap(display, RootWindow(display,screen),
+			vinfo.visual, AllocNone);
+
+	xswa.background_pixel = 0;
+	xswa.border_pixel     = 1;
+	xswa.colormap         = theCmap;
+	xswamask = CWBackPixel | CWBorderPixel |CWColormap;
+
+
+	mywindow = XCreateWindow(display, RootWindow(display,screen),
+				 hint.x, hint.y, hint.width, hint.height, 4, bpp,CopyFromParent,vinfo.visual,xswamask,&xswa);
+
+	XSelectInput(display, mywindow, StructureNotifyMask);
+
+	/* Tell other applications about this window */
+
+	XSetStandardProperties(display, mywindow, hello, hello, None, NULL, 0, &hint);
+
+	/* Map window. */
+
+	XMapWindow(display, mywindow);
+
+	/* Wait for map. */
+	do 
+	{
+		XNextEvent(display, &xev);
+	}
+	while (xev.type != MapNotify || xev.xmap.event != mywindow);
+
+	XSelectInput(display, mywindow, NoEventMask);
+
+	XFlush(display);
+	XSync(display, False);
+
+	X_already_started++;
+	return 0;
+}
+
+static void 
+dump_yuv_planar(uint32_t *y, uint32_t *u, uint32_t *v, uint32_t to, uint32_t width, uint32_t height) 
+{
+	// YUV conversion works like this:
+	//
+	//		 We write the Y, U, and V planes separately into 3dfx YUV Planar memory
+	//		 region.  The nice chip then takes these and packs them into the YUYV
+	//		 format in the regular frame buffer, starting at yuvBaseAddr, page 2 here.
+	//		 Then we tell the 3dfx to do a Screen to Screen Stretch BLT to copy all 
+	//		 of the data on page 2 onto page 1, converting it to 16 bpp RGB as it goes.
+	//		 The result is a nice image on page 1 ready for display. 
+
+	uint32_t j;
+	uint32_t y_imax, uv_imax, jmax;
+
+	reg_YUV->yuvBaseAddr = to;
+	reg_YUV->yuvStride = screenwidth*2;
+
+	LOG("video_out_3dfx: starting planar dump\n");
+	jmax = height>>1; // vidheight/2, height of U and V planes
+	y_imax = width; // Y plane is twice as wide as U and V planes
+	uv_imax = width>>1;  // vidwidth/2/4, width of U and V planes in 32-bit words
+
+	for (j=0;j<jmax;j++) 
+	{
+		//XXX this should be hand-rolled 32 bit memcpy for safeness.
+		memcpy(fb_YUV->U + (uint32_t) VOODOO_YUV_STRIDE*  j       ,((uint8_t*) u) + uv_imax*  j       , uv_imax);
+		memcpy(fb_YUV->V + (uint32_t) VOODOO_YUV_STRIDE*  j       ,((uint8_t*) v) + uv_imax*  j       , uv_imax);
+		memcpy(fb_YUV->Y + (uint32_t) VOODOO_YUV_STRIDE* (j<<1)   ,((uint8_t*) y) + y_imax * (j<<1)   , y_imax);
+		memcpy(fb_YUV->Y + (uint32_t) VOODOO_YUV_STRIDE*((j<<1)+1),((uint8_t*) y) + y_imax *((j<<1)+1), y_imax);
+	}
+  LOG("video_out_3dfx: done planar dump\n");
+}
+
+static void 
+screen_to_screen_stretch_blt(uint32_t to, uint32_t from, uint32_t width, uint32_t height) 
+{
+	//FIXME - this function should be called by a show_frame function that
+	//        uses a series of blts to show only those areas not covered
+	//        by another window
+	voodoo_2d_reg saved_regs;
+
+	LOG("video_out_3dfx: saving registers\n");
+	// Save VGA regs (so X kinda works when we're done)
+	saved_regs = *reg_2d;
+
+	/* The following lines set up the screen to screen stretch blt from page2 to
+		 page 1
+	*/
+
+	LOG("video_out_3dfx: setting blt registers\n");
+	reg_2d->commandExtra = 4; //disable colorkeying, enable wait for v-refresh (0100b)
+	reg_2d->clip0Min = 0;
+	reg_2d->clip0Max = 0xFFFFFFFF; //no clipping
+
+	reg_2d->srcBaseAddr = from;
+	reg_2d->srcXY = 0;
+	reg_2d->srcFormat = screenwidth*2 | VOODOO_BLT_FORMAT_YUYV; // | 1<<21;
+	reg_2d->srcSize = vidwidth | (vidheight << 16);
+
+	reg_2d->dstBaseAddr = to;
+	reg_2d->dstXY = 0;
+	reg_2d->dstFormat = screenwidth*2 | VOODOO_BLT_FORMAT_16;
+
+	reg_2d->dstSize = width | (height << 16);
+
+	LOG("video_out_3dfx: starting blt\n");
+	// Executes screen to screen stretch blt
+	reg_2d->command = 2 | 1<<8 | 0xCC<<24;
+
+	LOG("video_out_3dfx: restoring regs\n");
+	restore_regs(&saved_regs);
+
+	LOG("video_out_3dfx: done blt\n");
+}
+
+static void 
+update_target(void) 
+{
+	uint32_t xp, yp, w, h, b, d;
+	Window root;
+
+	XGetGeometry(display,mywindow,&root,&xp,&yp,&w,&h,&b,&d);
+	XTranslateCoordinates(display,mywindow,root,0,0,&xp,&yp,&root);
+	dispx = (uint32_t) xp;
+	dispy = (uint32_t) yp;
+	dispwidth = (uint32_t) w;
+	dispheight = (uint32_t) h;
+
+	if (is_fullscreen) 
+		targetoffset = vidpage0offset + (screenheight - dispheight)/2*screenwidth*screendepth + (screenwidth-dispwidth)/2*screendepth;
+	else 
+		targetoffset = vidpage0offset + (dispy*screenwidth + dispx)*screendepth;
+}
+
+static uint32_t 
+init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) 
+{
+	int fd;
+	char *name = ":0.0";
+	pioData data;
+	uint32_t retval;
+
+	if(getenv("DISPLAY"))
+		name = getenv("DISPLAY");
+	display = XOpenDisplay(name);
+
+	screenwidth = XDisplayWidth(display,0);
+	screenheight = XDisplayHeight(display,0);
+
+	page_space = screenwidth*screenheight*screendepth;
+	vidpage0offset = 0;
+	vidpage1offset = page_space;  // Use third and fourth pages
+	vidpage2offset = page_space*2;
+
+	signal(SIGALRM,sighup);
+	//alarm(120);
+
+	// Open driver device
+	if ( (fd = open("/dev/3dfx",O_RDWR) ) == -1) 
+	{
+		fprintf(stderr,"Couldn't open /dev/3dfx\n");
+		exit(1);
+	}
+
+	// Store sizes for later
+	vidwidth = width;
+	vidheight = height;
+
+	is_fullscreen = fullscreen = 0;
+	if (!is_fullscreen) 
+		create_window(display);
+
+	// Ask 3dfx driver for base memory address 0
+	data.port = 0x10; // PCI_BASE_ADDRESS_0_LINUX;
+	data.size = 4;
+	data.value = &baseAddr0;
+	data.device = 0;
+	if ((retval = ioctl(fd,_IOC(_IOC_READ,'3',3,0),&data)) < 0) 
+	{
+		printf("Error: %d\n",retval);
+		//return -1;
+	}
+
+	// Ask 3dfx driver for base memory address 1
+	data.port = 0x14; // PCI_BASE_ADDRESS_1_LINUX;
+	data.size = 4;
+	data.value = &baseAddr1;
+	data.device = 0;
+	if ((retval = ioctl(fd,_IOC(_IOC_READ,'3',3,0),&data)) < 0) 
+	{
+		printf("Error: %d\n",retval);
+		//return -1;
+	}
+
+	// Map all 3dfx memory areas
+	memBase0 = mmap(0,0x1000000,PROT_READ | PROT_WRITE,MAP_SHARED,fd,baseAddr0);
+	memBase1 = mmap(0,3*page_space,PROT_READ | PROT_WRITE,MAP_SHARED,fd,baseAddr1);
+	if (memBase0 == (uint32_t *) 0xFFFFFFFF || memBase1 == (uint32_t *) 0xFFFFFFFF) 
+	{
+		printf("Couldn't map 3dfx memory areas: %p,%p,%d\n", 
+		 memBase0,memBase1,errno);
+	}  
+
+	// Set up global pointers
+	reg_IO  = (void *)memBase0 + VOODOO_IO_REG_OFFSET;
+	reg_2d  = (void *)memBase0 + VOODOO_2D_REG_OFFSET;
+	reg_YUV = (void *)memBase0 + VOODOO_YUV_REG_OFFSET;
+	fb_YUV  = (void *)memBase0 + VOODOO_YUV_PLANE_OFFSET;
+
+	vidpage0 = (void *)memBase1 + (unsigned long int)vidpage0offset;
+	vidpage1 = (void *)memBase1 + (unsigned long int)vidpage1offset;
+	vidpage2 = (void *)memBase1 + (unsigned long int)vidpage2offset;
+
+	// Clear pages 1,2,3 
+	// leave page 0, that belongs to X.
+	// So does part of 1.  Oops.
+	memset(vidpage1,0x00,page_space);
+	memset(vidpage2,0x00,page_space);
+
+	if (is_fullscreen) 
+		memset(vidpage0,0x00,page_space);
+
+
+#ifndef VOODOO_DEBUG
+	// Show page 0 (unblanked)
+	reg_IO->vidDesktopStartAddr = vidpage0offset;
+
+	/* Stop X from messing with my video registers!
+		 Find a better way to do this?
+		 Currently I use DGA to tell XF86 to not screw with registers, but I can't really use it
+		 to do FB stuff because I need to know the absolute FB position and offset FB position
+		 to feed to BLT command 
+	*/
+	//XF86DGADirectVideo(display,0,XF86DGADirectGraphics); //| XF86DGADirectMouse | XF86DGADirectKeyb);
+#endif
+
+	/* fd is deliberately not closed - if it were, mmaps might be released??? */
+
+	atexit(restore);
+
+	printf("(display) 3dfx initialized %p\n",memBase1);
+	return 0;
+}
+
+static const vo_info_t*
+get_info(void)
+{
+	return &vo_info;
+}
+
+static uint32_t 
+draw_frame(uint8_t *src[]) 
+{
+	LOG("video_out_3dfx: starting display_frame\n");
+
+	// Put packed data onto page 2
+	dump_yuv_planar((uint32_t *)src[0],(uint32_t *)src[1],(uint32_t *)src[2],
+			vidpage2offset,vidwidth,vidheight);
+
+	LOG("video_out_3dfx: done display_frame\n");
+	return 0;
+}
+
+static uint32_t 
+draw_slice(uint8_t *src[], uint32_t slice_num) 
+{
+	uint32_t target;
+
+	target = vidpage2offset + (screenwidth*2 * 16*slice_num);
+	dump_yuv_planar((uint32_t *)src[0],(uint32_t *)src[1],(uint32_t *)src[2],target,vidwidth,16);
+	return 0;
+}
+
+static void 
+flip_page(void) 
+{
+	//FIXME - update_target() should be called by event handler when window
+	//        is resized or moved
+	update_target();
+	LOG("video_out_3dfx: calling blt function\n");
+	screen_to_screen_stretch_blt(targetoffset, vidpage2offset, dispwidth, dispheight);
+}
+
+static uint32_t
+query_format(uint32_t format)
+{
+    switch(format){
+    case IMGFMT_YV12:
+//    case IMGFMT_YUY2:
+//    case IMGFMT_RGB|24:
+//    case IMGFMT_BGR|24:
+        return 1;
+    }
+    return 0;
+}
+
+static void
+uninit(void)
+{
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/vo_gl.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,515 @@
+#define DISP
+
+// this can be 3 or 4  (regarding 24bpp and 32bpp)
+#define BYTES_PP 3
+
+#define TEXTUREFORMAT_32BPP
+
+/* 
+ * video_out_gl.c, X11/OpenGL interface
+ * based on video_out_x11 by Aaron Holtzman,
+ * and WS opengl window manager by Pontscho/Fresh!
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+
+LIBVO_EXTERN(gl)
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+//#include <X11/keysym.h>
+#include <GL/glx.h>
+#include <errno.h>
+#include "yuv2rgb.h"
+
+#include <GL/gl.h>
+
+static vo_info_t vo_info = 
+{
+	"X11 (OpenGL)",
+	"gl",
+	"Arpad Gereoffy <arpi@esp-team.scene.hu>",
+	""
+};
+
+/* private prototypes */
+static void Display_Image (unsigned char *ImageData);
+
+/* local data */
+static unsigned char *ImageData=NULL;
+
+/* X11 related variables */
+static Display *mydisplay;
+static Window mywindow;
+//static GC mygc;
+//static XImage *myximage;
+//static int depth,mode;
+static XWindowAttributes attribs;
+static int X_already_started = 0;
+
+static int texture_id=1;
+
+static GLXContext wsGLXContext;
+//XVisualInfo        * wsVisualInfo;
+int                  wsGLXAttrib[] = { GLX_RGBA,
+                                       GLX_RED_SIZE,1,
+                                       GLX_GREEN_SIZE,1,
+                                       GLX_BLUE_SIZE,1,
+//                                       GLX_DEPTH_SIZE,16,
+                                       GLX_DOUBLEBUFFER,
+                                       None };
+
+
+static uint32_t image_width;
+static uint32_t image_height;
+static uint32_t image_format;
+static uint32_t image_bpp;
+static uint32_t image_bytes;
+
+static uint32_t texture_width;
+static uint32_t texture_height;
+
+static resize(int x,int y){
+  printf("Resize: %dx%d\n",x,y);
+  glViewport( 0, 0, x, y );
+
+  glMatrixMode(GL_PROJECTION);
+  glLoadIdentity();
+  glOrtho(0, image_width, image_height, 0, -1,1);
+
+  glMatrixMode(GL_MODELVIEW);
+  glLoadIdentity();
+}
+
+extern void vo_decoration( Display * vo_Display,Window w,int d );
+
+/* connect to server, create and map window,
+ * allocate colors and (shared) memory
+ */
+static uint32_t 
+init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
+{
+	int screen;
+	unsigned int fg, bg;
+	char *hello = (title == NULL) ? "OpenGL rulez" : title;
+	char *name = ":0.0";
+	XSizeHints hint;
+	XVisualInfo *vinfo;
+	XEvent xev;
+
+	XGCValues xgcv;
+	XSetWindowAttributes xswa;
+	unsigned long xswamask;
+
+	image_height = height;
+	image_width = width;
+	image_format = format;
+  
+	if (X_already_started) return -1;
+
+	if(getenv("DISPLAY"))	name = getenv("DISPLAY");
+
+	mydisplay = XOpenDisplay(name);
+
+	if (mydisplay == NULL)
+	{
+		fprintf(stderr,"Can not open display\n");
+		return -1;
+	}
+
+	screen = DefaultScreen(mydisplay);
+
+	hint.x = 0;
+	hint.y = 0;
+	hint.width = d_width;
+	hint.height = d_height;
+	hint.flags = PPosition | PSize;
+
+	/* Get some colors */
+
+	bg = WhitePixel(mydisplay, screen);
+	fg = BlackPixel(mydisplay, screen);
+
+	/* Make the window */
+
+	XGetWindowAttributes(mydisplay, DefaultRootWindow(mydisplay), &attribs);
+
+#if 0
+	/*
+	 *
+	 * depth in X11 terminology land is the number of bits used to
+	 * actually represent the colour.
+   	 *
+	 * bpp in X11 land means how many bits in the frame buffer per
+	 * pixel. 
+	 *
+	 * ex. 15 bit color is 15 bit depth and 16 bpp. Also 24 bit
+	 *     color is 24 bit depth, but can be 24 bpp or 32 bpp.
+	 */
+
+	depth = attribs.depth;
+
+	if (depth != 15 && depth != 16 && depth != 24 && depth != 32) 
+	{
+		/* The root window may be 8bit but there might still be
+		* visuals with other bit depths. For example this is the 
+		* case on Sun/Solaris machines.
+		*/
+		depth = 24;
+	}
+	//BEGIN HACK
+	//mywindow = XCreateSimpleWindow(mydisplay, DefaultRootWindow(mydisplay),
+	//hint.x, hint.y, hint.width, hint.height, 4, fg, bg);
+	//
+#endif
+
+//	XMatchVisualInfo(mydisplay, screen, depth, TrueColor, &vinfo);
+  vinfo=glXChooseVisual( mydisplay,screen,wsGLXAttrib );
+
+	xswa.background_pixel = 0;
+	xswa.border_pixel     = 1;
+//	xswa.colormap         = XCreateColormap(mydisplay, RootWindow(mydisplay,screen), vinfo.visual, AllocNone);
+	xswa.colormap         = XCreateColormap(mydisplay, RootWindow(mydisplay,screen), vinfo->visual, AllocNone);
+	xswamask = CWBackPixel | CWBorderPixel | CWColormap;
+//  xswamask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWCursor | CWOverrideRedirect | CWSaveUnder | CWX | CWY | CWWidth | CWHeight;
+
+  mywindow = XCreateWindow(mydisplay, RootWindow(mydisplay,screen),
+    hint.x, hint.y, hint.width, hint.height, 4, vinfo->depth,CopyFromParent,vinfo->visual,xswamask,&xswa);
+
+  wsGLXContext=glXCreateContext( mydisplay,vinfo,NULL,True );
+//  XStoreName( wsDisplay,wsMyWin,wsSysName );
+
+//  printf("GLXcontext ok\n");
+
+  if ( fullscreen ) vo_decoration( mydisplay,mywindow,0 );
+
+	XSelectInput(mydisplay, mywindow, StructureNotifyMask);
+
+	/* Tell other applications about this window */
+
+	XSetStandardProperties(mydisplay, mywindow, hello, hello, None, NULL, 0, &hint);
+
+	/* Map window. */
+
+	XMapWindow(mydisplay, mywindow);
+
+	/* Wait for map. */
+	do 
+	{
+		XNextEvent(mydisplay, &xev);
+	}
+	while (xev.type != MapNotify || xev.xmap.event != mywindow);
+
+	XSelectInput(mydisplay, mywindow, NoEventMask);
+
+  glXMakeCurrent( mydisplay,mywindow,wsGLXContext );
+
+	XFlush(mydisplay);
+	XSync(mydisplay, False);
+
+//	mygc = XCreateGC(mydisplay, mywindow, 0L, &xgcv);
+
+//		myximage = XGetImage(mydisplay, mywindow, 0, 0,
+//		width, image_height, AllPlanes, ZPixmap);
+//		ImageData = myximage->data;
+//	bpp = myximage->bits_per_pixel;
+
+	//XSelectInput(mydisplay, mywindow, StructureNotifyMask); // !!!!
+        XSelectInput(mydisplay, mywindow, StructureNotifyMask | KeyPressMask );
+
+//  printf("Window setup ok\n");
+
+#if 0
+	// If we have blue in the lowest bit then obviously RGB 
+	mode = ((myximage->blue_mask & 0x01) != 0) ? MODE_RGB : MODE_BGR;
+#ifdef WORDS_BIGENDIAN 
+	if (myximage->byte_order != MSBFirst)
+#else
+	if (myximage->byte_order != LSBFirst) 
+#endif
+	{
+		fprintf( stderr, "No support fon non-native XImage byte order!\n" );
+		return -1;
+	}
+
+  printf("DEPTH=%d  BPP=%d\n",depth,bpp);
+#endif
+
+	/* 
+	 * If depth is 24 then it may either be a 3 or 4 byte per pixel
+	 * format. We can't use bpp because then we would lose the 
+	 * distinction between 15/16bit depth (2 byte formate assumed).
+	 *
+	 * FIXME - change yuv2rgb_init to take both depth and bpp
+	 * parameters
+	 */
+
+  texture_width=32;
+  while(texture_width<image_width) texture_width*=2;
+  while(texture_width<image_height) texture_width*=2;
+  texture_height=texture_width;
+
+  if(format==IMGFMT_YV12){
+    yuv2rgb_init(8*BYTES_PP, MODE_BGR);
+    printf("YUV init OK!\n");
+    image_bpp=8*BYTES_PP;
+    image_bytes=BYTES_PP;
+  } else {
+    image_bpp=format&0xFF;
+    image_bytes=(image_bpp+7)/8;
+  }
+
+  ImageData=malloc(texture_width*texture_height*image_bytes);
+  memset(ImageData,128,texture_width*texture_height*image_bytes);
+
+  glDisable(GL_BLEND); 
+  glDisable(GL_DEPTH_TEST);
+  glDepthMask(GL_FALSE);
+  glDisable(GL_CULL_FACE);
+
+  glEnable(GL_TEXTURE_2D);
+
+  printf("Creating %dx%d texture...\n",texture_width,texture_height);
+
+#if 1
+//  glBindTexture(GL_TEXTURE_2D, texture_id);
+  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+  glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+#ifdef TEXTUREFORMAT_32BPP
+  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, texture_width, texture_height, 0,
+#else
+  glTexImage2D(GL_TEXTURE_2D, 0, BYTES_PP, texture_width, texture_height, 0,
+#endif
+       (image_bytes==4)?GL_RGBA:GL_BGR, GL_UNSIGNED_BYTE, ImageData);
+#endif
+
+  resize(d_width,d_height);
+
+  glClearColor( 1.0f,0.0f,1.0f,0.0f );
+  glClear( GL_COLOR_BUFFER_BIT );
+
+//  printf("OpenGL setup OK!\n");
+
+	X_already_started++;
+	return 0;
+}
+
+static const vo_info_t*
+get_info(void)
+{
+	return &vo_info;
+}
+
+static void 
+Terminate_Display_Process(void) 
+{
+	getchar();	/* wait for enter to remove window */
+	XDestroyWindow(mydisplay, mywindow);
+	XCloseDisplay(mydisplay);
+	X_already_started = 0;
+}
+
+static void 
+FlipImage()
+{
+ int            i;
+ XEvent         Event;
+ char           buf[100];
+ KeySym         keySym;
+ XComposeStatus stat;
+ unsigned long  vo_KeyTable[512];
+
+ while ( XPending( mydisplay ) )
+  {
+   XNextEvent( mydisplay,&Event );
+   switch( Event.type )
+    {
+       case ConfigureNotify:
+             resize( Event.xconfigure.width,Event.xconfigure.height );
+             break;
+       case KeyPress:
+             XLookupString( &Event.xkey,buf,sizeof(buf),&keySym,&stat );
+             vo_keyboard( ( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ) );
+             break;
+    }
+  }
+
+//  glEnable(GL_TEXTURE_2D);
+//  glBindTexture(GL_TEXTURE_2D, texture_id);
+
+  glColor3f(1,1,1);
+  glBegin(GL_QUADS);
+    glTexCoord2f(0,0);glVertex2i(0,0);
+    glTexCoord2f(0,1);glVertex2i(0,texture_height);
+    glTexCoord2f(1,1);glVertex2i(texture_width,texture_height);
+    glTexCoord2f(1,0);glVertex2i(texture_width,0);
+  glEnd();
+
+//  glFlush();
+  glFinish();
+  glXSwapBuffers( mydisplay,mywindow );
+  
+}
+
+static void
+flip_page(void)
+{
+  FlipImage();
+}
+
+//static inline uint32_t draw_slice_x11(uint8_t *src[], uint32_t slice_num)
+static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
+{
+    int i;
+    int dstride=w*BYTES_PP;
+    
+//    dstride=(dstride+15)&(~15);
+
+	yuv2rgb(ImageData, src[0], src[1], src[2], 
+			w,h, dstride, stride[0],stride[1]);
+
+//	emms ();
+
+    for(i=0;i<h;i++){
+      glTexSubImage2D( GL_TEXTURE_2D,  // target
+		       0,              // level
+		       x,              // x offset
+		       y+i,            // y offset
+		       w,              // width
+		       1,              // height
+		       (BYTES_PP==4)?GL_RGBA:GL_RGB,        // format
+		       GL_UNSIGNED_BYTE, // type
+		       ImageData+i*dstride );        // *pixels
+    }
+
+	return 0;
+}
+
+static inline uint32_t 
+draw_frame_x11_yv12(uint8_t *src[])
+{
+int i;
+//  printf("Converting YUV->RGB...\n");
+	yuv2rgb(ImageData, src[0], src[1], src[2],
+		image_width, image_height, 
+		image_width*BYTES_PP, image_width, image_width/2 );
+//  printf("Ready!\n");
+
+//		emms ();
+
+    for(i=0;i<image_height;i++){
+      glTexSubImage2D( GL_TEXTURE_2D,  // target
+		       0,              // level
+		       0,              // x offset
+		       i,              // y offset
+		       image_width,    // width
+		       1,              // height
+		       (BYTES_PP==4)?GL_RGBA:GL_RGB,        // format
+		       GL_UNSIGNED_BYTE, // type
+		       ImageData+i*BYTES_PP*image_width );        // *pixels
+    }
+
+//	Display_Image(ImageData);
+//  FlipImage();
+	return 0; 
+}
+
+
+static inline uint32_t 
+draw_frame_x11_bgr(uint8_t *src[])
+{
+int i;
+uint8_t *s=src[0];
+uint8_t *de=&ImageData[3*image_width];
+
+    for(i=0;i<image_height;i++){
+      int j;
+      uint8_t *d=ImageData;
+      while(d<de){
+        d[0]=s[2];
+        d[1]=s[1];
+        d[2]=s[0];
+        s+=3;d+=3;
+      }
+      glTexSubImage2D( GL_TEXTURE_2D,  // target
+		       0,              // level
+		       0,              // x offset
+//		       image_height-1-i,  // y offset
+		       i,  // y offset
+		       image_width,    // width
+		       1,              // height
+		       (image_bytes==4)?GL_RGBA:GL_RGB,        // format
+		       GL_UNSIGNED_BYTE, // type
+		       ImageData);        // *pixels
+    }
+
+//	Display_Image(ImageData);
+//  FlipImage();
+	return 0; 
+}
+
+static inline uint32_t 
+draw_frame_x11_rgb(uint8_t *src[])
+{
+int i;
+uint8_t *ImageData=src[0];
+
+    for(i=0;i<image_height;i++){
+      glTexSubImage2D( GL_TEXTURE_2D,  // target
+		       0,              // level
+		       0,              // x offset
+//		       image_height-1-i,  // y offset
+		       i,  // y offset
+		       image_width,    // width
+		       1,              // height
+		       (image_bytes==4)?GL_RGBA:GL_RGB,        // format
+		       GL_UNSIGNED_BYTE, // type
+		       ImageData+i*image_bytes*image_width );        // *pixels
+    }
+
+//	Display_Image(ImageData);
+//  FlipImage();
+	return 0; 
+}
+
+
+static uint32_t
+draw_frame(uint8_t *src[])
+{
+    if(image_format==IMGFMT_YV12)
+	return draw_frame_x11_yv12(src);
+    else 
+    if((image_format&IMGFMT_RGB_MASK)==IMGFMT_RGB)
+	return draw_frame_x11_rgb(src);
+    else
+	return draw_frame_x11_bgr(src);
+}
+
+static uint32_t
+query_format(uint32_t format)
+{
+    switch(format){
+    case IMGFMT_YV12:
+    case IMGFMT_RGB|24:
+    case IMGFMT_BGR|24:
+        return 1;
+    }
+    return 0;
+}
+
+
+static void
+uninit(void)
+{
+vo_kill_eventhandler();
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/vo_md5.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,106 @@
+#define DISP
+
+/* 
+ * video_out_pgm.c, pgm interface
+ *
+ *
+ * Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. 
+ *
+ * Hacked into mpeg2dec by
+ * 
+ * Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * 15 & 16 bpp support added by Franck Sicard <Franck.Sicard@solsoft.fr>
+ *
+ * Xv image suuport by Gerd Knorr <kraxel@goldbach.in-berlin.de>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+LIBVO_EXTERN (md5)
+
+static vo_info_t vo_info = 
+{
+	"MD5 sum",
+	"md5",
+	"walken",
+	""
+};
+
+extern vo_functions_t video_out_pgm;
+
+static FILE * md5_file;
+static int framenum = -2;
+
+static uint32_t
+init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
+{
+    md5_file = fopen ("md5", "w");
+    return video_out_pgm.init (width, height, d_width,d_height,fullscreen, title, format);
+}
+
+static const vo_info_t*
+get_info(void)
+{
+    return &vo_info;
+}
+
+static void flip_page (void)
+{
+}
+
+//static uint32_t draw_slice(uint8_t * src[], uint32_t slice_num)
+static uint32_t draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y)
+{
+    return 0;
+}
+
+extern uint32_t output_pgm_frame (char * fname, uint8_t * src[]);
+
+static uint32_t draw_frame(uint8_t * src[])
+{
+    char buf[100];
+    char buf2[100];
+    FILE * f;
+    int i;
+
+    if (++framenum < 0)
+	return 0;
+
+    sprintf (buf, "%d.pgm", framenum);
+    output_pgm_frame (buf, src);
+
+    sprintf (buf2, "md5sum %s", buf);
+    f = popen (buf2, "r");
+    i = fread (buf2, 1, sizeof(buf2), f);
+    pclose (f);
+    fwrite (buf2, 1, i, md5_file);
+
+    remove (buf);
+
+    return 0;
+}
+
+static uint32_t
+query_format(uint32_t format)
+{
+    switch(format){
+    case IMGFMT_YV12:
+        return 1;
+    }
+    return 0;
+}
+
+
+static void
+uninit(void)
+{
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/vo_mga.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,127 @@
+
+//#define memcpy(a,b,c)
+
+/* 
+ *    video_out_mga.c
+ *
+ *	Copyright (C) Aaron Holtzman - Aug 1999
+ *
+ *  This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *	
+ *  mpeg2dec 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, or (at your option)
+ *  any later version.
+ *   
+ *  mpeg2dec 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 GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+LIBVO_EXTERN(mga)
+
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+#include "drivers/mga_vid.h"
+
+static vo_info_t vo_info = 
+{
+	"Matrox G200/G400 overlay (/dev/mga_vid)",
+	"mga",
+	"Aaron Holtzman <aholtzma@ess.engr.uvic.ca>",
+	""
+};
+
+static mga_vid_config_t mga_vid_config;
+static uint8_t *vid_data, *frame0, *frame1;
+static int next_frame = 0;
+static int f;
+
+#include "mga_common.c"
+
+static uint32_t
+init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
+{
+	char *frame_mem;
+	uint32_t frame_size;
+
+	f = open("/dev/mga_vid",O_RDWR);
+
+	if(f == -1)
+	{
+		fprintf(stderr,"Couldn't open /dev/mga_vid\n"); 
+		return(-1);
+	}
+
+        switch(format){
+        case IMGFMT_YV12:
+            mga_vid_config.format=MGA_VID_FORMAT_YV12; break;
+        case IMGFMT_YUY2:
+            mga_vid_config.format=MGA_VID_FORMAT_YUY2; break;
+        default: 
+            fprintf(stderr,"mga: invalid output format %0X\n",format);
+            return (-1);
+        }
+
+	mga_vid_config.src_width = width;
+	mga_vid_config.src_height= height;
+//	mga_vid_config.dest_width = width;
+//	mga_vid_config.dest_height= height;
+	mga_vid_config.dest_width = d_width;
+//        (width<704)?704:width;   // HACK
+	mga_vid_config.dest_height= d_height;
+//        (height<576)?576:height; // HACK
+	mga_vid_config.x_org= 0; // (720-mga_vid_config.dest_width)/2;
+	mga_vid_config.y_org= 0; // (576-mga_vid_config.dest_height)/2;
+
+	if (ioctl(f,MGA_VID_CONFIG,&mga_vid_config))
+	{
+		perror("Error in mga_vid_config ioctl");
+	}
+	ioctl(f,MGA_VID_ON,0);
+
+	frame_size = ((width + 31) & ~31) * height + (((width + 31) & ~31) * height) / 2;
+	frame_mem = (char*)mmap(0,frame_size*2,PROT_WRITE,MAP_SHARED,f,0);
+	frame0 = frame_mem;
+	frame1 = frame_mem + frame_size;
+	vid_data = frame0;
+	next_frame = 0;
+
+	//clear the buffer
+	memset(frame_mem,0x80,frame_size*2);
+
+  return 0;
+}
+
+static const vo_info_t*
+get_info(void)
+{
+	return &vo_info;
+}
+
+static void
+uninit(void)
+{
+ ioctl( f,MGA_VID_OFF,0 );
+printf("vo: uninit!\n");
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/vo_null.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,85 @@
+/* 
+ *  video_out_null.c
+ *
+ *	Copyright (C) Aaron Holtzman - June 2000
+ *
+ *  This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *	
+ *  mpeg2dec 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, or (at your option)
+ *  any later version.
+ *   
+ *  mpeg2dec 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 GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
+ *
+ */
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+LIBVO_EXTERN(null)
+
+
+static vo_info_t vo_info = 
+{
+	"Null video output",
+	"null",
+	"Aaron Holtzman <aholtzma@ess.engr.uvic.ca>",
+	""
+};
+
+static uint32_t image_width, image_height;
+
+//static uint32_t
+static uint32_t draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y)
+//draw_slice(uint8_t *src[], uint32_t slice_num)
+{
+	return 0;
+}
+
+static void
+flip_page(void)
+{
+}
+
+static uint32_t
+draw_frame(uint8_t *src[])
+{
+	return 0;
+}
+
+static uint32_t
+query_format(uint32_t format)
+{
+    return 1;
+}
+
+static uint32_t
+init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
+{
+	image_width = width;
+	image_height = height;
+	return 0;
+}
+
+static const vo_info_t*
+get_info(void)
+{
+	return &vo_info;
+}
+
+static void
+uninit(void)
+{
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/vo_odivx.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,234 @@
+/* 
+ *  OpenDivX AVI file writer
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+LIBVO_EXTERN(odivx)
+
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+#include "../encore/encore.h"
+
+static vo_info_t vo_info = 
+{
+	"OpenDivX AVI File writer",
+	"odivx",
+	"Arpad Gereoffy <arpi@esp-team.scene.hu>",
+	""
+};
+
+static uint8_t *image=NULL;
+static int image_width=0;
+static int image_height=0;
+static unsigned int image_format=0;
+static char *buffer=NULL;
+static int frameno=0;
+
+extern char* encode_name;
+extern char* encode_index_name;
+
+//static uint32_t draw_slice(uint8_t *src[], uint32_t slice_num)
+static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
+{
+    uint8_t *s;
+    uint8_t *d;
+    int i;
+    int dstride=image_width;
+
+    // copy Y
+    d=image+dstride*y+x;
+    s=src[0];
+    for(i=0;i<h;i++){
+        memcpy(d,s,w);
+        s+=stride[0];
+        d+=dstride;
+    }
+    
+    w/=2;h/=2;x/=2;y/=2; dstride/=2;
+    
+    // copy U
+    d=image+image_width*image_height + dstride*y+x;
+    s=src[1];
+    for(i=0;i<h;i++){
+        memcpy(d,s,w);
+        s+=stride[1];
+        d+=dstride;
+    }
+
+    // copy V
+    d=image+image_width*image_height +image_width*image_height/4 + dstride*y+x;
+    s=src[2];
+    for(i=0;i<h;i++){
+        memcpy(d,s,w);
+        s+=stride[2];
+        d+=dstride;
+    }
+    
+    return 0;
+}
+
+static uint32_t
+draw_frame(uint8_t *src[])
+{
+  uint8_t *d=image;
+
+  switch(image_format){
+  case IMGFMT_YV12:
+    // copy Y
+    memcpy(d,src[0],image_width*image_height);
+    // copy U
+    d+=image_width*image_height;
+    memcpy(d,src[1],image_width*image_height/4);
+    // copy V
+    d+=image_width*image_height/4;
+    memcpy(d,src[2],image_width*image_height/4);
+    break;
+//    case IMGFMT_YUY2:
+  case IMGFMT_BGR|24:
+    memcpy(d,src[0],image_width*image_height*3);
+    break;
+  }
+
+  return 0;
+}
+
+typedef unsigned int DWORD;
+
+typedef struct
+{
+    DWORD               ckid;
+    DWORD               dwFlags;
+    DWORD               dwChunkOffset;          // Position of chunk
+    DWORD               dwChunkLength;          // Length of chunk
+} AVIINDEXENTRY;
+
+static void
+flip_page(void)
+{
+
+// we are rady to encode this frame
+ENC_FRAME enc_frame;
+ENC_RESULT enc_result;
+
+if(++frameno<10) return;
+
+enc_frame.bmp=image;
+enc_frame.bitstream=buffer;
+enc_frame.length=0;
+encore(0x123,0,&enc_frame,&enc_result);
+
+printf("coded length: %d  \n",enc_frame.length);
+
+if(encode_name){
+  AVIINDEXENTRY i;
+  FILE *file;
+  i.ckid=('c'<<24)|('d'<<16)|('0'<<8)|'0'; // "00dc"
+  i.dwFlags=enc_result.isKeyFrame?0x10:0;
+  i.dwChunkLength=enc_frame.length;
+  // Write AVI chunk:
+  if((file=fopen(encode_name,"ab"))){
+    unsigned char zerobyte=0;
+    i.dwChunkOffset=ftell(file);
+    fwrite(&i.ckid,4,1,file);
+    fwrite(&enc_frame.length,4,1,file);
+    fwrite(buffer,enc_frame.length,1,file);
+    if(enc_frame.length&1) fwrite(&zerobyte,1,1,file); // padding
+    fclose(file);
+  }
+  // Write AVI index:
+  if(encode_index_name && (file=fopen(encode_index_name,"ab"))){
+    fwrite(&i,sizeof(i),1,file);
+    fclose(file);
+  }
+}
+
+
+}
+
+static uint32_t
+query_format(uint32_t format)
+{
+    switch(format){
+    case IMGFMT_YV12:
+//    case IMGFMT_YUY2:
+    case IMGFMT_BGR|24:
+        return 1;
+    }
+    return 0;
+}
+
+extern int encode_bitrate;
+
+static uint32_t
+init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
+{
+	uint32_t frame_size;
+        ENC_PARAM enc_param;
+
+//	file = fopen("encoded.odvx","wb");
+//        if(!file) return -1;
+        
+    switch(format){
+    case IMGFMT_YV12:
+        frame_size=width*height+width*height/2;
+        enc_param.flip=2; // 0=RGB  1=flippedRGB  2=planarYUV format
+        break;
+    case IMGFMT_BGR|24:
+        enc_param.flip=0; // 0=RGB  1=flippedRGB  2=planarYUV format
+        frame_size=width*height*3;
+        break;
+    default: return -1; // invalid format
+    }
+
+    enc_param.x_dim=width;
+    enc_param.y_dim=height;
+
+    image_width=width;
+    image_height=height;
+    image_format=format;
+    image=malloc(frame_size);
+
+	//clear the buffer
+	memset(image,0x80,frame_size);
+
+    // buffer for encoded video data:
+    buffer=malloc(0x100000);
+    if(!buffer) return -1;
+
+    // encoding parameters:
+    enc_param.framerate=25.0;
+    enc_param.bitrate=encode_bitrate?encode_bitrate:780000;
+    enc_param.rc_period=300;
+    enc_param.max_quantizer=15;
+    enc_param.min_quantizer=1;
+    enc_param.search_range=128;
+
+    // init codec:
+    encore(0x123,ENC_OPT_INIT,&enc_param,NULL);
+
+  return 0;
+}
+
+static const vo_info_t*
+get_info(void)
+{
+	return &vo_info;
+}
+
+static void
+uninit(void)
+{
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/vo_pgm.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,115 @@
+#define DISP
+
+/* 
+ * video_out_pgm.c, pgm interface
+ *
+ *
+ * Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. 
+ *
+ * Hacked into mpeg2dec by
+ * 
+ * Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * 15 & 16 bpp support added by Franck Sicard <Franck.Sicard@solsoft.fr>
+ *
+ * Xv image suuport by Gerd Knorr <kraxel@goldbach.in-berlin.de>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+LIBVO_EXTERN (pgm)
+
+static vo_info_t vo_info = 
+{
+	"PGM file",
+	"pgm",
+	"walken",
+	""
+};
+
+static int image_width;
+static int image_height;
+static char header[1024];
+static int framenum = -2;
+
+static uint32_t
+init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
+{
+    image_height = height;
+    image_width = width;
+
+    sprintf (header, "P5\n\n%d %d\n255\n", width, height*3/2);
+
+    return 0;
+}
+
+static const vo_info_t*
+get_info(void)
+{
+    return &vo_info;
+}
+
+static void flip_page (void)
+{
+}
+
+static uint32_t draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y)
+//static uint32_t draw_slice(uint8_t * src[], uint32_t slice_num)
+{
+    return 0;
+}
+
+uint32_t output_pgm_frame (char * fname, uint8_t * src[])
+{
+    FILE * f;
+    int i;
+
+    f = fopen (fname, "wb");
+    if (f == NULL) return 1;
+    fwrite (header, strlen (header), 1, f);
+    fwrite (src[0], image_width, image_height, f);
+    for (i = 0; i < image_height/2; i++) {
+	fwrite (src[1]+i*image_width/2, image_width/2, 1, f);
+	fwrite (src[2]+i*image_width/2, image_width/2, 1, f);
+    }
+    fclose (f);
+
+    return 0;
+}
+
+static uint32_t draw_frame(uint8_t * src[])
+{
+    char buf[100];
+
+    if (++framenum < 0)
+	return 0;
+
+    sprintf (buf, "%d.pgm", framenum);
+    return output_pgm_frame (buf, src);
+}
+
+static uint32_t
+query_format(uint32_t format)
+{
+    switch(format){
+    case IMGFMT_YV12:
+//    case IMGFMT_RGB|24:
+//    case IMGFMT_BGR|24:
+        return 1;
+    }
+    return 0;
+}
+
+static void
+uninit(void)
+{
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/vo_sdl.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,607 @@
+/*
+ *  video_out_sdl.c
+ *
+ *  Copyright (C) Ryan C. Gordon <icculus@lokigames.com> - April 22, 2000.
+ *
+ *  A mpeg2dec display driver that does output through the
+ *  Simple DirectMedia Layer (SDL) library. This effectively gives us all
+ *  sorts of output options: X11, SVGAlib, fbcon, AAlib, GGI. Win32, MacOS
+ *  and BeOS support, too. Yay. SDL info, source, and binaries can be found
+ *  at http://slouken.devolution.com/SDL/
+ *
+ *  This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *	
+ *  mpeg2dec 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, or (at your option)
+ *  any later version.
+ *   
+ *  mpeg2dec 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 GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 
+ *
+ *  Changes:
+ *    Dominik Schnitzer <dominik@schnitzer.at> - November 08, 2000.
+ *    - Added resizing support, fullscreen: chnaged the sdlmodes selection
+ *       routine.
+ *    - SDL bugfixes: removed the atexit(SLD_Quit), SDL_Quit now resides in
+ *       the plugin_exit routine.
+ *    - Commented the source :)
+ *    - Shortcuts: for switching between Fullscreen/Windowed mode and for
+ *       cycling between the different Fullscreen modes.
+ *    - Small bugfixes: proper width/height of movie
+ *    Dominik Schnitzer <dominik@schnitzer.at> - November 11, 2000.
+ *    - Cleanup code, more comments
+ *    - Better error handling
+ *    Bruno Barreyra <barreyra@ufl.edu> - December 10, 2000.
+ *    - Eliminated memcpy's for entire frames
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+LIBVO_EXTERN(sdl)
+
+//#include "log.h"
+//#define LOG if(0)printf
+
+static vo_info_t vo_info = 
+{
+	"SDL YUV overlay (SDL v1.1.7 only!)",
+	"sdl",
+	"Ryan C. Gordon <icculus@lokigames.com>",
+	""
+};
+
+#include <SDL/SDL.h>
+
+/** Private SDL Data structure **/
+
+static struct sdl_priv_s {
+
+	/* SDL YUV surface & overlay */
+	SDL_Surface *surface;
+	SDL_Overlay *overlay;
+//	SDL_Overlay *current_frame;
+
+	/* available fullscreen modes */
+	SDL_Rect **fullmodes;
+
+	/* surface attributes for fullscreen and windowed mode */
+	Uint32 sdlflags, sdlfullflags;
+
+	/* save the windowed output extents */
+	SDL_Rect windowsize;
+	
+	/* Bits per Pixel */
+	Uint8 bpp;
+
+	/* current fullscreen mode, 0 = highest available fullscreen mode */
+	int fullmode;
+
+	/* YUV ints */
+	int framePlaneY, framePlaneUV;
+	int stridePlaneY, stridePlaneUV;
+        int width,height;
+        int format;
+} sdl_priv;
+
+
+/** OMS Plugin functions **/
+
+
+/**
+ * Take a null-terminated array of pointers, and find the last element.
+ *
+ *    params : array == array of which we want to find the last element.
+ *   returns : index of last NON-NULL element.
+ **/
+
+static inline int findArrayEnd (SDL_Rect **array)
+{
+	int i = 0;
+	while ( array[i++] );	/* keep loopin' ... */
+	
+	/* return the index of the last array element */
+	return i - 1;
+}
+
+
+/**
+ * Open and prepare SDL output.
+ *
+ *    params : *plugin ==
+ *             *name == 
+ *   returns : 0 on success, -1 on failure
+ **/
+
+static int sdl_open (void *plugin, void *name)
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+	const SDL_VideoInfo *vidInfo = NULL;
+	static int opened = 0;
+
+	if (opened)
+	    return 0;
+	opened = 1;
+
+//	LOG (LOG_DEBUG, "SDL video out: Opened Plugin");
+	
+	/* default to no fullscreen mode, we'll set this as soon we have the avail. mdoes */
+	priv->fullmode = -2;
+	/* other default values */
+	priv->sdlflags = SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT;
+	priv->sdlfullflags = SDL_HWSURFACE|SDL_FULLSCREEN|SDL_DOUBLEBUF|SDL_ASYNCBLIT;
+	priv->surface = NULL;
+	priv->overlay = NULL;
+	priv->fullmodes = NULL;
+
+	/* initialize the SDL Video system */
+	if (SDL_Init (SDL_INIT_VIDEO)) {
+//		LOG (LOG_ERROR, "SDL video out: Initializing of SDL failed (SDL_Init). Please use the latest version of SDL.");
+		return -1;
+	}
+	
+	/* No Keyrepeats! */
+	SDL_EnableKeyRepeat(0,0);
+
+	/* get information about the graphics adapter */
+	vidInfo = SDL_GetVideoInfo ();
+	
+	/* collect all fullscreen & hardware modes available */
+	if (!(priv->fullmodes = SDL_ListModes (vidInfo->vfmt, priv->sdlfullflags))) {
+
+		/* non hardware accelerated fullscreen modes */
+		priv->sdlfullflags &= ~SDL_HWSURFACE;
+ 		priv->fullmodes = SDL_ListModes (vidInfo->vfmt, priv->sdlfullflags);
+	}
+	
+	/* test for normal resizeable & windowed hardware accellerated surfaces */
+	if (!SDL_ListModes (vidInfo->vfmt, priv->sdlflags)) {
+		
+		/* test for NON hardware accelerated resizeable surfaces - poor you. 
+		 * That's all we have. If this fails there's nothing left.
+		 * Theoretically there could be Fullscreenmodes left - we ignore this for now.
+		 */
+		priv->sdlflags &= ~SDL_HWSURFACE;
+		if ((!SDL_ListModes (vidInfo->vfmt, priv->sdlflags)) && (!priv->fullmodes)) {
+//			LOG (LOG_ERROR, "SDL video out: Couldn't get any acceptable SDL Mode for output. (SDL_ListModes failed)");
+			return -1;
+		}
+	}
+	
+		
+   /* YUV overlays need at least 16-bit color depth, but the
+    * display might less. The SDL AAlib target says it can only do
+    * 8-bits, for example. So, if the display is less than 16-bits,
+    * we'll force the BPP to 16, and pray that SDL can emulate for us.
+	 */
+	priv->bpp = vidInfo->vfmt->BitsPerPixel;
+	if (priv->bpp < 16) {
+/*
+		LOG (LOG_WARNING, "SDL video out: Your SDL display target wants to be at a color depth of (%d), but we need it to be at\
+least 16 bits, so we need to emulate 16-bit color. This is going to slow things down; you might want to\
+increase your display's color depth, if possible", priv->bpp);
+*/
+		priv->bpp = 16;  
+	}
+	
+	/* We dont want those in out event queue */
+	SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
+	SDL_EventState(SDL_KEYUP, SDL_IGNORE);
+	SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
+	SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE);
+	SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE);
+	SDL_EventState(SDL_QUIT, SDL_IGNORE);
+	SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
+	SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
+	
+	/* Success! */
+	return 0;
+}
+
+
+/**
+ * Close SDL, Cleanups, Free Memory
+ *
+ *    params : *plugin
+ *   returns : non-zero on success, zero on error.
+ **/
+
+static int sdl_close (void)
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+	
+//	LOG (LOG_DEBUG, "SDL video out: Closed Plugin");
+//	LOG (LOG_INFO, "SDL video out: Closed Plugin");
+
+	/* Cleanup YUV Overlay structure */
+	if (priv->overlay) 
+		SDL_FreeYUVOverlay(priv->overlay);
+
+	/* Free our blitting surface */
+	if (priv->surface)
+		SDL_FreeSurface(priv->surface);
+	
+	/* TODO: cleanup the full_modes array */
+	
+	/* Cleanup SDL */
+	SDL_Quit();
+
+	return 0;
+}
+
+
+/**
+ * Sets the specified fullscreen mode.
+ *
+ *   params : mode == index of the desired fullscreen mode
+ *  returns : doesn't return
+ **/
+ 
+static void set_fullmode (int mode)
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+	SDL_Surface *newsurface = NULL;
+	
+	
+	/* if we haven't set a fullmode yet, default to the lowest res fullmode first */
+	if (mode < 0) 
+		mode = priv->fullmode = findArrayEnd(priv->fullmodes) - 1;
+
+	/* change to given fullscreen mode and hide the mouse cursor*/
+	newsurface = SDL_SetVideoMode(priv->fullmodes[mode]->w, priv->fullmodes[mode]->h, priv->bpp, priv->sdlfullflags);
+	
+	/* if we were successfull hide the mouse cursor and save the mode */
+	if (newsurface) {
+		priv->surface = newsurface;
+		SDL_ShowCursor(0);
+	}
+}
+
+
+/**
+ * Initialize an SDL surface and an SDL YUV overlay.
+ *
+ *    params : width  == width of video we'll be displaying.
+ *             height == height of video we'll be displaying.
+ *             fullscreen == want to be fullscreen?
+ *             title == Title for window titlebar.
+ *   returns : non-zero on success, zero on error.
+ **/
+
+static uint32_t
+init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
+//static int sdl_setup (int width, int height)
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+        unsigned int sdl_format;
+
+        switch(format){
+          case IMGFMT_YV12: sdl_format=SDL_YV12_OVERLAY;break;
+          case IMGFMT_YUY2: sdl_format=SDL_YUY2_OVERLAY;break;
+          default:
+            printf("SDL: Unsupported image format (0x%X)\n",format);
+            return -1;
+        }
+
+	sdl_open (NULL, NULL);
+
+	/* Save the original Image size */
+
+	priv->width  = width;
+	priv->height = height;
+        priv->format = format;
+        
+        if(fullscreen){
+	    priv->windowsize.w = width;
+	    priv->windowsize.h = height;
+            priv->surface=NULL;
+            set_fullmode(priv->fullmode);
+        } else {
+	    priv->windowsize.w = d_width;
+	    priv->windowsize.h = d_height;
+            priv->surface = SDL_SetVideoMode (d_width, d_height, priv->bpp, priv->sdlflags);
+        }
+        if(!priv->surface) return -1; // cannot SetVideoMode
+
+	/* Initialize and create the YUV Overlay used for video out */
+	if (!(priv->overlay = SDL_CreateYUVOverlay (width, height, sdl_format, priv->surface))) {
+		printf ("SDL video out: Couldn't create an SDL-based YUV overlay\n");
+		return -1;
+	}
+	priv->framePlaneY = width * height;
+	priv->framePlaneUV = (width * height) >> 2;
+	priv->stridePlaneY = width;
+	priv->stridePlaneUV = width/2;
+
+	return 0;
+}
+
+
+/**
+ * Draw a frame to the SDL YUV overlay.
+ *
+ *   params : *src[] == the Y, U, and V planes that make up the frame.
+ *  returns : non-zero on success, zero on error.
+ **/
+
+//static int sdl_draw_frame (frame_t *frame)
+static uint32_t draw_frame(uint8_t *src[])
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+	uint8_t *dst;
+
+//	priv->current_frame = (SDL_Overlay*) frame->private;
+//	SDL_UnlockYUVOverlay (priv->current_frame);
+
+	if (SDL_LockYUVOverlay (priv->overlay)) {
+//		LOG (LOG_ERROR, "SDL video out: Couldn't lock SDL-based YUV overlay");
+		return -1;
+	}
+
+        switch(priv->format){
+        case IMGFMT_YV12:
+	    dst = (uint8_t *) *(priv->overlay->pixels);
+	    memcpy (dst, src[0], priv->framePlaneY);
+	    dst += priv->framePlaneY;
+	    memcpy (dst, src[2], priv->framePlaneUV);
+	    dst += priv->framePlaneUV;
+	    memcpy (dst, src[1], priv->framePlaneUV);
+            break;
+        case IMGFMT_YUY2:
+	    dst = (uint8_t *) *(priv->overlay->pixels);
+	    memcpy (dst, src[0], priv->width*priv->height*2);
+            break;
+        }
+        	
+	SDL_UnlockYUVOverlay (priv->overlay);
+
+	return 0;
+}
+
+
+/**
+ * Draw a slice (16 rows of image) to the SDL YUV overlay.
+ *
+ *   params : *src[] == the Y, U, and V planes that make up the slice.
+ *  returns : non-zero on error, zero on success.
+ **/
+
+//static uint32_t draw_slice(uint8_t *src[], uint32_t slice_num)
+static uint32_t draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y)
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+	uint8_t *dst;
+	uint8_t *src;
+        int i;
+
+	//priv->current_frame = priv->overlay;
+	
+	if (SDL_LockYUVOverlay (priv->overlay)) {
+//		LOG (LOG_ERROR, "SDL video out: Couldn't lock SDL-based YUV overlay");
+		return -1;
+	}
+
+	dst = (uint8_t *) *(priv->overlay->pixels) 
+            + (priv->stridePlaneY * y + x);
+        src = image[0];
+        for(i=0;i<h;i++){
+            memcpy(dst,src,w);
+            src+=stride[0];
+            dst+=priv->stridePlaneY;
+        }
+        
+        x/=2;y/=2;w/=2;h/=2;
+
+	dst = (uint8_t *) *(priv->overlay->pixels) + priv->framePlaneY
+            + (priv->stridePlaneUV * y + x);
+        src = image[2];
+        for(i=0;i<h;i++){
+            memcpy(dst,src,w);
+            src+=stride[2];
+            dst+=priv->stridePlaneUV;
+        }
+        
+	dst = (uint8_t *) *(priv->overlay->pixels) + priv->framePlaneY
+            + priv->framePlaneUV + (priv->stridePlaneUV * y + x);
+        src = image[1];
+        for(i=0;i<h;i++){
+            memcpy(dst,src,w);
+            src+=stride[1];
+            dst+=priv->stridePlaneUV;
+        }
+
+#if 0
+	dst = (uint8_t *) *(priv->overlay->pixels) + (priv->slicePlaneY * slice_num);
+	memcpy (dst, src[0], priv->slicePlaneY);
+	dst = (uint8_t *) *(priv->overlay->pixels) + priv->framePlaneY + (priv->slicePlaneUV * slice_num);
+	memcpy (dst, src[2], priv->slicePlaneUV);
+	dst += priv->framePlaneUV;
+	memcpy (dst, src[1], priv->slicePlaneUV);
+#endif
+	
+	SDL_UnlockYUVOverlay (priv->overlay);
+
+	return 0;
+}
+
+
+
+/**
+ * Checks for SDL keypress and window resize events
+ *
+ *   params : none
+ *  returns : doesn't return
+ **/
+
+#include "../linux/keycodes.h"
+extern void mplayer_put_key(int code);
+ 
+static void check_events (void)
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+	SDL_Event event;
+	SDLKey keypressed;
+	
+	/* Poll the waiting SDL Events */
+	while ( SDL_PollEvent(&event) ) {
+		switch (event.type) {
+
+			/* capture window resize events */
+			case SDL_VIDEORESIZE:
+				priv->surface = SDL_SetVideoMode(event.resize.w, event.resize.h, priv->bpp, priv->sdlflags);
+
+				/* save video extents, to restore them after going fullscreen */
+			 	//if(!(priv->surface->flags & SDL_FULLSCREEN)) {
+				    priv->windowsize.w = priv->surface->w;
+				    priv->windowsize.h = priv->surface->h;
+				//}
+//				LOG (LOG_DEBUG, "SDL video out: Window resize");
+			break;
+			
+			
+			/* graphics mode selection shortcuts */
+			case SDL_KEYDOWN:
+				keypressed = event.key.keysym.sym;
+				
+				/* plus key pressed. plus cycles through available fullscreenmodes, if we have some */
+				if ( ((keypressed == SDLK_PLUS) || (keypressed == SDLK_KP_PLUS)) && (priv->fullmodes) ) {
+					/* select next fullscreen mode */
+					priv->fullmode++;
+					if (priv->fullmode > (findArrayEnd(priv->fullmodes) - 1)) priv->fullmode = 0;
+					set_fullmode(priv->fullmode);
+	
+//					LOG (LOG_DEBUG, "SDL video out: Set next available fullscreen mode.");
+				}
+
+				/* return or escape key pressed toggles/exits fullscreenmode */
+				else if ( (keypressed == SDLK_RETURN) || (keypressed == SDLK_ESCAPE) ) {
+				 	if (priv->surface->flags & SDL_FULLSCREEN) {
+						priv->surface = SDL_SetVideoMode(priv->windowsize.w, priv->windowsize.h, priv->bpp, priv->sdlflags);
+						SDL_ShowCursor(1);
+						
+//						LOG (LOG_DEBUG, "SDL video out: Windowed mode");
+					} 
+					else if (priv->fullmodes){
+						set_fullmode(priv->fullmode);
+
+//						LOG (LOG_DEBUG, "SDL video out: Set fullscreen mode.");
+					}
+				}
+                                
+                                else switch(keypressed){
+//                                case SDLK_q: if(!(priv->surface->flags & SDL_FULLSCREEN))mplayer_put_key('q');break;
+                                case SDLK_q: mplayer_put_key('q');break;
+//                                case SDLK_p: mplayer_put_key('p');break;
+//                                case SDLK_SPACE: mplayer_put_key(' ');break;
+                                case SDLK_UP: mplayer_put_key(KEY_UP);break;
+                                case SDLK_DOWN: mplayer_put_key(KEY_DOWN);break;
+                                case SDLK_LEFT: mplayer_put_key(KEY_LEFT);break;
+                                case SDLK_RIGHT: mplayer_put_key(KEY_RIGHT);break;
+                                case SDLK_PLUS:
+                                case SDLK_KP_PLUS: mplayer_put_key('+');break;
+                                case SDLK_MINUS:
+                                case SDLK_KP_MINUS: mplayer_put_key('-');break;
+                                }
+                                
+				break;
+		}
+	}
+}
+
+
+/**
+ * Display the surface we have written our data to and check for events.
+ *
+ *   params : mode == index of the desired fullscreen mode
+ *  returns : doesn't return
+ **/
+
+static void flip_page (void)
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+
+	/* check and react on keypresses and window resizes */
+	check_events();
+
+	/* blit to the YUV overlay */
+	SDL_DisplayYUVOverlay (priv->overlay, &priv->surface->clip_rect);
+
+	/* check if we have a double buffered surface and flip() if we do. */
+	if ( priv->surface->flags & SDL_DOUBLEBUF )
+        	SDL_Flip(priv->surface);
+	
+	SDL_LockYUVOverlay (priv->overlay);
+}
+
+#if 0
+static frame_t* sdl_allocate_image_buffer(int width, int height)
+{
+	struct sdl_priv_s *priv = &sdl_priv;
+	frame_t	*frame;
+
+	if (!(frame = malloc (sizeof (frame_t))))
+		return NULL;
+
+	if (!(frame->private = (void*) SDL_CreateYUVOverlay (width, height, 
+			SDL_IYUV_OVERLAY, priv->surface)))
+	{
+//		LOG (LOG_ERROR, "SDL video out: Couldn't create an SDL-based YUV overlay");
+		return NULL;
+	}
+	
+	frame->base[0] = (uint8_t*) ((SDL_Overlay*) (frame->private))->pixels[0];
+	frame->base[1] = (uint8_t*) ((SDL_Overlay*) (frame->private))->pixels[1];
+	frame->base[2] = (uint8_t*) ((SDL_Overlay*) (frame->private))->pixels[2];
+	
+	SDL_LockYUVOverlay ((SDL_Overlay*) frame->private);
+	return frame;
+}
+
+static void sdl_free_image_buffer(frame_t* frame)
+{
+	SDL_FreeYUVOverlay((SDL_Overlay*) frame->private);
+	free(frame);
+}
+#endif
+
+static uint32_t
+query_format(uint32_t format)
+{
+    switch(format){
+    case IMGFMT_YV12:
+    case IMGFMT_YUY2:
+//    case IMGFMT_RGB|24:
+//    case IMGFMT_BGR|24:
+        return 1;
+    }
+    return 0;
+}
+
+static const vo_info_t*
+get_info(void)
+{
+	return &vo_info;
+}
+
+
+static void
+uninit(void)
+{
+sdl_close();
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/vo_syncfb.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,446 @@
+
+// How many MegaBytes of RAM is on your G200/G400 card?
+#define RAM_SIZE 16
+
+/* 
+ *    video_out_syncfb.c
+ *
+ *	Copyright (C) Aaron Holtzman - Aug 1999
+ *
+ *  This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *	
+ *  mpeg2dec 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, or (at your option)
+ *  any later version.
+ *   
+ *  mpeg2dec 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 GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+LIBVO_EXTERN(syncfb)
+
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <linux/videodev.h>
+
+#include "drivers/syncfb/syncfb.h"
+
+static vo_info_t vo_info =
+{
+	"Matrox G200/G400 Synchronous framebuffer (/dev/syncfb)",
+	"syncfb",
+	"Matthias Oelmann <mao@well.com>",
+	""
+};
+
+/* deinterlacing on? looks only good in 50 Hz(PAL) or 60 Hz(NTSC) modes */
+static int vo_conf_deinterlace = 0;
+
+/* 72/75 Hz Monitor frequency for progressive output */
+static int vo_conf_cinemode = 0;
+
+
+static syncfb_config_t config;
+static syncfb_capability_t sfb_caps;
+
+static syncfb_buffer_info_t bufinfo;
+
+static uint_8 *vid_data;
+static uint_8 *frame_mem;
+
+static int debug_skip_first = 250;
+static int dbg_singleframe = 0;
+
+static int conf_palette;
+
+static int f;
+
+
+
+/*
+	it seems that mpeg2dec never calls
+	draw_frame, so i could not test it....
+*/
+
+static void
+write_frame_YUV422(uint_8 *y,uint_8 *cr, uint_8 *cb)
+{
+	uint_8 *crp, *cbp;
+	uint_32 *dest32;
+	uint_32 bespitch,h,w;
+
+
+	bespitch = config.src_pitch;
+	dest32 = (uint_32 *)vid_data;
+
+	for(h=0; h < config.src_height/2; h++)
+	{
+		cbp = cb;
+		crp = cr;
+		for(w=0; w < config.src_width/2; w++)
+		{
+			*dest32++ = (*y) + ((*cr)<<8) + ((*(y+1))<<16) + ((*cb)<<24);
+			y++; y++; cb++; cr++;
+		}
+		dest32 += (bespitch - config.src_width) / 2;
+
+		for(w=0; w < config.src_width/2; w++)
+		{
+			*dest32++ = (*y) + ((*crp)<<8) + ((*(y+1))<<16) + ((*cbp)<<24);
+			y++; y++; cbp++; crp++;
+		}
+		dest32 += (bespitch - config.src_width) / 2;
+	}
+}
+
+
+static void
+write_frame_YUV420P2(uint_8 *y,uint_8 *cr, uint_8 *cb)
+{
+	uint_8 *dest, *tmp;
+	uint_32 bespitch,h,w;
+
+	bespitch = config.src_pitch;
+	dest = frame_mem + bufinfo.offset;
+
+	for(h=0; h < config.src_height; h++)
+	{
+		memcpy(dest, y, config.src_width);
+		y += config.src_width;
+		dest += bespitch;
+	}
+
+	dest = frame_mem + bufinfo.offset_p2;
+	for(h=0; h < config.src_height/2; h++)
+	{
+		tmp = dest;
+		for(w=0; w < config.src_width/2; w++)
+		{
+			*tmp++ =  *cr++;
+			*tmp++ =  *cb++;
+		}
+		dest += bespitch;
+	}
+}
+
+static void
+write_frame_YUV420P3(uint_8 *y,uint_8 *cr, uint_8 *cb)
+{
+}
+
+static void
+write_slice_YUV420P2(uint_8 *y,uint_8 *cr, uint_8 *cb,uint_32 slice_num)
+{
+	uint_8 *dest, *tmp;
+	uint_32 bespitch,h,w;
+
+	bespitch = config.src_pitch;
+	dest = frame_mem + bufinfo.offset + (bespitch * 16 * slice_num);
+
+	for(h=0; h < 16; h++)
+	{
+		memcpy(dest, y, config.src_width);
+		y += config.src_width;
+		dest += bespitch;
+	}
+
+	dest = frame_mem + bufinfo.offset_p2 + (bespitch * 16 * slice_num) /2;
+	for(h=0; h < 8; h++)
+	{
+		tmp = dest;
+		for(w=0; w < config.src_width/2; w++)
+		{
+			*tmp++ =  *cr++;
+			*tmp++ =  *cb++;
+		}
+		dest += bespitch;
+	}
+}
+
+static void
+write_slice_YUV420P3(uint_8 *y,uint_8 *cr, uint_8 *cb,int stride[],uint_32 ypos,uint_32 xsize,uint_32 ysize)
+{
+	uint_8 *dest;
+	uint_32 bespitch,h;
+
+	bespitch = config.src_pitch;
+
+	dest = frame_mem + bufinfo.offset + (bespitch * ypos);
+	for(h=0; h < ysize; h++)
+	{
+		memcpy(dest, y, xsize);
+		y += stride[0];
+		dest += bespitch;
+	}
+        
+        xsize/=2;
+        ysize/=2;
+
+	dest = frame_mem + bufinfo.offset_p2 + (bespitch * ypos)/4;
+	for(h=0; h < ysize; h++)
+	{
+		memcpy(dest, cr, xsize);
+		cr += stride[1];
+		dest += bespitch/2;
+	}
+
+	dest = frame_mem + bufinfo.offset_p3 + (bespitch * ypos)/4;
+	for(h=0; h < ysize; h++)
+	{
+		memcpy(dest, cb, xsize);
+		cb += stride[2];
+		dest += bespitch/2;
+	}
+
+
+}
+
+
+static void
+write_slice_YUV422(uint_8 *y,uint_8 *cr, uint_8 *cb,uint_32 slice_num)
+{
+	uint_8 *crp, *cbp;
+	uint_32 *dest32;
+	uint_32 bespitch,h,w;
+
+
+	bespitch = config.src_pitch;
+	dest32 = (uint_32 *)(vid_data + (bespitch * 16 * slice_num) * 2);
+
+	for(h=0; h < 8; h++)
+	{
+		cbp = cb;
+		crp = cr;
+		for(w=0; w < config.src_width/2; w++)
+		{
+			*dest32++ = (*y) + ((*cr)<<8) + ((*(y+1))<<16) + ((*cb)<<24);
+			y++; y++; cb++; cr++;
+		}
+		dest32 += (bespitch - config.src_width) / 2;
+
+		for(w=0; w < config.src_width/2; w++)
+		{
+			*dest32++ = (*y) + ((*crp)<<8) + ((*(y+1))<<16) + ((*cbp)<<24);
+			y++; y++; cbp++; crp++;
+		}
+		dest32 += (bespitch - config.src_width) / 2;
+	}
+}
+
+//static uint32_t draw_slice(uint8_t *src[], uint32_t slice_num)
+static uint32_t
+draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
+{
+
+    if ( vid_data == NULL ) return 0;
+
+    write_slice_YUV420P3(src[0],src[1], src[2],stride,y,w,h);
+
+    //printf("sorry, not syncfb/draw_slice() implemented yet...\n");
+
+#if 0
+
+	if ( conf_palette == VIDEO_PALETTE_YUV422 ) {
+		write_slice_YUV422(src[0],src[1], src[2],slice_num);
+	} else if ( conf_palette == VIDEO_PALETTE_YUV420P2 ) {
+		write_slice_YUV420P2(src[0],src[1], src[2],slice_num);
+	} else if ( conf_palette == VIDEO_PALETTE_YUV420P3 ) {
+		write_slice_YUV420P3(src[0],src[1], src[2],slice_num);
+	}
+#endif
+
+	return 0;
+}
+
+
+
+
+static void
+flip_page(void)
+{
+
+//	memset(frame_mem + bufinfo.offset_p2, 0x80, config.src_width*config.src_height);
+	ioctl(f,SYNCFB_COMMIT_BUFFER,&bufinfo);
+
+	if ( dbg_singleframe ) {
+		if ( debug_skip_first == 0 ) {
+			printf( "Press 'anykey' for field 1\n" );
+			getchar();
+			ioctl(f,SYNCFB_VBI,0);
+		}
+
+		if ( debug_skip_first > 0 ) {
+			debug_skip_first--;
+			// debug_skip_first = 0;
+			if ( debug_skip_first == 0 ) {
+			ioctl(f,SYNCFB_VBI,0);
+			ioctl(f,SYNCFB_VBI,0);
+			ioctl(f,SYNCFB_VBI,0);
+			}
+		}
+
+		if ( debug_skip_first == 0 ) {
+			printf( "Press 'anykey' for field 2\n" );
+			getchar();
+			ioctl(f,SYNCFB_VBI,0);
+		}
+	}
+
+	ioctl(f,SYNCFB_REQUEST_BUFFER,&bufinfo);
+	if ( bufinfo.id == -1 ) printf( "Got buffer #%d\n", bufinfo.id );
+
+	vid_data = (uint_8 *)(frame_mem + bufinfo.offset);
+	if ( bufinfo.id == -1 ) {
+		//vid_data = frame_mem;
+		vid_data = NULL;
+	}
+//	printf("Flip %d\n", bufinfo.offset);
+
+}
+
+static uint32_t draw_frame(uint8_t *src[])
+{
+	printf("DRAW FRAME!!!\n");
+	if ( conf_palette == VIDEO_PALETTE_YUV422 ) {
+		write_frame_YUV422(src[0],src[1], src[2]);
+	} else if ( conf_palette == VIDEO_PALETTE_YUV420P2 ) {
+		write_frame_YUV420P2(src[0],src[1], src[2]);
+	} else if ( conf_palette == VIDEO_PALETTE_YUV420P3 ) {
+		write_frame_YUV420P3(src[0],src[1], src[2]);
+	}
+
+	flip_page();
+	return 0;
+}
+
+static uint32_t
+query_format(uint32_t format)
+{
+    switch(format){
+    case IMGFMT_YV12:
+//    case IMGFMT_RGB|24:
+//    case IMGFMT_BGR|24:
+        return 1;
+    }
+    return 0;
+}
+
+static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
+{
+	uint_32 frame_size;
+
+	f = open("/dev/syncfb",O_RDWR);
+
+	if(f == -1)
+	{
+		f = open("/dev/mga_vid",O_RDWR);
+		if(f == -1)
+		{
+			fprintf(stderr,"Couldn't open /dev/syncfb or /dev/mga_vid\n");
+			return(-1);
+		}
+	}
+
+	if (ioctl(f,SYNCFB_GET_CAPS,&sfb_caps)) perror("Error in mga_vid_config ioctl");
+	if (ioctl(f,SYNCFB_GET_CONFIG,&config)) perror("Error in mga_vid_config ioctl");
+
+	if (sfb_caps.palettes & (1<<VIDEO_PALETTE_YUV420P3) ) {
+		config.src_palette= VIDEO_PALETTE_YUV420P3;
+		printf("using palette yuv420p3\n");
+	}else if ( sfb_caps.palettes & (1<<VIDEO_PALETTE_YUV420P2) ) {
+		config.src_palette= VIDEO_PALETTE_YUV420P2;
+		printf("using palette yuv420p2\n");
+	} else if ( sfb_caps.palettes & (1<<VIDEO_PALETTE_YUV422) ) {
+		config.src_palette= VIDEO_PALETTE_YUV422;
+		printf("using palette yuv422\n");
+	} else {
+		printf("no supported palette found\n");
+		exit(1);
+	}
+
+	// config.src_palette= VIDEO_PALETTE_YUV422;
+
+	if ( vo_conf_cinemode ) {
+		config.default_repeat = 3;
+	} else {
+		config.default_repeat = 2;
+	}
+
+	conf_palette = config.src_palette;
+	if ( vo_conf_deinterlace ) {
+		config.syncfb_mode = SYNCFB_FEATURE_SCALE | SYNCFB_FEATURE_BLOCK_REQUEST | SYNCFB_FEATURE_DEINTERLACE;
+		config.default_repeat = 1;
+	} else {
+		config.syncfb_mode = SYNCFB_FEATURE_SCALE | SYNCFB_FEATURE_BLOCK_REQUEST;
+	}
+
+	config.fb_screen_size = (RAM_SIZE-4)*0x100000; //(1280 * 1024 * 32) / 8;
+	config.src_width = width;
+	config.src_height= height;
+
+	config.image_width = d_width;
+	config.image_height= d_height;
+	//config.image_width = 1024;
+	//config.image_height= 576;
+
+	config.image_xorg= 0;
+	config.image_yorg= 0;
+
+
+	printf ("BES Sourcer size: %d x %d\n", width, height);
+
+	ioctl(f,SYNCFB_ON,0);
+	if (ioctl(f,SYNCFB_SET_CONFIG,&config)) perror("Error in mga_vid_config ioctl");
+
+	printf ("Framebuffer memory: %ld in %ld buffers\n", sfb_caps.memory_size, config.buffers);
+
+	frame_size = ((width + 31) & ~31) * height + (((width + 31) & ~31) * height) / 2;
+	frame_mem = (uint_8*)mmap(0,sfb_caps.memory_size,PROT_WRITE,MAP_SHARED,f,0);
+
+	printf( "Requesting first buffer #%d\n", bufinfo.id );
+	ioctl(f,SYNCFB_REQUEST_BUFFER,&bufinfo);
+	printf( "Got first buffer #%d\n", bufinfo.id );
+
+
+	vid_data = (uint_8 *)(frame_mem + bufinfo.offset);
+
+	//clear the buffer
+	// memset(frame_mem,0x80,frame_size*2);
+  	return 0;
+}
+
+static const vo_info_t*
+get_info(void)
+{
+	return &vo_info;
+}
+
+
+static void
+uninit(void)
+{
+	if (ioctl(f,SYNCFB_OFF,0)) perror("Error in OFF ioctl");
+
+}
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/vo_syncfb.c.OLD	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,434 @@
+/* 
+ *    video_out_syncfb.c
+ *
+ *	Copyright (C) Aaron Holtzman - Aug 1999
+ *
+ *  This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *	
+ *  mpeg2dec 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, or (at your option)
+ *  any later version.
+ *   
+ *  mpeg2dec 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 GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+LIBVO_EXTERN(syncfb)
+
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <linux/videodev.h>
+
+#include "drivers/syncfb.h"
+
+static vo_info_t vo_info =
+{
+	"Matrox G200/G400 Synchronous framebuffer (/dev/syncfb)",
+	"syncfb",
+	"Matthias Oelmann <mao@well.com>",
+	""
+};
+
+/* deinterlacing on? looks only good in 50 Hz(PAL) or 60 Hz(NTSC) modes */
+static int vo_conf_deinterlace = 1;
+
+/* 72/75 Hz Monitor frequency for progressive output */
+static int vo_conf_cinemode = 1;
+
+
+static syncfb_config_t config;
+static syncfb_capability_t sfb_caps;
+
+static syncfb_buffer_info_t bufinfo;
+
+static uint_8 *vid_data;
+static uint_8 *frame_mem;
+
+static int debug_skip_first = 250;
+static int dbg_singleframe = 0;
+
+static int conf_palette;
+
+static int f;
+
+
+
+/*
+	it seems that mpeg2dec never calls
+	draw_frame, so i could not test it....
+*/
+
+static void
+write_frame_YUV422(uint_8 *y,uint_8 *cr, uint_8 *cb)
+{
+	uint_8 *crp, *cbp;
+	uint_32 *dest32;
+	uint_32 bespitch,h,w;
+
+
+	bespitch = config.src_pitch;
+	dest32 = (uint_32 *)vid_data;
+
+	for(h=0; h < config.src_height/2; h++)
+	{
+		cbp = cb;
+		crp = cr;
+		for(w=0; w < config.src_width/2; w++)
+		{
+			*dest32++ = (*y) + ((*cr)<<8) + ((*(y+1))<<16) + ((*cb)<<24);
+			y++; y++; cb++; cr++;
+		}
+		dest32 += (bespitch - config.src_width) / 2;
+
+		for(w=0; w < config.src_width/2; w++)
+		{
+			*dest32++ = (*y) + ((*crp)<<8) + ((*(y+1))<<16) + ((*cbp)<<24);
+			y++; y++; cbp++; crp++;
+		}
+		dest32 += (bespitch - config.src_width) / 2;
+	}
+}
+
+
+static void
+write_frame_YUV420P2(uint_8 *y,uint_8 *cr, uint_8 *cb)
+{
+	uint_8 *dest, *tmp;
+	uint_32 bespitch,h,w;
+
+	bespitch = config.src_pitch;
+	dest = frame_mem + bufinfo.offset;
+
+	for(h=0; h < config.src_height; h++)
+	{
+		memcpy(dest, y, config.src_width);
+		y += config.src_width;
+		dest += bespitch;
+	}
+
+	dest = frame_mem + bufinfo.offset_p2;
+	for(h=0; h < config.src_height/2; h++)
+	{
+		tmp = dest;
+		for(w=0; w < config.src_width/2; w++)
+		{
+			*tmp++ =  *cr++;
+			*tmp++ =  *cb++;
+		}
+		dest += bespitch;
+	}
+}
+
+static void
+write_frame_YUV420P3(uint_8 *y,uint_8 *cr, uint_8 *cb)
+{
+}
+
+static void
+write_slice_YUV420P2(uint_8 *y,uint_8 *cr, uint_8 *cb,uint_32 slice_num)
+{
+	uint_8 *dest, *tmp;
+	uint_32 bespitch,h,w;
+
+	bespitch = config.src_pitch;
+	dest = frame_mem + bufinfo.offset + (bespitch * 16 * slice_num);
+
+	for(h=0; h < 16; h++)
+	{
+		memcpy(dest, y, config.src_width);
+		y += config.src_width;
+		dest += bespitch;
+	}
+
+	dest = frame_mem + bufinfo.offset_p2 + (bespitch * 16 * slice_num) /2;
+	for(h=0; h < 8; h++)
+	{
+		tmp = dest;
+		for(w=0; w < config.src_width/2; w++)
+		{
+			*tmp++ =  *cr++;
+			*tmp++ =  *cb++;
+		}
+		dest += bespitch;
+	}
+}
+
+static void
+write_slice_YUV420P3(uint_8 *y,uint_8 *cr, uint_8 *cb,uint_32 slice_num)
+{
+	uint_8 *dest;
+	uint_32 bespitch,h;
+
+	bespitch = config.src_pitch;
+	dest = frame_mem + bufinfo.offset + (bespitch * 16 * slice_num);
+
+	for(h=0; h < 16; h++)
+	{
+		memcpy(dest, y, config.src_width);
+		y += config.src_width;
+		dest += bespitch;
+	}
+
+	dest = frame_mem + bufinfo.offset_p2 + (bespitch * 16 * slice_num)/4;
+	for(h=0; h < 8; h++)
+	{
+		memcpy(dest, cr, config.src_width/2);
+		cr += config.src_width/2;
+		dest += bespitch/2;
+	}
+
+	dest = frame_mem + bufinfo.offset_p3 + (bespitch * 16 * slice_num)/4;
+	for(h=0; h < 8; h++)
+	{
+		memcpy(dest, cb, config.src_width/2);
+		cb += config.src_width/2;
+		dest += bespitch/2;
+	}
+
+
+}
+
+
+static void
+write_slice_YUV422(uint_8 *y,uint_8 *cr, uint_8 *cb,uint_32 slice_num)
+{
+	uint_8 *crp, *cbp;
+	uint_32 *dest32;
+	uint_32 bespitch,h,w;
+
+
+	bespitch = config.src_pitch;
+	dest32 = (uint_32 *)(vid_data + (bespitch * 16 * slice_num) * 2);
+
+	for(h=0; h < 8; h++)
+	{
+		cbp = cb;
+		crp = cr;
+		for(w=0; w < config.src_width/2; w++)
+		{
+			*dest32++ = (*y) + ((*cr)<<8) + ((*(y+1))<<16) + ((*cb)<<24);
+			y++; y++; cb++; cr++;
+		}
+		dest32 += (bespitch - config.src_width) / 2;
+
+		for(w=0; w < config.src_width/2; w++)
+		{
+			*dest32++ = (*y) + ((*crp)<<8) + ((*(y+1))<<16) + ((*cbp)<<24);
+			y++; y++; cbp++; crp++;
+		}
+		dest32 += (bespitch - config.src_width) / 2;
+	}
+}
+
+//static uint32_t draw_slice(uint8_t *src[], uint32_t slice_num)
+static uint32_t
+draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
+{
+
+    printf("sorry, not syncfb/draw_slice() implemented yet...\n");
+
+#if 0
+	if ( vid_data == NULL ) return 0;
+
+	if ( conf_palette == VIDEO_PALETTE_YUV422 ) {
+		write_slice_YUV422(src[0],src[1], src[2],slice_num);
+	} else if ( conf_palette == VIDEO_PALETTE_YUV420P2 ) {
+		write_slice_YUV420P2(src[0],src[1], src[2],slice_num);
+	} else if ( conf_palette == VIDEO_PALETTE_YUV420P3 ) {
+		write_slice_YUV420P3(src[0],src[1], src[2],slice_num);
+	}
+#endif
+
+	return 0;
+}
+
+
+
+
+static void
+flip_page(void)
+{
+
+//	memset(frame_mem + bufinfo.offset_p2, 0x80, config.src_width*config.src_height);
+	ioctl(f,SYNCFB_COMMIT_BUFFER,&bufinfo);
+
+	if ( dbg_singleframe ) {
+		if ( debug_skip_first == 0 ) {
+			printf( "Press 'anykey' for field 1\n" );
+			getchar();
+			ioctl(f,SYNCFB_VBI,0);
+		}
+
+		if ( debug_skip_first > 0 ) {
+			debug_skip_first--;
+			// debug_skip_first = 0;
+			if ( debug_skip_first == 0 ) {
+			ioctl(f,SYNCFB_VBI,0);
+			ioctl(f,SYNCFB_VBI,0);
+			ioctl(f,SYNCFB_VBI,0);
+			}
+		}
+
+		if ( debug_skip_first == 0 ) {
+			printf( "Press 'anykey' for field 2\n" );
+			getchar();
+			ioctl(f,SYNCFB_VBI,0);
+		}
+	}
+
+	ioctl(f,SYNCFB_REQUEST_BUFFER,&bufinfo);
+	if ( bufinfo.id == -1 ) printf( "Got buffer #%d\n", bufinfo.id );
+
+	vid_data = (uint_8 *)(frame_mem + bufinfo.offset);
+	if ( bufinfo.id == -1 ) {
+		//vid_data = frame_mem;
+		vid_data = NULL;
+	}
+//	printf("Flip %d\n", bufinfo.offset);
+
+}
+
+static uint32_t draw_frame(uint8_t *src[])
+{
+	printf("DRAW FRAME!!!\n");
+	if ( conf_palette == VIDEO_PALETTE_YUV422 ) {
+		write_frame_YUV422(src[0],src[1], src[2]);
+	} else if ( conf_palette == VIDEO_PALETTE_YUV420P2 ) {
+		write_frame_YUV420P2(src[0],src[1], src[2]);
+	} else if ( conf_palette == VIDEO_PALETTE_YUV420P3 ) {
+		write_frame_YUV420P3(src[0],src[1], src[2]);
+	}
+
+	flip_page();
+	return 0;
+}
+
+static uint32_t
+query_format(uint32_t format)
+{
+    switch(format){
+    case IMGFMT_YV12:
+//    case IMGFMT_RGB|24:
+//    case IMGFMT_BGR|24:
+        return 1;
+    }
+    return 0;
+}
+
+static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
+{
+	uint_32 frame_size;
+
+	f = open("/dev/syncfb",O_RDWR);
+
+	if(f == -1)
+	{
+		f = open("/dev/mga_vid",O_RDWR);
+		if(f == -1)
+		{
+			fprintf(stderr,"Couldn't open /dev/syncfb or /dev/mga_vid\n");
+			return(-1);
+		}
+	}
+
+	if (ioctl(f,SYNCFB_GET_CAPS,&sfb_caps)) perror("Error in mga_vid_config ioctl");
+	if (ioctl(f,SYNCFB_GET_CONFIG,&config)) perror("Error in mga_vid_config ioctl");
+
+	if (sfb_caps.palettes & (1<<VIDEO_PALETTE_YUV420P3) ) {
+		config.src_palette= VIDEO_PALETTE_YUV420P3;
+		printf("using palette yuv420p3\n");
+	}else if ( sfb_caps.palettes & (1<<VIDEO_PALETTE_YUV420P2) ) {
+		config.src_palette= VIDEO_PALETTE_YUV420P2;
+		printf("using palette yuv420p2\n");
+	} else if ( sfb_caps.palettes & (1<<VIDEO_PALETTE_YUV422) ) {
+		config.src_palette= VIDEO_PALETTE_YUV422;
+		printf("using palette yuv422\n");
+	} else {
+		printf("no supported palette found\n");
+		exit(1);
+	}
+
+	// config.src_palette= VIDEO_PALETTE_YUV422;
+
+	if ( vo_conf_cinemode ) {
+		config.default_repeat = 3;
+	} else {
+		config.default_repeat = 2;
+	}
+
+	conf_palette = config.src_palette;
+	if ( vo_conf_deinterlace ) {
+		config.syncfb_mode = SYNCFB_FEATURE_SCALE | SYNCFB_FEATURE_BLOCK_REQUEST | SYNCFB_FEATURE_DEINTERLACE;
+		config.default_repeat = 1;
+	} else {
+		config.syncfb_mode = SYNCFB_FEATURE_SCALE | SYNCFB_FEATURE_BLOCK_REQUEST;
+	}
+
+	config.fb_screen_size = (1280 * 1024 * 8) / 8;
+	config.src_width = width;
+	config.src_height= height;
+
+	config.image_width = width;
+	config.image_height= height; 
+	//config.image_width = 1024;
+	//config.image_height= 576;
+
+	config.image_xorg= 10;
+	config.image_yorg= 10;
+
+
+	printf ("BES Sourcer size: %d x %d\n", width, height);
+
+	ioctl(f,SYNCFB_ON,0);
+	if (ioctl(f,SYNCFB_SET_CONFIG,&config)) perror("Error in mga_vid_config ioctl");
+
+	printf ("Framebuffer memory: %ld in %ld buffers\n", sfb_caps.memory_size, config.buffers);
+
+	frame_size = ((width + 31) & ~31) * height + (((width + 31) & ~31) * height) / 2;
+	frame_mem = (uint_8*)mmap(0,sfb_caps.memory_size,PROT_WRITE,MAP_SHARED,f,0);
+
+	printf( "Requesting first buffer #%d\n", bufinfo.id );
+	ioctl(f,SYNCFB_REQUEST_BUFFER,&bufinfo);
+	printf( "Got first buffer #%d\n", bufinfo.id );
+
+
+	vid_data = (uint_8 *)(frame_mem + bufinfo.offset);
+
+	//clear the buffer
+	// memset(frame_mem,0x80,frame_size*2);
+  	return 0;
+}
+
+static const vo_info_t*
+get_info(void)
+{
+	return &vo_info;
+}
+
+
+static void
+uninit(void)
+{
+}
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/vo_x11.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,476 @@
+#define DISP
+
+/*
+ * video_out_x11.c,X11 interface
+ *
+ *
+ * Copyright ( C ) 1996,MPEG Software Simulation Group. All Rights Reserved.
+ *
+ * Hacked into mpeg2dec by
+ *
+ * Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * 15 & 16 bpp support added by Franck Sicard <Franck.Sicard@solsoft.fr>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+LIBVO_EXTERN( x11 )
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/XShm.h>
+#include <errno.h>
+#include "yuv2rgb.h"
+
+static vo_info_t vo_info =
+{
+        "X11 ( XImage/Shm )",
+        "x11",
+        "Aaron Holtzman <aholtzma@ess.engr.uvic.ca>",
+        ""
+};
+
+/* private prototypes */
+static void Display_Image ( XImage * myximage,unsigned char *ImageData );
+
+/* since it doesn't seem to be defined on some platforms */
+int XShmGetEventBase( Display* );
+
+/* local data */
+static unsigned char *ImageData;
+
+/* X11 related variables */
+static Display *mDisplay;
+static Window mywindow;
+static GC mygc;
+static XImage *myximage;
+static int depth,bpp,mode;
+static XWindowAttributes attribs;
+static int X_already_started=0;
+
+static int windowwidth,windowheight;
+
+#define SH_MEM
+
+#ifdef SH_MEM
+
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <X11/extensions/XShm.h>
+
+//static int HandleXError _ANSI_ARGS_( ( Display * dpy,XErrorEvent * event ) );
+static void InstallXErrorHandler ( void );
+static void DeInstallXErrorHandler ( void );
+
+static int Shmem_Flag;
+static int Quiet_Flag;
+static XShmSegmentInfo Shminfo[1];
+static int gXErrorFlag;
+static int CompletionType=-1;
+
+static void InstallXErrorHandler()
+{
+        //XSetErrorHandler( HandleXError );
+        XFlush( mDisplay );
+}
+
+static void DeInstallXErrorHandler()
+{
+        XSetErrorHandler( NULL );
+        XFlush( mDisplay );
+}
+
+#endif
+
+static uint32_t image_width;
+static uint32_t image_height;
+static uint32_t image_format;
+
+extern void vo_decoration( Display * vo_Display,Window w,int d );
+
+static Bool mEvents( Display * display,XEvent * Event,XPointer arg )
+{
+ int            i;
+ char           buf[100];
+ KeySym         keySym;
+ XComposeStatus stat;
+ unsigned long  vo_KeyTable[512];
+
+ switch( Event->type )
+  {
+   case ConfigureNotify:
+         windowwidth=Event->xconfigure.width;
+         windowheight=Event->xconfigure.height;
+         break;
+   case KeyPress:
+         XLookupString( &Event->xkey,buf,sizeof(buf),&keySym,&stat );
+         vo_keyboard( ( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ) );
+         break;
+  }
+ return 0;
+}
+
+static XEvent mEvent;
+
+static uint32_t init( uint32_t width,uint32_t height,uint32_t d_width,uint32_t d_height,uint32_t fullscreen,char *title,uint32_t format )
+{
+ int screen;
+ unsigned int fg,bg;
+ char *hello=( title == NULL ) ? "X11 render" : title;
+ char *name=":0.0";
+ XSizeHints hint;
+ XVisualInfo vinfo;
+ XEvent xev;
+ XGCValues xgcv;
+ Colormap theCmap;
+ XSetWindowAttributes xswa;
+ unsigned long xswamask;
+
+ image_height=height;
+ image_width=width;
+ image_format=format;
+
+ if ( X_already_started ) return -1;
+ if( !vo_init() ) return 0; // Can't open X11
+
+ if( getenv( "DISPLAY" ) ) name=getenv( "DISPLAY" );
+
+ mDisplay=XOpenDisplay( name );
+
+ if ( mDisplay == NULL )
+  {
+   fprintf( stderr,"Can not open display\n" );
+   return -1;
+  }
+
+ screen=DefaultScreen( mDisplay );
+
+ hint.x=0;
+ hint.y=0;
+ hint.width=image_width;
+ hint.height=image_height;
+ if ( fullscreen )
+  {
+   hint.width=vo_screenwidth;
+   hint.height=vo_screenheight;
+  }
+ windowwidth=hint.width;
+ windowheight=hint.height;
+ hint.flags=PPosition | PSize;
+
+ bg=WhitePixel( mDisplay,screen );
+ fg=BlackPixel( mDisplay,screen );
+
+ XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs );
+ depth=attribs.depth;
+
+ if ( depth != 15 && depth != 16 && depth != 24 && depth != 32 ) depth=24;
+ XMatchVisualInfo( mDisplay,screen,depth,TrueColor,&vinfo );
+
+ theCmap  =XCreateColormap( mDisplay,RootWindow( mDisplay,screen ),
+ vinfo.visual,AllocNone );
+
+ xswa.background_pixel=0;
+ xswa.border_pixel=1;
+ xswa.colormap=theCmap;
+ xswamask=CWBackPixel | CWBorderPixel |CWColormap;
+
+ mywindow=XCreateWindow( mDisplay,RootWindow( mDisplay,screen ),
+                         hint.x,hint.y,
+                         hint.width,hint.height,
+                         xswa.border_pixel,depth,CopyFromParent,vinfo.visual,xswamask,&xswa );
+
+ if ( fullscreen ) vo_decoration( mDisplay,mywindow,0 );
+ XSelectInput( mDisplay,mywindow,StructureNotifyMask );
+ XSetStandardProperties( mDisplay,mywindow,hello,hello,None,NULL,0,&hint );
+ XMapWindow( mDisplay,mywindow );
+ do { XNextEvent( mDisplay,&xev ); } while ( xev.type != MapNotify || xev.xmap.event != mywindow );
+
+ XSelectInput( mDisplay,mywindow,NoEventMask );
+
+ XFlush( mDisplay );
+ XSync( mDisplay,False );
+
+ mygc=XCreateGC( mDisplay,mywindow,0L,&xgcv );
+
+#ifdef SH_MEM
+ if ( XShmQueryExtension( mDisplay ) ) Shmem_Flag=1;
+  else
+   {
+    Shmem_Flag=0;
+    if ( !Quiet_Flag ) fprintf( stderr,"Shared memory not supported\nReverting to normal Xlib\n" );
+   }
+ if ( Shmem_Flag ) CompletionType=XShmGetEventBase( mDisplay ) + ShmCompletion;
+
+ InstallXErrorHandler();
+
+ if ( Shmem_Flag )
+  {
+   myximage=XShmCreateImage( mDisplay,vinfo.visual,depth,ZPixmap,NULL,&Shminfo[0],width,image_height );
+   if ( myximage == NULL )
+    {
+     if ( myximage != NULL ) XDestroyImage( myximage );
+     if ( !Quiet_Flag ) fprintf( stderr,"Shared memory error,disabling ( Ximage error )\n" );
+     goto shmemerror;
+    }
+   Shminfo[0].shmid=shmget( IPC_PRIVATE,
+   myximage->bytes_per_line * myximage->height ,
+   IPC_CREAT | 0777 );
+   if ( Shminfo[0].shmid < 0 )
+   {
+    XDestroyImage( myximage );
+    if ( !Quiet_Flag )
+     {
+      printf( "%s\n",strerror( errno ) );
+      perror( strerror( errno ) );
+      fprintf( stderr,"Shared memory error,disabling ( seg id error )\n" );
+     }
+    goto shmemerror;
+   }
+   Shminfo[0].shmaddr=( char * ) shmat( Shminfo[0].shmid,0,0 );
+
+   if ( Shminfo[0].shmaddr == ( ( char * ) -1 ) )
+   {
+    XDestroyImage( myximage );
+    if ( Shminfo[0].shmaddr != ( ( char * ) -1 ) ) shmdt( Shminfo[0].shmaddr );
+    if ( !Quiet_Flag ) fprintf( stderr,"Shared memory error,disabling ( address error )\n" );
+    goto shmemerror;
+   }
+   myximage->data=Shminfo[0].shmaddr;
+   ImageData=( unsigned char * ) myximage->data;
+   Shminfo[0].readOnly=False;
+   XShmAttach( mDisplay,&Shminfo[0] );
+
+   XSync( mDisplay,False );
+
+   if ( gXErrorFlag )
+   {
+    XDestroyImage( myximage );
+    shmdt( Shminfo[0].shmaddr );
+    if ( !Quiet_Flag ) fprintf( stderr,"Shared memory error,disabling.\n" );
+    gXErrorFlag=0;
+    goto shmemerror;
+   }
+   else
+    shmctl( Shminfo[0].shmid,IPC_RMID,0 );
+
+   if ( !Quiet_Flag ) fprintf( stderr,"Sharing memory.\n" );
+ }
+ else
+  {
+   shmemerror:
+   Shmem_Flag=0;
+#endif
+   myximage=XGetImage( mDisplay,mywindow,0,0,
+   width,image_height,AllPlanes,ZPixmap );
+   ImageData=myximage->data;
+#ifdef SH_MEM
+  }
+
+  DeInstallXErrorHandler();
+#endif
+
+  bpp=myximage->bits_per_pixel;
+
+  fprintf( stderr,"X11 color mask:  R:%X  G:%X  B:%X\n",myximage->red_mask,myximage->green_mask,myximage->blue_mask );
+
+  // If we have blue in the lowest bit then obviously RGB
+  mode=( ( myximage->blue_mask & 0x01 ) != 0 ) ? MODE_RGB : MODE_BGR;
+#ifdef WORDS_BIGENDIAN
+  if ( myximage->byte_order != MSBFirst )
+#else
+  if ( myximage->byte_order != LSBFirst )
+#endif
+  {
+   fprintf( stderr,"No support fon non-native XImage byte order!\n" );
+   return -1;
+  }
+
+ if( format==IMGFMT_YV12 ) yuv2rgb_init( ( depth == 24 ) ? bpp : depth,mode );
+
+ XSelectInput( mDisplay,mywindow,StructureNotifyMask | KeyPressMask );
+ X_already_started++;
+
+// vo_initthread( mThread );
+
+ if((vo_eventhandler_pid=fork())==0){
+   XIfEvent( mDisplay,&mEvent,mEvents,NULL ); 
+   exit(0);
+ }
+
+ return 0;
+}
+
+static const vo_info_t* get_info( void )
+{ return &vo_info; }
+
+static void Terminate_Display_Process( void )
+{
+ getchar();      /* wait for enter to remove window */
+#ifdef SH_MEM
+ if ( Shmem_Flag )
+  {
+   XShmDetach( mDisplay,&Shminfo[0] );
+   XDestroyImage( myximage );
+   shmdt( Shminfo[0].shmaddr );
+  }
+#endif
+ XDestroyWindow( mDisplay,mywindow );
+ XCloseDisplay( mDisplay );
+ X_already_started=0;
+}
+
+static void Display_Image( XImage *myximage,uint8_t *ImageData )
+{
+#ifdef DISP
+#ifdef SH_MEM
+ if ( Shmem_Flag )
+  {
+   XShmPutImage( mDisplay,mywindow,mygc,myximage,
+                 0,0,
+                 ( windowwidth - myximage->width ) / 2,( windowheight - myximage->height ) / 2,
+                 myximage->width,myximage->height,True );
+   XFlush( mDisplay );
+  }
+  else
+#endif
+   {
+    XPutImage( mDisplay,mywindow,mygc,myximage,
+               0,0,
+               ( windowwidth - myximage->width ) / 2,( windowheight - myximage->height ) / 2,
+               myximage->width,myximage->height );
+    XFlush( mDisplay );
+  }
+#endif
+}
+
+static void flip_page( void )
+{ Display_Image( myximage,ImageData ); }
+
+static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y )
+{
+ uint8_t *dst;
+
+ dst=ImageData + ( image_width * y + x ) * ( bpp/8 );
+ yuv2rgb( dst,src[0],src[1],src[2],w,h,image_width*( bpp/8 ),stride[0],stride[1] );
+ return 0;
+}
+
+void rgb15to16_mmx( char* s0,char* d0,int count );
+
+#if 1
+static uint32_t draw_frame( uint8_t *src[] )
+{
+ if( image_format==IMGFMT_YV12 )
+  {
+   yuv2rgb( ImageData,src[0],src[1],src[2],image_width,image_height,image_width*( bpp/8 ),image_width,image_width/2 );
+  }
+  else
+   {
+    int sbpp=( ( image_format&0xFF )+7 )/8;
+    int dbpp=( bpp+7 )/8;
+    char *d=ImageData;
+    char *s=src[0];
+    //printf( "sbpp=%d  dbpp=%d  depth=%d  bpp=%d\n",sbpp,dbpp,depth,bpp );
+#if 0
+    // flipped BGR
+    int i;
+    //printf( "Rendering flipped BGR frame  bpp=%d  src=%d  dst=%d\n",bpp,sbpp,dbpp );
+    s+=sbpp*image_width*image_height;
+    for( i=0;i<image_height;i++ )
+     {
+      s-=sbpp*image_width;
+      if( sbpp==dbpp ) memcpy( d,s,sbpp*image_width );
+       else
+        {
+         char *s2=s;
+         char *d2=d;
+         char *e=s2+sbpp*image_width;
+         while( s2<e )
+          {
+           d2[0]=s2[0];
+           d2[1]=s2[1];
+           d2[2]=s2[2];
+           s2+=sbpp;d2+=dbpp;
+          }
+        }
+      d+=dbpp*image_width;
+     }
+#else
+//   memcpy( ImageData,src[0],image_width*image_height*bpp );
+     if( sbpp==dbpp )
+      {
+       //Display_Image( myximage,s );return 0;
+#if 1
+       if( depth==16 && image_format==( IMGFMT_BGR|15 ) ){
+       // do 15bpp->16bpp
+#ifdef HAVE_MMX
+       rgb15to16_mmx( s,d,2*image_width*image_height );
+#else
+       unsigned short *s1=( unsigned short * )s;
+       unsigned short *d1=( unsigned short * )d;
+       unsigned short *e=s1+image_width*image_height;
+       while( s1<e )
+        {
+         register int x=*( s1++ );
+         // rrrrrggggggbbbbb
+         // 0rrrrrgggggbbbbb
+         // 0111 1111 1110 0000=0x7FE0
+         // 00000000000001 1111=0x001F
+         *( d1++ )=( x&0x001F )|( ( x&0x7FE0 )<<1 );
+        }
+#endif
+      }
+      else
+#endif
+       { memcpy( d,s,sbpp*image_width*image_height ); }
+   }
+   else
+    {
+     char *e=s+sbpp*image_width*image_height;
+     //printf( "libvo: using C 24->32bpp conversion\n" );
+     while( s<e )
+      {
+       d[0]=s[0];
+       d[1]=s[1];
+       d[2]=s[2];
+       s+=sbpp;d+=dbpp;
+      }
+   }
+#endif
+  }
+ //Display_Image( myximage,ImageData );
+ return 0;
+}
+#endif
+
+static uint32_t query_format( uint32_t format )
+{
+ if( !vo_init() ) return 0; // Can't open X11
+ if( ( format&IMGFMT_BGR_MASK )==IMGFMT_BGR && ( format&0xFF )==vo_depthonscreen ) return 1;
+ switch( format )
+  {
+   case IMGFMT_YV12: return 1;
+  }
+ return 0;
+}
+
+
+static void
+uninit(void)
+{
+printf("vo: uninit!\n");
+vo_kill_eventhandler();
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/vo_xmga.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,319 @@
+
+/*
+ *    video_out_xmga.c
+ *
+ *      Copyright (C) Zoltan Ponekker - Jan 2001
+ *
+ *  This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
+ *
+ *  mpeg2dec 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, or (at your option)
+ *  any later version.
+ *
+ *  mpeg2dec 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 GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+LIBVO_EXTERN( xmga )
+
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+#include "drivers/mga_vid.h"
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <errno.h>
+
+static vo_info_t vo_info =
+{
+ "X11 (Matrox G200/G400 overlay in window using /dev/mga_vid)",
+ "xmga",
+ "Zoltan Ponekker <pontscho@makacs.poliod.hu>",
+ ""
+};
+
+static mga_vid_config_t       mga_vid_config;
+static uint8_t              * vid_data;
+static uint8_t              * frame0;
+static uint8_t              * frame1;
+static int                    next_frame=0;
+static int                    f;
+
+static Display              * mDisplay;
+static Window                 mWindow;
+static GC                     mGC;
+static XGCValues              wGCV;
+
+static XImage               * myximage;
+
+static uint32_t               mDepth, bpp, mode;
+static XWindowAttributes      attribs;
+static uint32_t               X_already_started=0;
+
+static uint32_t               wndHeight;
+static uint32_t               wndWidth;
+static uint32_t               wndX;
+static uint32_t               wndY;
+
+static uint32_t               fgColor;
+
+static uint32_t               mvHeight;
+static uint32_t               mvWidth;
+
+static Window                 mRoot;
+static uint32_t               drwX,drwY,drwWidth,drwHeight,drwBorderWidth,drwDepth;
+static uint32_t               drwcX,drwcY,dwidth,dheight,mFullscreen;
+
+static XSetWindowAttributes   xWAttribs;
+
+#include "mga_common.c"
+
+
+static void mDrawColorKey( void )
+{
+ XClearWindow( mDisplay,mWindow );
+ XSetForeground( mDisplay,mGC,fgColor );
+ XFillRectangle( mDisplay,mWindow,mGC,drwX,drwY,drwWidth,(mFullscreen?drwHeight - 1:drwHeight) );
+ XFlush( mDisplay );
+}
+
+static Bool mEvents( Display * display,XEvent * Event,XPointer arg )
+{
+ int            i;
+ char           buf[100];
+ KeySym         keySym;
+ XComposeStatus stat;
+ unsigned long  vo_KeyTable[512];
+
+ switch( Event->type )
+  {
+   case Expose:
+         mDrawColorKey();
+         break;
+   case ConfigureNotify:
+         XGetGeometry( mDisplay,mWindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth );
+         drwX=0; drwY=0;
+         XTranslateCoordinates( mDisplay,mWindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
+         if ( mFullscreen )
+          {
+           drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2;
+           drwcX=drwX;
+           drwY=( vo_screenheight - (dheight > vo_screenheight?vo_screenheight:dheight) ) / 2;
+           drwcY=drwY;
+           drwWidth=(dwidth > vo_screenwidth?vo_screenwidth:dwidth);
+           drwHeight=(dheight > vo_screenheight?vo_screenheight:dheight);
+          }
+
+         mDrawColorKey();
+         mga_vid_config.x_org=drwcX;
+         mga_vid_config.y_org=drwcY;
+         mga_vid_config.dest_width=drwWidth;
+         mga_vid_config.dest_height=drwHeight;
+
+         fprintf( stderr,"[xmga] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
+
+         if ( ioctl( f,MGA_VID_CONFIG,&mga_vid_config ) )
+          {
+           fprintf( stderr,"Error in mga_vid_config ioctl" );
+           exit( 0 );
+          }
+         break;
+   case KeyPress:
+         XLookupString( &Event->xkey,buf,sizeof(buf),&keySym,&stat );
+         vo_keyboard( ( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ) );
+         break;
+  }
+ return 0;
+}
+
+static XEvent mEvent;
+
+static uint32_t init( uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format )
+{
+ char                 * frame_mem;
+ uint32_t               frame_size;
+ int                    mScreen;
+ unsigned int           fg, bg;
+ char                 * mTitle=(title == NULL) ? "XMGA render" : title;
+ char                 * name=":0.0";
+ XSizeHints             hint;
+ XVisualInfo            vinfo;
+ XEvent                 xev;
+
+ XGCValues              xgcv;
+ unsigned long          xswamask;
+
+ f=open( "/dev/mga_vid",O_RDWR );
+ if ( f == -1 )
+  {
+   fprintf(stderr,"Couldn't open /dev/mga_vid\n");
+   return(-1);
+  }
+
+ switch(format)
+  {
+   case IMGFMT_YV12: mga_vid_config.format=MGA_VID_FORMAT_YV12; break;
+   case IMGFMT_YUY2: mga_vid_config.format=MGA_VID_FORMAT_YUY2; break;
+   default:          fprintf(stderr,"mga: invalid output format %0X\n",format); return (-1);
+  }
+
+ if ( X_already_started ) return -1;
+
+ vo_init();
+
+ if ( getenv( "DISPLAY" ) ) name=getenv( "DISPLAY" );
+ mDisplay=XOpenDisplay(name);
+ if ( mDisplay == NULL )
+  {
+   fprintf( stderr,"Can not open display\n" );
+   return -1;
+  }
+
+ mScreen=DefaultScreen( mDisplay );
+
+ mvWidth=width; mvHeight=height;
+
+ wndX=0; wndY=0;
+ wndWidth=d_width; wndHeight=d_height;
+ dwidth=d_width; dheight=d_height;
+ mFullscreen=fullscreen;
+
+ if ( fullscreen )
+  {
+   wndWidth=vo_screenwidth;
+   wndHeight=vo_screenheight;
+  }
+
+ XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs );
+ mDepth=attribs.depth;
+ if ( mDepth != 15 && mDepth != 16 && mDepth != 24 && mDepth != 32 ) mDepth=24;
+ XMatchVisualInfo( mDisplay,mScreen,mDepth,TrueColor,&vinfo );
+ xWAttribs.colormap=XCreateColormap( mDisplay,RootWindow( mDisplay,mScreen ),vinfo.visual,AllocNone );
+ switch ( vo_depthonscreen )
+  {
+   case 32:
+   case 24: fgColor=0x00ff00ffL; break;
+   case 16: fgColor=0xf81fL; break;
+   case 15: fgColor=0x7c1fL; break;
+   default: fprintf( stderr,"Sorry, this (%d) color depth not supported.\n",vo_depthonscreen ); return -1;
+  }
+ xWAttribs.background_pixel=0;
+ xWAttribs.border_pixel=0;
+ xWAttribs.event_mask=StructureNotifyMask | ExposureMask | KeyPressMask;
+ xswamask=CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ mWindow=XCreateWindow( mDisplay,RootWindow( mDisplay,mScreen ),
+   wndX,wndY,
+   wndWidth,wndHeight,
+   xWAttribs.border_pixel,
+   mDepth,
+   InputOutput,
+   vinfo.visual,xswamask,&xWAttribs );
+
+ if ( fullscreen ) vo_decoration( mDisplay,mWindow,0 );
+
+ XGetNormalHints( mDisplay,mWindow,&hint );
+ hint.x=wndX; hint.y=wndY;
+ hint.width=wndWidth; hint.height=wndHeight;
+ hint.base_width=wndWidth; hint.base_height=wndHeight;
+ hint.flags=USPosition | USSize;
+ XSetNormalHints( mDisplay,mWindow,&hint );
+ XStoreName( mDisplay,mWindow,mTitle );
+
+ mGC=XCreateGC( mDisplay,mWindow,GCForeground,&wGCV );
+
+ XMapWindow( mDisplay,mWindow );
+
+ XGetGeometry( mDisplay,mWindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth );
+ drwX=0; drwY=0; drwWidth=wndWidth; drwHeight=wndHeight;
+ XTranslateCoordinates( mDisplay,mWindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
+
+ if ( fullscreen )
+  {
+   drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2;
+   drwcX=drwX;
+   drwY=( vo_screenheight - (dheight > vo_screenheight?vo_screenheight:dheight) ) / 2;
+   drwcY=drwY;
+   drwWidth=(dwidth > vo_screenwidth?vo_screenwidth:dwidth);
+   drwHeight=(dheight > vo_screenheight?vo_screenheight:dheight);
+  }
+
+ mDrawColorKey();
+
+ mga_vid_config.src_width=width;
+ mga_vid_config.src_height=height;
+ mga_vid_config.x_org=drwcX;
+ mga_vid_config.y_org=drwcY;
+ mga_vid_config.dest_width=drwWidth;
+ mga_vid_config.dest_height=drwHeight;
+
+ fprintf( stderr,"[xmga] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
+
+ mga_vid_config.colkey_on=1;
+ mga_vid_config.colkey_red=255;
+ mga_vid_config.colkey_green=0;
+ mga_vid_config.colkey_blue=255;
+
+#if 1
+ if ( ioctl( f,MGA_VID_CONFIG,&mga_vid_config ) )
+  {
+   fprintf( stderr,"Error in mga_vid_config ioctl" );
+   return -1;
+  }
+ ioctl( f,MGA_VID_ON,0 );
+#endif
+
+ frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2;
+ frame_mem=(char*)mmap( 0,frame_size*2,PROT_WRITE,MAP_SHARED,f,0 );
+ frame0=frame_mem;
+ frame1=frame_mem + frame_size;
+ vid_data=frame0;
+ next_frame=0;
+ memset( frame_mem,0x80,frame_size * 2 );
+
+ XFlush( mDisplay );
+ XSync( mDisplay,False );
+
+// vo_initthread( mThread );
+
+ if((vo_eventhandler_pid=fork())==0){
+   XIfEvent( mDisplay,&mEvent,mEvents,NULL ); 
+   exit(0);
+ }
+
+ return 0;
+}
+
+static const vo_info_t* get_info( void )
+{ return &vo_info; }
+
+
+static void
+uninit(void)
+{
+ ioctl( f,MGA_VID_OFF,0 );
+printf("vo: uninit!\n");
+vo_kill_eventhandler();
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/vo_xv.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,457 @@
+#define DISP
+
+/* 
+ * video_out_x11.c, X11 interface
+ *
+ *
+ * Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. 
+ *
+ * Hacked into mpeg2dec by
+ * 
+ * Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *
+ * 15 & 16 bpp support added by Franck Sicard <Franck.Sicard@solsoft.fr>
+ *
+ * Xv image suuport by Gerd Knorr <kraxel@goldbach.in-berlin.de>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "video_out_internal.h"
+
+LIBVO_EXTERN(xv)
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/XShm.h>
+#include <errno.h>
+#include "yuv2rgb.h"
+
+static vo_info_t vo_info = 
+{
+	"X11/Xv",
+	"xv",
+	"Gerd Knorr <kraxel@goldbach.in-berlin.de>",
+	""
+};
+
+/* since it doesn't seem to be defined on some platforms */
+int XShmGetEventBase(Display*);
+
+/* local data */
+static unsigned char *ImageData;
+
+/* X11 related variables */
+static Display *mydisplay;
+static Window mywindow;
+static GC mygc;
+static XImage *myximage;
+static int depth, bpp, mode;
+static XWindowAttributes attribs;
+
+#include <X11/extensions/Xv.h>
+#include <X11/extensions/Xvlib.h>
+// FIXME: dynamically allocate this stuff
+static void allocate_xvimage(int);
+static unsigned int ver,rel,req,ev,err;
+static unsigned int formats, adaptors,i,xv_port,xv_format;
+static int win_width,win_height;
+static XvAdaptorInfo        *ai;
+static XvImageFormatValues  *fo;
+static XvImage *xvimage[1];
+
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <X11/extensions/XShm.h>
+
+static int Shmem_Flag;
+static int Quiet_Flag;
+static XShmSegmentInfo Shminfo[1];
+static int gXErrorFlag;
+static int CompletionType = -1;
+
+static uint32_t image_width;
+static uint32_t image_height;
+static uint32_t image_format;
+
+static int get_depth(){
+	char *name = ":0.0";
+	if(getenv("DISPLAY")) name = getenv("DISPLAY");
+	mydisplay = XOpenDisplay(name);
+	if (mydisplay == NULL) return 0;
+	XGetWindowAttributes(mydisplay, DefaultRootWindow(mydisplay), &attribs);
+	depth = attribs.depth;
+	XCloseDisplay(mydisplay);
+
+    if (depth != 15 && depth != 16 && depth != 24 && depth != 32) depth = 24;
+    printf("X11 Display color depth = %d\n",depth);
+    return depth;
+}
+
+extern void vo_decoration( Display * vo_Display,Window w,int d );
+
+/* connect to server, create and map window,
+ * allocate colors and (shared) memory
+ */
+static uint32_t 
+init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
+{
+	int screen;
+//	unsigned int fg, bg;
+	char *hello = (title == NULL) ? "Xv rulez" : title;
+	char *name = ":0.0";
+	XSizeHints hint;
+	XVisualInfo vinfo;
+	XEvent xev;
+
+	XGCValues xgcv;
+	Colormap theCmap;
+	XSetWindowAttributes xswa;
+	unsigned long xswamask;
+
+	image_height = height;
+	image_width = width;
+        image_format=format;
+
+	if(getenv("DISPLAY"))
+		name = getenv("DISPLAY");
+
+	mydisplay = XOpenDisplay(name);
+
+	if (mydisplay == NULL)
+	{
+		fprintf(stderr,"Can't open display\n");
+		return -1;
+	}
+
+	screen = DefaultScreen(mydisplay);
+
+	hint.x = 0;
+	hint.y = 0;
+	hint.width = image_width;
+	hint.height = image_height;
+	hint.flags = PPosition | PSize;
+
+	/* Get some colors */
+
+//	bg = WhitePixel(mydisplay, screen);
+//	fg = BlackPixel(mydisplay, screen);
+
+	/* Make the window */
+
+	XGetWindowAttributes(mydisplay, DefaultRootWindow(mydisplay), &attribs);
+
+	/*
+	 *
+	 * depth in X11 terminology land is the number of bits used to
+	 * actually represent the colour.
+   	 *
+	 * bpp in X11 land means how many bits in the frame buffer per
+	 * pixel. 
+	 *
+	 * ex. 15 bit color is 15 bit depth and 16 bpp. Also 24 bit
+	 *     color is 24 bit depth, but can be 24 bpp or 32 bpp.
+	 */
+
+	depth = attribs.depth;
+
+	if (depth != 15 && depth != 16 && depth != 24 && depth != 32) 
+	{
+		/* The root window may be 8bit but there might still be
+		* visuals with other bit depths. For example this is the 
+		* case on Sun/Solaris machines.
+		*/
+		depth = 24;
+	}
+	//BEGIN HACK
+	//mywindow = XCreateSimpleWindow(mydisplay, DefaultRootWindow(mydisplay),
+	//hint.x, hint.y, hint.width, hint.height, 4, fg, bg);
+	//
+	XMatchVisualInfo(mydisplay, screen, depth, TrueColor, &vinfo);
+
+	theCmap   = XCreateColormap(mydisplay, RootWindow(mydisplay,screen), 
+	vinfo.visual, AllocNone);
+
+	xswa.background_pixel = 0;
+	xswa.border_pixel     = 1;
+	xswa.colormap         = theCmap;
+	xswamask = CWBackPixel | CWBorderPixel |CWColormap;
+
+
+	mywindow = XCreateWindow(mydisplay, RootWindow(mydisplay,screen),
+	hint.x, hint.y, hint.width, hint.height, 4, depth,CopyFromParent,vinfo.visual,xswamask,&xswa);
+
+	XSelectInput(mydisplay, mywindow, StructureNotifyMask);
+
+	/* Tell other applications about this window */
+
+	XSetStandardProperties(mydisplay, mywindow, hello, hello, None, NULL, 0, &hint);
+
+        if ( fullscreen ) vo_decoration( mydisplay,mywindow,0 );
+
+	/* Map window. */
+
+	XMapWindow(mydisplay, mywindow);
+
+	/* Wait for map. */
+	do 
+	{
+		XNextEvent(mydisplay, &xev);
+	}
+	while (xev.type != MapNotify || xev.xmap.event != mywindow);
+
+	XSelectInput(mydisplay, mywindow, NoEventMask);
+
+	XFlush(mydisplay);
+	XSync(mydisplay, False);
+
+	mygc = XCreateGC(mydisplay, mywindow, 0L, &xgcv);
+
+	xv_port = 0;
+	if (Success == XvQueryExtension(mydisplay,&ver,&rel,&req,&ev,&err)) 
+	{
+		/* check for Xvideo support */
+		if (Success != XvQueryAdaptors(mydisplay,DefaultRootWindow(mydisplay), &adaptors,&ai)) 
+		{
+			fprintf(stderr,"Xv: XvQueryAdaptors failed");
+			return -1;
+		}
+		/* check adaptors */
+		for (i = 0; i < adaptors; i++) 
+		{
+			if ((ai[i].type & XvInputMask) && (ai[i].type & XvImageMask) && (xv_port == 0)) 
+				xv_port = ai[i].base_id;
+		}
+		/* check image formats */
+		if (xv_port != 0) 
+		{
+			fo = XvListImageFormats(mydisplay, xv_port, (int*)&formats);
+                        xv_format=0;
+			for(i = 0; i < formats; i++) 
+			{
+				fprintf(stderr, "Xvideo image format: 0x%x (%4.4s) %s\n", fo[i].id, 
+						(char*)&fo[i].id, (fo[i].format == XvPacked) ? "packed" : "planar");
+
+				if (fo[i].id == format) 
+				{
+					xv_format = fo[i].id;
+//					break;
+				}
+			}
+			if (!xv_format) /* no matching image format not */
+				xv_port = 0;
+		}
+
+		if (xv_port != 0) 
+		{
+			fprintf(stderr,"using Xvideo port %d for hw scaling\n",
+			xv_port);
+
+			allocate_xvimage(0);
+
+			/* catch window resizes */
+                        XSelectInput(mydisplay, mywindow, StructureNotifyMask | KeyPressMask);
+//			XSelectInput(mydisplay, mywindow, StructureNotifyMask);
+			win_width  = image_width;
+			win_height = image_height;
+                        // resize:
+            XMoveResizeWindow(mydisplay,mywindow,0,0,d_width,d_height);
+
+			return 0;
+		}
+	}
+        
+        printf("Sorry, Xv not supported by this X11 version/driver\n");
+        printf("******** Try with  -vo x11  or  -vo sdl  *********\n");
+        return 1;
+
+}
+
+static const vo_info_t*
+get_info(void)
+{
+	return &vo_info;
+}
+
+static void
+allocate_xvimage(int foo)
+{
+	/* allocate XvImages.  FIXME: no error checking, without
+	 * mit-shm this will bomb... */
+	xvimage[foo] = XvShmCreateImage(mydisplay, xv_port, xv_format, 0, image_width, image_height, &Shminfo[foo]);
+			
+	Shminfo[foo].shmid    = shmget(IPC_PRIVATE, xvimage[foo]->data_size, IPC_CREAT | 0777);
+	Shminfo[foo].shmaddr  = (char *) shmat(Shminfo[foo].shmid, 0, 0);
+	Shminfo[foo].readOnly = False;
+			
+	xvimage[foo]->data = Shminfo[foo].shmaddr;
+	XShmAttach(mydisplay, &Shminfo[foo]);
+	XSync(mydisplay, False);
+	shmctl(Shminfo[foo].shmid, IPC_RMID, 0);
+
+	/* so we can do grayscale while testing... */
+	memset(xvimage[foo]->data,128,xvimage[foo]->data_size);
+
+	return;
+}
+
+#if 0
+static void
+check_events(void)
+{
+	Window root;
+	XEvent event;
+	int x, y;
+	unsigned int w, h, b, d;
+
+	if (XCheckWindowEvent(mydisplay, mywindow, StructureNotifyMask, &event))
+	{
+		XGetGeometry(mydisplay, mywindow, &root, &x, &y, &w, &h, &b, &d);
+		win_width  = w;
+		win_height = h;
+	}
+}
+#endif
+
+static void
+flip_page(void)
+{
+ int            i;
+ XEvent         Event;
+ char           buf[100];
+ KeySym         keySym;
+ XComposeStatus stat;
+ unsigned long  vo_KeyTable[512];
+
+ while ( XPending( mydisplay ) )
+  {
+   XNextEvent( mydisplay,&Event );
+   switch( Event.type )
+    {
+       case ConfigureNotify:
+             win_width = Event.xconfigure.width;
+             win_height = Event.xconfigure.height;
+             break;
+       case KeyPress:
+             XLookupString( &Event.xkey,buf,sizeof(buf),&keySym,&stat );
+             vo_keyboard( ( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ) );
+             break;
+    }
+  }
+
+//	check_events();
+
+#ifdef DISP
+	XvShmPutImage(mydisplay, xv_port, mywindow, mygc, xvimage[0],
+		0, 0,  image_width, image_height,
+		0, 0,  win_width, win_height,
+		False);
+	XFlush(mydisplay);
+#endif
+	return;
+}
+
+//draw_slice(uint8_t *src[], uint32_t slice_num)
+static uint32_t 
+draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y)
+{
+	uint8_t *src;
+	uint8_t *dst;
+        int i;
+
+	dst = xvimage[0]->data + image_width * y + x;
+        src = image[0];
+        if(w==stride[0] && w==image_width)
+            memcpy(dst,src,w*h);
+        else
+        for(i=0;i<h;i++){
+            memcpy(dst,src,w);
+            src+=stride[0];
+            dst+=image_width;
+        }
+        
+        x/=2;y/=2;w/=2;h/=2;
+        
+	dst = xvimage[0]->data + image_width * image_height + image_width/2 * y + x;
+        src = image[2];
+        if(w==stride[2] && w==image_width/2)
+            memcpy(dst,src,w*h);
+        else
+        for(i=0;i<h;i++){
+            memcpy(dst,src,w);
+            src+=stride[2];
+            dst+=image_width/2;
+        }
+
+	dst = xvimage[0]->data + image_width * image_height * 5 / 4 + image_width/2 * y + x;
+        src = image[1];
+        if(w==stride[1] && w==image_width/2)
+            memcpy(dst,src,w*h);
+        else
+        for(i=0;i<h;i++){
+            memcpy(dst,src,w);
+            src+=stride[1];
+            dst+=image_width/2;
+        }
+        
+	return 0;  
+}
+
+
+static uint32_t
+draw_frame(uint8_t *src[])
+{
+	int foo;
+
+//	check_events();
+
+        if(xv_format==IMGFMT_YUY2){
+          // YUY2 packed, flipped
+#if 0
+          int i;
+          unsigned short *s=(unsigned short *)src[0];
+          unsigned short *d=(unsigned short *)xvimage[0]->data;
+          s+=image_width*image_height;
+          for(i=0;i<image_height;i++){
+            s-=image_width;
+            memcpy(d,s,image_width*2);
+            d+=image_width;
+          }
+#else
+	  memcpy(xvimage[0]->data,src[0],image_width*image_height*2);
+#endif
+        } else {
+          // YV12 planar
+	  memcpy(xvimage[0]->data,src[0],image_width*image_height);
+	  memcpy(xvimage[0]->data+image_width*image_height,src[2],image_width*image_height/4);
+	  memcpy(xvimage[0]->data+image_width*image_height*5/4,src[1],image_width*image_height/4);
+        }
+	
+	return 0;  
+}
+
+static uint32_t
+query_format(uint32_t format)
+{
+    switch(format){
+    case IMGFMT_YV12:
+    case IMGFMT_YUY2:
+//    case IMGFMT_RGB|24:
+//    case IMGFMT_BGR|32:
+        return 1;
+    }
+    return 0;
+}
+
+static void
+uninit(void)
+{
+vo_kill_eventhandler();
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/wskeys.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,103 @@
+
+#ifndef _MY_WSKEY
+#define _MY_WSKEY
+
+#define wsosbrackets '['
+#define wscsbrackets ']'
+
+#define wsq 'q'
+#define wsa 'a'
+#define wsz 'z'
+#define wsw 'w'
+#define wss 's'
+#define wsx 'x'
+#define wse 'e'
+#define wsd 'd'
+#define wsr 'r'
+#define wsf 'f'
+#define wsv 'v'
+#define wst 't'
+#define wsg 'g'
+#define wsb 'b'
+#define wsy 'y'
+#define wsh 'h'
+#define wsn 'n'
+#define wsu 'u'
+#define wsj 'j'
+#define wsm 'm'
+#define wsi 'i'
+#define wsk 'k'
+#define wso 'o'
+#define wsl 'l'
+#define wsp 'p'
+
+#define wsQ 'Q'
+#define wsA 'A'
+#define wsZ 'Z'
+#define wsW 'W'
+#define wsS 'S'
+#define wsX 'X'
+#define wsE 'E'
+#define wsD 'D'
+#define wsR 'R'
+#define wsF 'F'
+#define wsV 'V'
+#define wsT 'T'
+#define wsG 'G'
+#define wsB 'B'
+#define wsY 'Y'
+#define wsH 'H'
+#define wsN 'N'
+#define wsU 'U'
+#define wsJ 'J'
+#define wsM 'M'
+#define wsI 'I'
+#define wsK 'K'
+#define wsO 'O'
+#define wsL 'L'
+#define wsP 'P'
+
+#define wsSpace ' '
+#define wsMinus '-'
+#define wsPlus  '+'
+
+#define wsUp            0x52 + 256
+#define wsDown          0x54 + 256
+#define wsLeft          0x51 + 256
+#define wsRight         0x53 + 256
+#define wsLeftCtrl      0xe3 + 256
+#define wsRightCtrl     0xe4 + 256
+#define wsLeftAlt       0xe9 + 256
+#define wsRightAlt      0x7e + 256
+#define wsLeftShift     0xe1 + 256
+#define wsRightShift    0xe2 + 256
+#define wsEnter         0x0d + 256
+#define wsBackSpace     0x08 + 256
+#define wsCapsLock      0xe5 + 256
+#define wsTab           0x09 + 256
+#define wsF1            0xbe + 256
+#define wsF2            0xbf + 256
+#define wsF3            0xc0 + 256
+#define wsF4            0xc1 + 256
+#define wsF5            0xc2 + 256
+#define wsF6            0xc3 + 256
+#define wsF7            0xc4 + 256
+#define wsF8            0xc5 + 256
+#define wsF9            0xc6 + 256
+#define wsF10           0xc7 + 256
+#define wsInsert        0x63 + 256
+#define wsDelete        0xff + 256
+#define wsHome          0x50 + 256
+#define wsEnd           0x57 + 256
+#define wsPageUp        0x55 + 256
+#define wsPageDown      0x56 + 256
+#define wsNumLock       0x7f + 256
+#define wsEscape        0x1b + 256
+#define wsGrayEnter     0x8d + 256
+#define wsGrayPlus      0xab + 256
+#define wsGrayMinus     0xad + 256
+#define wsGrayMul       0xaa + 256
+#define wsGrayDiv       0xaf + 256
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/yuv2rgb.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,414 @@
+/*
+ * yuv2rgb.c, Software YUV to RGB coverter
+ *
+ *  Copyright (C) 1999, Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *  All Rights Reserved.
+ *
+ *  Functions broken out from display_x11.c and several new modes
+ *  added by Håkan Hjort <d95hjort@dtek.chalmers.se>
+ *
+ *  15 & 16 bpp support by Franck Sicard <Franck.Sicard@solsoft.fr>
+ *
+ *  This file is part of mpeg2dec, a free MPEG-2 video decoder
+ *
+ *  mpeg2dec 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, or (at your option)
+ *  any later version.
+ *
+ *  mpeg2dec 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 GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "yuv2rgb.h"
+
+uint32_t matrix_coefficients = 6;
+
+const int32_t Inverse_Table_6_9[8][4] = {
+    {117504, 138453, 13954, 34903}, /* no sequence_display_extension */
+    {117504, 138453, 13954, 34903}, /* ITU-R Rec. 709 (1990) */
+    {104597, 132201, 25675, 53279}, /* unspecified */
+    {104597, 132201, 25675, 53279}, /* reserved */
+    {104448, 132798, 24759, 53109}, /* FCC */
+    {104597, 132201, 25675, 53279}, /* ITU-R Rec. 624-4 System B, G */
+    {104597, 132201, 25675, 53279}, /* SMPTE 170M */
+    {117579, 136230, 16907, 35559}  /* SMPTE 240M (1987) */
+};
+
+static void yuv2rgb_c_init (int bpp, int mode);
+
+yuv2rgb_fun yuv2rgb;
+
+static void (* yuv2rgb_c_internal) (uint8_t *, uint8_t *,
+				    uint8_t *, uint8_t *,
+				    void *, void *, int);
+
+static void yuv2rgb_c (void * dst, uint8_t * py, 
+		       uint8_t * pu, uint8_t * pv, 
+		       int h_size, int v_size, 
+		       int rgb_stride, int y_stride, int uv_stride) 
+{
+    v_size >>= 1;
+
+    while (v_size--) {
+	yuv2rgb_c_internal (py, py + y_stride, pu, pv, dst, dst + rgb_stride,
+			    h_size);
+
+	py += 2 * y_stride;
+	pu += uv_stride;
+	pv += uv_stride;
+	dst += 2 * rgb_stride;
+    }
+}
+
+void yuv2rgb_init (int bpp, int mode) 
+{
+    yuv2rgb = NULL;
+#ifdef HAVE_MMX
+    if (yuv2rgb == NULL /*&& (config.flags & VO_MMX_ENABLE)*/) {
+        yuv2rgb = yuv2rgb_init_mmx (bpp, mode);
+        if (yuv2rgb != NULL)
+            fprintf (stderr, "Using MMX for colorspace transform\n");
+        else
+            fprintf (stderr, "Cannot init MMX colorspace transform\n");
+    }
+#endif
+#ifdef HAVE_MLIB
+    if (yuv2rgb == NULL /*&& (config.flags & VO_MLIB_ENABLE)*/) {
+	yuv2rgb = yuv2rgb_init_mlib (bpp, mode);
+	if (yuv2rgb != NULL)
+	    fprintf (stderr, "Using mlib for colorspace transform\n");
+    }
+#endif
+    if (yuv2rgb == NULL) {
+	fprintf (stderr, "No accelerated colorspace conversion found\n");
+	yuv2rgb_c_init (bpp, mode);
+	yuv2rgb = (yuv2rgb_fun)yuv2rgb_c;
+    }
+}
+
+void * table_rV[256];
+void * table_gU[256];
+int table_gV[256];
+void * table_bU[256];
+
+#define RGB(i)					\
+	U = pu[i];				\
+	V = pv[i];				\
+	r = table_rV[V];			\
+	g = table_gU[U] + table_gV[V];		\
+	b = table_bU[U];
+
+#define DST1(i)					\
+	Y = py_1[2*i];				\
+	dst_1[2*i] = r[Y] + g[Y] + b[Y];	\
+	Y = py_1[2*i+1];			\
+	dst_1[2*i+1] = r[Y] + g[Y] + b[Y];
+
+#define DST2(i)					\
+	Y = py_2[2*i];				\
+	dst_2[2*i] = r[Y] + g[Y] + b[Y];	\
+	Y = py_2[2*i+1];			\
+	dst_2[2*i+1] = r[Y] + g[Y] + b[Y];
+
+#define DST1RGB(i)							\
+	Y = py_1[2*i];							\
+	dst_1[6*i] = r[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = b[Y];	\
+	Y = py_1[2*i+1];						\
+	dst_1[6*i+3] = r[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = b[Y];
+
+#define DST2RGB(i)							\
+	Y = py_2[2*i];							\
+	dst_2[6*i] = r[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = b[Y];	\
+	Y = py_2[2*i+1];						\
+	dst_2[6*i+3] = r[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = b[Y];
+
+#define DST1BGR(i)							\
+	Y = py_1[2*i];							\
+	dst_1[6*i] = b[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = r[Y];	\
+	Y = py_1[2*i+1];						\
+	dst_1[6*i+3] = b[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = r[Y];
+
+#define DST2BGR(i)							\
+	Y = py_2[2*i];							\
+	dst_2[6*i] = b[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = r[Y];	\
+	Y = py_2[2*i+1];						\
+	dst_2[6*i+3] = b[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = r[Y];
+
+static void yuv2rgb_c_32 (uint8_t * py_1, uint8_t * py_2,
+			  uint8_t * pu, uint8_t * pv,
+			  void * _dst_1, void * _dst_2, int h_size)
+{
+    int U, V, Y;
+    uint32_t * r, * g, * b;
+    uint32_t * dst_1, * dst_2;
+
+    h_size >>= 3;
+    dst_1 = _dst_1;
+    dst_2 = _dst_2;
+
+    while (h_size--) {
+	RGB(0);
+	DST1(0);
+	DST2(0);
+
+	RGB(1);
+	DST2(1);
+	DST1(1);
+
+	RGB(2);
+	DST1(2);
+	DST2(2);
+
+	RGB(3);
+	DST2(3);
+	DST1(3);
+
+	pu += 4;
+	pv += 4;
+	py_1 += 8;
+	py_2 += 8;
+	dst_1 += 8;
+	dst_2 += 8;
+    }
+}
+
+// This is very near from the yuv2rgb_c_32 code
+static void yuv2rgb_c_24_rgb (uint8_t * py_1, uint8_t * py_2,
+			      uint8_t * pu, uint8_t * pv,
+			      void * _dst_1, void * _dst_2, int h_size)
+{
+    int U, V, Y;
+    uint8_t * r, * g, * b;
+    uint8_t * dst_1, * dst_2;
+
+    h_size >>= 3;
+    dst_1 = _dst_1;
+    dst_2 = _dst_2;
+
+    while (h_size--) {
+	RGB(0);
+	DST1RGB(0);
+	DST2RGB(0);
+
+	RGB(1);
+	DST2RGB(1);
+	DST1RGB(1);
+
+	RGB(2);
+	DST1RGB(2);
+	DST2RGB(2);
+
+	RGB(3);
+	DST2RGB(3);
+	DST1RGB(3);
+
+	pu += 4;
+	pv += 4;
+	py_1 += 8;
+	py_2 += 8;
+	dst_1 += 24;
+	dst_2 += 24;
+    }
+}
+
+// only trivial mods from yuv2rgb_c_24_rgb
+static void yuv2rgb_c_24_bgr (uint8_t * py_1, uint8_t * py_2,
+			      uint8_t * pu, uint8_t * pv,
+			      void * _dst_1, void * _dst_2, int h_size)
+{
+    int U, V, Y;
+    uint8_t * r, * g, * b;
+    uint8_t * dst_1, * dst_2;
+
+    h_size >>= 3;
+    dst_1 = _dst_1;
+    dst_2 = _dst_2;
+
+    while (h_size--) {
+	RGB(0);
+	DST1BGR(0);
+	DST2BGR(0);
+
+	RGB(1);
+	DST2BGR(1);
+	DST1BGR(1);
+
+	RGB(2);
+	DST1BGR(2);
+	DST2BGR(2);
+
+	RGB(3);
+	DST2BGR(3);
+	DST1BGR(3);
+
+	pu += 4;
+	pv += 4;
+	py_1 += 8;
+	py_2 += 8;
+	dst_1 += 24;
+	dst_2 += 24;
+    }
+}
+
+// This is exactly the same code as yuv2rgb_c_32 except for the types of
+// r, g, b, dst_1, dst_2
+static void yuv2rgb_c_16 (uint8_t * py_1, uint8_t * py_2,
+			  uint8_t * pu, uint8_t * pv,
+			  void * _dst_1, void * _dst_2, int h_size)
+{
+    int U, V, Y;
+    uint16_t * r, * g, * b;
+    uint16_t * dst_1, * dst_2;
+
+    h_size >>= 3;
+    dst_1 = _dst_1;
+    dst_2 = _dst_2;
+
+    while (h_size--) {
+	RGB(0);
+	DST1(0);
+	DST2(0);
+
+	RGB(1);
+	DST2(1);
+	DST1(1);
+
+	RGB(2);
+	DST1(2);
+	DST2(2);
+
+	RGB(3);
+	DST2(3);
+	DST1(3);
+
+	pu += 4;
+	pv += 4;
+	py_1 += 8;
+	py_2 += 8;
+	dst_1 += 8;
+	dst_2 += 8;
+    }
+}
+
+static int div_round (int dividend, int divisor)
+{
+    if (dividend > 0)
+	return (dividend + (divisor>>1)) / divisor;
+    else
+	return -((-dividend + (divisor>>1)) / divisor);
+}
+
+static void yuv2rgb_c_init (int bpp, int mode)
+{  
+    int i;
+    uint8_t table_Y[1024];
+    uint32_t *table_32 = 0;
+    uint16_t *table_16 = 0;
+    uint8_t *table_8 = 0;
+    uint32_t entry_size = 0;
+    void *table_r = 0, *table_g = 0, *table_b = 0;
+
+    int crv = Inverse_Table_6_9[matrix_coefficients][0];
+    int cbu = Inverse_Table_6_9[matrix_coefficients][1];
+    int cgu = -Inverse_Table_6_9[matrix_coefficients][2];
+    int cgv = -Inverse_Table_6_9[matrix_coefficients][3];
+
+    for (i = 0; i < 1024; i++) {
+	int j;
+
+	j = (76309 * (i - 384 - 16) + 32768) >> 16;
+	j = (j < 0) ? 0 : ((j > 255) ? 255 : j);
+	table_Y[i] = j;
+    }
+
+    switch (bpp) {
+    case 32:
+	yuv2rgb_c_internal = yuv2rgb_c_32;
+
+	table_32 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t));
+
+	entry_size = sizeof (uint32_t);
+	table_r = table_32 + 197;
+	table_b = table_32 + 197 + 685;
+	table_g = table_32 + 197 + 2*682;
+
+	for (i = -197; i < 256+197; i++)
+	    ((uint32_t *)table_r)[i] = table_Y[i+384] << ((mode==MODE_RGB) ? 16 : 0);
+	for (i = -132; i < 256+132; i++)
+	    ((uint32_t *)table_g)[i] = table_Y[i+384] << 8;
+	for (i = -232; i < 256+232; i++)
+	    ((uint32_t *)table_b)[i] = table_Y[i+384] << ((mode==MODE_RGB) ? 0 : 16);
+	break;
+
+    case 24:
+//	yuv2rgb_c_internal = (mode==MODE_RGB) ? yuv2rgb_c_24_rgb : yuv2rgb_c_24_bgr;
+	yuv2rgb_c_internal = (mode!=MODE_RGB) ? yuv2rgb_c_24_rgb : yuv2rgb_c_24_bgr;
+
+	table_8 = malloc ((256 + 2*232) * sizeof (uint8_t));
+
+	entry_size = sizeof (uint8_t);
+	table_r = table_g = table_b = table_8 + 232;
+
+	for (i = -232; i < 256+232; i++)
+	    ((uint8_t * )table_b)[i] = table_Y[i+384];
+	break;
+
+    case 15:
+    case 16:
+	yuv2rgb_c_internal = yuv2rgb_c_16;
+
+	table_16 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t));
+
+	entry_size = sizeof (uint16_t);
+	table_r = table_16 + 197;
+	table_b = table_16 + 197 + 685;
+	table_g = table_16 + 197 + 2*682;
+
+	for (i = -197; i < 256+197; i++) {
+	    int j = table_Y[i+384] >> 3;
+
+	    if (mode == MODE_RGB)
+		j <<= ((bpp==16) ? 11 : 10);
+
+	    ((uint16_t *)table_r)[i] = j;
+	}
+	for (i = -132; i < 256+132; i++) {
+	    int j = table_Y[i+384] >> ((bpp==16) ? 2 : 3);
+
+	    ((uint16_t *)table_g)[i] = j << 5;
+	}
+	for (i = -232; i < 256+232; i++) {
+	    int j = table_Y[i+384] >> 3;
+
+	    if (mode == MODE_BGR)
+		j <<= ((bpp==16) ? 11 : 10);
+
+	    ((uint16_t *)table_b)[i] = j;
+	}
+	break;
+
+    default:
+	fprintf (stderr, "%ibpp not supported by yuv2rgb\n", bpp);
+	exit (1);
+    }
+
+    for (i = 0; i < 256; i++) {
+	table_rV[i] = table_r + entry_size * div_round (crv * (i-128), 76309);
+	table_gU[i] = table_g + entry_size * div_round (cgu * (i-128), 76309);
+	table_gV[i] = entry_size * div_round (cgv * (i-128), 76309);
+	table_bU[i] = table_b + entry_size * div_round (cbu * (i-128), 76309);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/yuv2rgb.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,43 @@
+/* 
+ *
+ *  yuv2rgb.h, Software YUV to RGB coverter
+ *
+ *
+ *  Copyright (C) 1999, Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
+ *  All Rights Reserved. 
+ * 
+ *  Functions broken out from display_x11.c and several new modes
+ *  added by Håkan Hjort <d95hjort@dtek.chalmers.se>
+ * 
+ *  15 & 16 bpp support by Franck Sicard <Franck.Sicard@solsoft.fr>
+ *
+ *  This file is part of mpeg2dec, a free MPEG-2 video decoder
+ *	
+ *  mpeg2dec 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, or (at your option)
+ *  any later version.
+ *   
+ *  mpeg2dec 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 GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
+ */
+
+#define MODE_RGB  0x1
+#define MODE_BGR  0x2
+
+typedef void (* yuv2rgb_fun) (uint8_t * image, uint8_t * py,
+			      uint8_t * pu, uint8_t * pv,
+			      int h_size, int v_size,
+			      int rgb_stride, int y_stride, int uv_stride);
+
+extern yuv2rgb_fun yuv2rgb;
+
+void yuv2rgb_init (int bpp, int mode);
+yuv2rgb_fun yuv2rgb_init_mmx (int bpp, int mode);
+yuv2rgb_fun yuv2rgb_init_mlib (int bpp, int mode);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/yuv2rgb_mlib.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,87 @@
+/* 
+ * yuv2rgb_mlib.c, Software YUV to RGB coverter using mediaLib
+ *
+ *  Copyright (C) 2000, Håkan Hjort <d95hjort@dtek.chalmers.se>
+ *  All Rights Reserved.
+ *
+ *  This file is part of mpeg2dec, a free MPEG-2 video decoder
+ *
+ *  mpeg2dec 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, or (at your option)
+ *  any later version.
+ *
+ *  mpeg2dec 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 GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "config.h"
+#include "video_out.h"
+#include "yuv2rgb.h"
+
+#include <mlib_types.h>
+#include <mlib_status.h>
+#include <mlib_sys.h>
+#include <mlib_video.h>
+
+static void mlib_YUV2ARGB420_32(uint8_t* image, const uint8_t* py, 
+			 const uint8_t* pu, const uint8_t* pv, 
+			 const uint32_t h_size, const uint32_t v_size, 
+			 const uint32_t rgb_stride, const uint32_t y_stride, 
+			 const uint32_t uv_stride)
+{
+  mlib_VideoColorYUV2ARGB420(image, py, pu, pv, h_size,
+			     v_size, rgb_stride, y_stride, uv_stride);
+}
+
+static void mlib_YUV2ABGR420_32(uint8_t* image, const uint8_t* py, 
+			 const uint8_t* pu, const uint8_t* pv, 
+			 const uint32_t h_size, const uint32_t v_size, 
+			 const uint32_t rgb_stride, const uint32_t y_stride, 
+			 const uint32_t uv_stride)
+{
+	mlib_VideoColorYUV2ABGR420(image, py, pu, pv, h_size,
+			     v_size, rgb_stride, y_stride, uv_stride);
+}
+
+static void mlib_YUV2RGB420_24(uint8_t* image, const uint8_t* py, 
+			 const uint8_t* pu, const uint8_t* pv, 
+			 const uint32_t h_size, const uint32_t v_size, 
+			 const uint32_t rgb_stride, const uint32_t y_stride, 
+			 const uint32_t uv_stride)
+{
+	mlib_VideoColorYUV2RGB420(image, py, pu, pv, h_size,
+			    v_size, rgb_stride, y_stride, uv_stride);
+}
+
+
+yuv2rgb_fun yuv2rgb_init_mlib(int bpp, int mode) 
+{  
+
+	if( bpp == 24 ) 
+	{
+		if( mode == MODE_RGB )
+			return mlib_YUV2RGB420_24;
+  }
+
+	if( bpp == 32 ) 
+	{
+		if( mode == MODE_RGB )
+			return mlib_YUV2ARGB420_32;
+		else if( mode == MODE_BGR )
+			return mlib_YUV2ABGR420_32;
+	}
+  
+	return NULL;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libvo/yuv2rgb_mmx.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,419 @@
+
+/*
+ * yuv2rgb_mmx.c, Software YUV to RGB coverter with Intel MMX "technology"
+ *
+ * Copyright (C) 2000, Silicon Integrated System Corp.
+ * All Rights Reserved.
+ *
+ * Author: Olie Lho <ollie@sis.com.tw>
+ *
+ * This file is part of mpeg2dec, a free MPEG-2 video decoder
+ *
+ * mpeg2dec 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, or (at your option)
+ * any later version.
+ *
+ * mpeg2dec 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 GNU Make; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "mmx.h"
+//#include "libmpeg2/mpeg2.h"
+//#include "libmpeg2/mpeg2_internal.h"
+#include <inttypes.h>
+
+#include "yuv2rgb.h"
+
+/* hope these constant values are cache line aligned */
+uint64_t mmx_80w = 0x0080008000800080;
+uint64_t mmx_10w = 0x1010101010101010;
+uint64_t mmx_00ffw = 0x00ff00ff00ff00ff;
+uint64_t mmx_Y_coeff = 0x253f253f253f253f;
+
+/* hope these constant values are cache line aligned */
+uint64_t mmx_U_green = 0xf37df37df37df37d;
+uint64_t mmx_U_blue = 0x4093409340934093;
+uint64_t mmx_V_red = 0x3312331233123312;
+uint64_t mmx_V_green = 0xe5fce5fce5fce5fc;
+
+/* hope these constant values are cache line aligned */
+uint64_t mmx_redmask = 0xf8f8f8f8f8f8f8f8;
+uint64_t mmx_grnmask = 0xfcfcfcfcfcfcfcfc;
+uint64_t mmx_grnshift = 0x03;
+uint64_t mmx_blueshift = 0x03;
+
+#if defined (HAVE_SSE) || defined (HAVE_3DNOW)
+#define movntq "movntq" // use this for processors that have SSE or 3Dnow
+#else
+#define movntq "movq" // for MMX-only processors
+#endif
+
+static void yuv420_rgb16_mmx (uint8_t * image, uint8_t * py,
+			      uint8_t * pu, uint8_t * pv,
+			      int h_size, int v_size,
+			      int rgb_stride, int y_stride, int uv_stride)
+{
+    int even = 1;
+    int x = 0, y = 0;
+
+    /* load data for first scan line */
+    __asm__ (
+	     "movd (%1), %%mm0 # Load 4 Cb 00 00 00 00 u3 u2 u1 u0\n\t"
+	     "movd (%2), %%mm1 # Load 4 Cr 00 00 00 00 v3 v2 v1 v0\n\t"
+
+	     "pxor %%mm4, %%mm4 # zero mm4\n\t"
+	     "movq (%0), %%mm6 # Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0\n\t"
+
+	     //"movl $0, (%3) # cache preload for image\n\t"
+	     : : "r" (py), "r" (pu), "r" (pv), "r" (image));
+
+    do {
+	do {
+	    /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8
+	       pixels in each iteration */
+	    __asm__ (".align 8 \n\t"
+		     /* Do the multiply part of the conversion for even and odd pixels,
+			register usage:
+			mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels,
+			mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels,
+			mm6 -> Y even, mm7 -> Y odd */
+		     /* convert the chroma part */
+		     "punpcklbw %%mm4, %%mm0 # scatter 4 Cb 00 u3 00 u2 00 u1 00 u0\n\t"
+		     "punpcklbw %%mm4, %%mm1 # scatter 4 Cr 00 v3 00 v2 00 v1 00 v0\n\t"
+
+		     "psubsw mmx_80w, %%mm0 # Cb -= 128\n\t"
+		     "psubsw mmx_80w, %%mm1 # Cr -= 128\n\t"
+
+		     "psllw $3, %%mm0 # Promote precision\n\t"
+		     "psllw $3, %%mm1 # Promote precision\n\t"
+
+		     "movq %%mm0, %%mm2 # Copy 4 Cb 00 u3 00 u2 00 u1 00 u0\n\t"
+		     "movq %%mm1, %%mm3 # Copy 4 Cr 00 v3 00 v2 00 v1 00 v0\n\t"
+
+		     "pmulhw mmx_U_green, %%mm2# Mul Cb with green coeff -> Cb green\n\t"
+		     "pmulhw mmx_V_green, %%mm3# Mul Cr with green coeff -> Cr green\n\t"
+
+		     "pmulhw mmx_U_blue, %%mm0 # Mul Cb -> Cblue 00 b3 00 b2 00 b1 00 b0\n\t"
+		     "pmulhw mmx_V_red, %%mm1 # Mul Cr -> Cred 00 r3 00 r2 00 r1 00 r0\n\t"
+
+		     "paddsw %%mm3, %%mm2 # Cb green + Cr green -> Cgreen\n\t"
+
+		     /* convert the luma part */
+		     "psubusb mmx_10w, %%mm6 # Y -= 16\n\t"
+
+		     "movq %%mm6, %%mm7 # Copy 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0\n\t"
+		     "pand mmx_00ffw, %%mm6 # get Y even 00 Y6 00 Y4 00 Y2 00 Y0\n\t"
+
+		     "psrlw $8, %%mm7 # get Y odd 00 Y7 00 Y5 00 Y3 00 Y1\n\t"
+
+		     "psllw $3, %%mm6 # Promote precision\n\t"
+		     "psllw $3, %%mm7 # Promote precision\n\t"
+
+		     "pmulhw mmx_Y_coeff, %%mm6# Mul 4 Y even 00 y6 00 y4 00 y2 00 y0\n\t"
+		     "pmulhw mmx_Y_coeff, %%mm7# Mul 4 Y odd 00 y7 00 y5 00 y3 00 y1\n\t"
+
+		     /* Do the addition part of the conversion for even and odd pixels,
+			register usage:
+			mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels,
+			mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels,
+			mm6 -> Y even, mm7 -> Y odd */
+		     "movq %%mm0, %%mm3 # Copy Cblue\n\t"
+		     "movq %%mm1, %%mm4 # Copy Cred\n\t"
+		     "movq %%mm2, %%mm5 # Copy Cgreen\n\t"
+
+		     "paddsw %%mm6, %%mm0 # Y even + Cblue 00 B6 00 B4 00 B2 00 B0\n\t"
+		     "paddsw %%mm7, %%mm3 # Y odd + Cblue 00 B7 00 B5 00 B3 00 B1\n\t"
+
+		     "paddsw %%mm6, %%mm1 # Y even + Cred 00 R6 00 R4 00 R2 00 R0\n\t"
+		     "paddsw %%mm7, %%mm4 # Y odd + Cred 00 R7 00 R5 00 R3 00 R1\n\t"
+
+		     "paddsw %%mm6, %%mm2 # Y even + Cgreen 00 G6 00 G4 00 G2 00 G0\n\t"
+		     "paddsw %%mm7, %%mm5 # Y odd + Cgreen 00 G7 00 G5 00 G3 00 G1\n\t"
+
+		     /* Limit RGB even to 0..255 */
+		     "packuswb %%mm0, %%mm0 # B6 B4 B2 B0 | B6 B4 B2 B0\n\t"
+		     "packuswb %%mm1, %%mm1 # R6 R4 R2 R0 | R6 R4 R2 R0\n\t"
+		     "packuswb %%mm2, %%mm2 # G6 G4 G2 G0 | G6 G4 G2 G0\n\t"
+
+		     /* Limit RGB odd to 0..255 */
+		     "packuswb %%mm3, %%mm3 # B7 B5 B3 B1 | B7 B5 B3 B1\n\t"
+		     "packuswb %%mm4, %%mm4 # R7 R5 R3 R1 | R7 R5 R3 R1\n\t"
+		     "packuswb %%mm5, %%mm5 # G7 G5 G3 G1 | G7 G5 G3 G1\n\t"
+
+		     /* Interleave RGB even and odd */
+		     "punpcklbw %%mm3, %%mm0 # B7 B6 B5 B4 B3 B2 B1 B0\n\t"
+		     "punpcklbw %%mm4, %%mm1 # R7 R6 R5 R4 R3 R2 R1 R0\n\t"
+		     "punpcklbw %%mm5, %%mm2 # G7 G6 G5 G4 G3 G2 G1 G0\n\t"
+
+		     /* mask unneeded bits off */
+		     "pand mmx_redmask, %%mm0# b7b6b5b4 b3_0_0_0 b7b6b5b4 b3_0_0_0\n\t"
+		     "pand mmx_grnmask, %%mm2# g7g6g5g4 g3g2_0_0 g7g6g5g4 g3g2_0_0\n\t"
+		     "pand mmx_redmask, %%mm1# r7r6r5r4 r3_0_0_0 r7r6r5r4 r3_0_0_0\n\t"
+
+		     "psrlw mmx_blueshift,%%mm0#0_0_0_b7 b6b5b4b3 0_0_0_b7 b6b5b4b3\n\t"
+		     "pxor %%mm4, %%mm4 # zero mm4\n\t"
+
+		     "movq %%mm0, %%mm5 # Copy B7-B0\n\t"
+		     "movq %%mm2, %%mm7 # Copy G7-G0\n\t"
+
+		     /* convert rgb24 plane to rgb16 pack for pixel 0-3 */
+		     "punpcklbw %%mm4, %%mm2 # 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0\n\t"
+		     "punpcklbw %%mm1, %%mm0 # r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3\n\t"
+
+		     "psllw mmx_blueshift,%%mm2# 0_0_0_0 0_g7g6g5 g4g3g2_0 0_0_0_0\n\t"
+		     "por %%mm2, %%mm0 # r7r6r5r4 r3g7g6g5 g4g3g2b7 b6b5b4b3\n\t"
+
+		     "movq 8 (%0), %%mm6 # Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0\n\t"
+		     movntq " %%mm0, (%3) # store pixel 0-3\n\t"
+
+		     /* convert rgb24 plane to rgb16 pack for pixel 0-3 */
+		     "punpckhbw %%mm4, %%mm7 # 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0\n\t"
+		     "punpckhbw %%mm1, %%mm5 # r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3\n\t"
+
+		     "psllw mmx_blueshift,%%mm7# 0_0_0_0 0_g7g6g5 g4g3g2_0 0_0_0_0\n\t"
+		     "movd 4 (%1), %%mm0 # Load 4 Cb 00 00 00 00 u3 u2 u1 u0\n\t"
+
+		     "por %%mm7, %%mm5 # r7r6r5r4 r3g7g6g5 g4g3g2b7 b6b5b4b3\n\t"
+		     "movd 4 (%2), %%mm1 # Load 4 Cr 00 00 00 00 v3 v2 v1 v0\n\t"
+
+		     movntq " %%mm5, 8 (%3) # store pixel 4-7\n\t"
+		     : : "r" (py), "r" (pu), "r" (pv), "r" (image));
+
+	    py += 8;
+	    pu += 4;
+	    pv += 4;
+	    image += 16;
+	    x += 8;
+	} while (x < h_size);
+
+	if (even) {
+	    pu -= h_size/2;
+	    pv -= h_size/2;
+	} else {
+	    pu += (uv_stride - h_size/2);
+	    pv += (uv_stride - h_size/2);
+	}
+
+	py += (y_stride - h_size);
+	image += (rgb_stride - 2*h_size);
+
+	/* load data for start of next scan line */
+	__asm__ (
+		 "movd (%1), %%mm0 # Load 4 Cb 00 00 00 00 00 u3 u2 u1 u0\n\t"
+		 "movd (%2), %%mm1 # Load 4 Cr 00 00 00 00 00 v2 v1 v0\n\t"
+
+		 //"movl $0, (%3) # cache preload for image\n\t"
+		 "movq (%0), %%mm6 # Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0\n\t"
+
+		 : : "r" (py), "r" (pu), "r" (pv), "r" (image));
+
+	x = 0;
+	y += 1;
+	even = (!even);
+    } while (y < v_size) ;
+
+    __asm__ ("emms\n\t");
+}
+
+static void yuv420_argb32_mmx (uint8_t * image, uint8_t * py,
+			       uint8_t * pu, uint8_t * pv,
+			       int h_size, int v_size,
+			       int rgb_stride, int y_stride, int uv_stride)
+{
+    int even = 1;
+    int x = 0, y = 0;
+
+    __asm__ (
+	     ".align 8 \n\t"
+	     "movd (%1), %%mm0 # Load 4 Cb 00 00 00 00 u3 u2 u1 u0\n\t"
+	     //"movl $0, (%3) # cache preload for image\n\t"
+
+	     "movd (%2), %%mm1 # Load 4 Cr 00 00 00 00 v3 v2 v1 v0\n\t"
+	     "pxor %%mm4, %%mm4 # zero mm4\n\t"
+
+	     "movq (%0), %%mm6 # Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0\n\t"
+	     : : "r" (py), "r" (pu), "r" (pv), "r" (image));
+
+    do {
+	do {
+	    /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8
+	       pixels in each iteration */
+	    __asm__ (
+		     ".align 8 \n\t"
+		     /* Do the multiply part of the conversion for even and odd pixels,
+			register usage:
+			mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels,
+			mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels,
+			mm6 -> Y even, mm7 -> Y odd */
+
+		     /* convert the chroma part */
+		     "punpcklbw %%mm4, %%mm0 # scatter 4 Cb 00 u3 00 u2 00 u1 00 u0\n\t"
+		     "punpcklbw %%mm4, %%mm1 # scatter 4 Cr 00 v3 00 v2 00 v1 00 v0\n\t"
+
+		     "psubsw mmx_80w, %%mm0 # Cb -= 128\n\t"
+		     "psubsw mmx_80w, %%mm1 # Cr -= 128\n\t"
+
+		     "psllw $3, %%mm0 # Promote precision\n\t"
+		     "psllw $3, %%mm1 # Promote precision\n\t"
+
+		     "movq %%mm0, %%mm2 # Copy 4 Cb 00 u3 00 u2 00 u1 00 u0\n\t"
+		     "movq %%mm1, %%mm3 # Copy 4 Cr 00 v3 00 v2 00 v1 00 v0\n\t"
+
+		     "pmulhw mmx_U_green, %%mm2# Mul Cb with green coeff -> Cb green\n\t"
+		     "pmulhw mmx_V_green, %%mm3# Mul Cr with green coeff -> Cr green\n\t"
+
+		     "pmulhw mmx_U_blue, %%mm0 # Mul Cb -> Cblue 00 b3 00 b2 00 b1 00 b0\n\t"
+		     "pmulhw mmx_V_red, %%mm1 # Mul Cr -> Cred 00 r3 00 r2 00 r1 00 r0\n\t"
+
+		     "paddsw %%mm3, %%mm2 # Cb green + Cr green -> Cgreen\n\t"
+
+		     /* convert the luma part */
+		     "psubusb mmx_10w, %%mm6 # Y -= 16\n\t"
+
+		     "movq %%mm6, %%mm7 # Copy 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0\n\t"
+		     "pand mmx_00ffw, %%mm6 # get Y even 00 Y6 00 Y4 00 Y2 00 Y0\n\t"
+
+		     "psrlw $8, %%mm7 # get Y odd 00 Y7 00 Y5 00 Y3 00 Y1\n\t"
+
+		     "psllw $3, %%mm6 # Promote precision\n\t"
+		     "psllw $3, %%mm7 # Promote precision\n\t"
+
+		     "pmulhw mmx_Y_coeff, %%mm6# Mul 4 Y even 00 y6 00 y4 00 y2 00 y0\n\t"
+		     "pmulhw mmx_Y_coeff, %%mm7# Mul 4 Y odd 00 y7 00 y5 00 y3 00 y1\n\t"
+
+		     /* Do the addition part of the conversion for even and odd pixels,
+			register usage:
+			mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels,
+			mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels,
+			mm6 -> Y even, mm7 -> Y odd */
+
+		     "movq %%mm0, %%mm3 # Copy Cblue\n\t"
+		     "movq %%mm1, %%mm4 # Copy Cred\n\t"
+		     "movq %%mm2, %%mm5 # Copy Cgreen\n\t"
+
+		     "paddsw %%mm6, %%mm0 # Y even + Cblue 00 B6 00 B4 00 B2 00 B0\n\t"
+		     "paddsw %%mm7, %%mm3 # Y odd + Cblue 00 B7 00 B5 00 B3 00 B1\n\t"
+
+		     "paddsw %%mm6, %%mm1 # Y even + Cred 00 R6 00 R4 00 R2 00 R0\n\t"
+		     "paddsw %%mm7, %%mm4 # Y odd + Cred 00 R7 00 R5 00 R3 00 R1\n\t"
+
+		     "paddsw %%mm6, %%mm2 # Y even + Cgreen 00 G6 00 G4 00 G2 00 G0\n\t"
+		     "paddsw %%mm7, %%mm5 # Y odd + Cgreen 00 G7 00 G5 00 G3 00 G1\n\t"
+
+		     /* Limit RGB even to 0..255 */
+		     "packuswb %%mm0, %%mm0 # B6 B4 B2 B0 B6 B4 B2 B0\n\t"
+		     "packuswb %%mm1, %%mm1 # R6 R4 R2 R0 R6 R4 R2 R0\n\t"
+		     "packuswb %%mm2, %%mm2 # G6 G4 G2 G0 G6 G4 G2 G0\n\t"
+
+		     /* Limit RGB odd to 0..255 */
+		     "packuswb %%mm3, %%mm3 # B7 B5 B3 B1 B7 B5 B3 B1\n\t"
+		     "packuswb %%mm4, %%mm4 # R7 R5 R3 R1 R7 R5 R3 R1\n\t"
+		     "packuswb %%mm5, %%mm5 # G7 G5 G3 G1 G7 G5 G3 G1\n\t"
+
+		     /* Interleave RGB even and odd */
+		     "punpcklbw %%mm3, %%mm0 # B7 B6 B5 B4 B3 B2 B1 B0\n\t"
+		     "punpcklbw %%mm4, %%mm1 # R7 R6 R5 R4 R3 R2 R1 R0\n\t"
+		     "punpcklbw %%mm5, %%mm2 # G7 G6 G5 G4 G3 G2 G1 G0\n\t"
+
+		     /* convert RGB plane to RGB packed format, 
+			mm0 -> B, mm1 -> R, mm2 -> G, mm3 -> 0,
+			mm4 -> GB, mm5 -> AR pixel 4-7,
+			mm6 -> GB, mm7 -> AR pixel 0-3 */
+		     "pxor %%mm3, %%mm3 # zero mm3\n\t"
+
+		     "movq %%mm0, %%mm6 # B7 B6 B5 B4 B3 B2 B1 B0\n\t"
+		     "movq %%mm1, %%mm7 # R7 R6 R5 R4 R3 R2 R1 R0\n\t"
+
+		     "movq %%mm0, %%mm4 # B7 B6 B5 B4 B3 B2 B1 B0\n\t"
+		     "movq %%mm1, %%mm5 # R7 R6 R5 R4 R3 R2 R1 R0\n\t"
+
+		     "punpcklbw %%mm2, %%mm6 # G3 B3 G2 B2 G1 B1 G0 B0\n\t"
+		     "punpcklbw %%mm3, %%mm7 # 00 R3 00 R2 00 R1 00 R0\n\t"
+
+		     "punpcklwd %%mm7, %%mm6 # 00 R1 B1 G1 00 R0 B0 G0\n\t"
+		     movntq " %%mm6, (%3) # Store ARGB1 ARGB0\n\t"
+
+		     "movq %%mm0, %%mm6 # B7 B6 B5 B4 B3 B2 B1 B0\n\t"
+		     "punpcklbw %%mm2, %%mm6 # G3 B3 G2 B2 G1 B1 G0 B0\n\t"
+
+		     "punpckhwd %%mm7, %%mm6 # 00 R3 G3 B3 00 R2 B3 G2\n\t"
+		     movntq " %%mm6, 8 (%3) # Store ARGB3 ARGB2\n\t"
+
+		     "punpckhbw %%mm2, %%mm4 # G7 B7 G6 B6 G5 B5 G4 B4\n\t"
+		     "punpckhbw %%mm3, %%mm5 # 00 R7 00 R6 00 R5 00 R4\n\t"
+				
+		     "punpcklwd %%mm5, %%mm4 # 00 R5 B5 G5 00 R4 B4 G4\n\t"
+		     movntq " %%mm4, 16 (%3) # Store ARGB5 ARGB4\n\t"
+
+		     "movq %%mm0, %%mm4 # B7 B6 B5 B4 B3 B2 B1 B0\n\t"
+		     "punpckhbw %%mm2, %%mm4 # G7 B7 G6 B6 G5 B5 G4 B4\n\t"
+
+		     "punpckhwd %%mm5, %%mm4 # 00 R7 G7 B7 00 R6 B6 G6\n\t"
+		     movntq " %%mm4, 24 (%3) # Store ARGB7 ARGB6\n\t"
+
+		     "movd 4 (%1), %%mm0 # Load 4 Cb 00 00 00 00 u3 u2 u1 u0\n\t"
+		     "movd 4 (%2), %%mm1 # Load 4 Cr 00 00 00 00 v3 v2 v1 v0\n\t"
+
+		     "pxor %%mm4, %%mm4 # zero mm4\n\t"
+		     "movq 8 (%0), %%mm6 # Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0\n\t"
+
+		     : : "r" (py), "r" (pu), "r" (pv), "r" (image));
+
+	    py += 8;
+	    pu += 4;
+	    pv += 4;
+	    image += 32;
+	    x += 8;
+	} while (x < h_size);
+
+	if (even) {
+	    pu -= h_size/2;
+	    pv -= h_size/2;
+	} else {
+	    pu += (uv_stride - h_size/2);
+	    pv += (uv_stride - h_size/2);
+	}
+
+	py += (y_stride - h_size);
+	image += (rgb_stride - 4*h_size);
+
+	/* load data for start of next scan line */
+	__asm__ 
+	    (
+	     ".align 8 \n\t"
+	     "movd (%1), %%mm0 # Load 4 Cb 00 00 00 00 u3 u2 u1 u0\n\t"
+	     "movd (%2), %%mm1 # Load 4 Cr 00 00 00 00 v3 v2 v1 v0\n\t"
+
+	     //"movl $0, (%3) # cache preload for image\n\t"
+	     "movq (%0), %%mm6 # Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0\n\t"
+	     : : "r" (py), "r" (pu), "r" (pv), "r" (image)
+	     );
+
+
+	x = 0;
+	y += 1;
+	even = (!even);
+    } while ( y < v_size) ;
+
+    __asm__ ("emms\n\t");
+}
+
+yuv2rgb_fun yuv2rgb_init_mmx (int bpp, int mode)
+{
+//    if (bpp == 15 || bpp == 16) {
+    if (bpp == 16 && mode == MODE_RGB) return yuv420_rgb16_mmx;
+    if (bpp == 32 && mode == MODE_RGB) return yuv420_argb32_mmx;
+    return NULL; // Fallback to C.
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/linux/getch2.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,215 @@
+/* GyS-TermIO v2.0 (for GySmail v3)          (C) 1999 A'rpi/ESP-team */
+
+#include "../config.h"
+
+//#define USE_TERMCAP
+#define USE_IOCTL
+
+#define MAX_KEYS 64
+#define BUF_LEN 256
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#ifdef USE_IOCTL
+#include <sys/ioctl.h>
+#endif
+#include <sys/termios.h>
+#include <unistd.h>
+
+#include "keycodes.h"
+
+static struct termios tio_orig;
+static int getch2_len=0;
+static char getch2_buf[BUF_LEN];
+
+int screen_width=80;
+int screen_height=24;
+
+typedef struct {
+  int len;
+  int code;
+  char chars[8];
+} keycode_st;
+static keycode_st getch2_keys[MAX_KEYS];
+static int getch2_key_db=0;
+
+#ifdef USE_TERMCAP
+
+#if 0
+#include <termcap.h>
+#else
+  extern int tgetent (char *BUFFER, char *TERMTYPE);
+  extern int tgetnum (char *NAME);
+  extern int tgetflag (char *NAME);
+  extern char *tgetstr (char *NAME, char **AREA);
+#endif
+
+static char term_buffer[4096];
+static char term_buffer2[4096];
+static char *term_p=term_buffer2;
+
+static void termcap_add(char *id,int code){
+char *p=tgetstr(id,&term_p);
+  if(!p) return;
+  if(getch2_key_db>=MAX_KEYS) return;
+  getch2_keys[getch2_key_db].len=strlen(p);
+  strncpy(getch2_keys[getch2_key_db].chars,p,8);
+  getch2_keys[getch2_key_db].code=code;
+  ++getch2_key_db;
+/*  printf("%s=%s\n",id,p); */
+}
+
+static int success=0;
+
+int load_termcap(char *termtype){
+  if(!termtype) termtype=getenv("TERM");
+  success=tgetent(term_buffer, termtype);
+  if(success<0){ printf("Could not access the 'termcap' data base.\n"); return 0; }
+  if(success==0){ printf("Terminal type `%s' is not defined.\n", termtype);return 0;}
+
+  screen_width=tgetnum("co");
+  screen_height=tgetnum("li");
+  if(screen_width<1 || screen_width>255) screen_width=80;
+  if(screen_height<1 || screen_height>255) screen_height=24;
+
+  termcap_add("kP",KEY_PGUP);
+  termcap_add("kN",KEY_PGDWN);
+  termcap_add("kh",KEY_HOME);
+  termcap_add("kH",KEY_END);
+  termcap_add("kI",KEY_INS);
+  termcap_add("kD",KEY_DEL);
+  termcap_add("kb",KEY_BS);
+  termcap_add("kl",KEY_LEFT);
+  termcap_add("kd",KEY_DOWN);
+  termcap_add("ku",KEY_UP);
+  termcap_add("kr",KEY_RIGHT);
+  termcap_add("k0",KEY_F+0);
+  termcap_add("k1",KEY_F+1);
+  termcap_add("k2",KEY_F+2);
+  termcap_add("k3",KEY_F+3);
+  termcap_add("k4",KEY_F+4);
+  termcap_add("k5",KEY_F+5);
+  termcap_add("k6",KEY_F+6);
+  termcap_add("k7",KEY_F+7);
+  termcap_add("k8",KEY_F+8);
+  termcap_add("k9",KEY_F+9);
+  termcap_add("k;",KEY_F+10);
+  return getch2_key_db;
+}
+
+#endif
+
+void get_screen_size(){
+#ifdef USE_IOCTL
+  struct winsize ws;
+  if (ioctl(0, TIOCGWINSZ, &ws) < 0 || !ws.ws_row || !ws.ws_col) return;
+/*  printf("Using IOCTL\n"); */
+  screen_width=ws.ws_col;
+  screen_height=ws.ws_row;
+#endif
+}
+
+int getch2(int time){
+  int len=0;
+  int code=0;
+  int i=0;
+
+  while(!getch2_len || (getch2_len==1 && getch2_buf[0]==27)){
+    fd_set rfds;
+    struct timeval tv;
+    int retval;
+    /* Watch stdin (fd 0) to see when it has input. */
+    FD_ZERO(&rfds); FD_SET(0,&rfds);
+    /* Wait up to 'time' microseconds. */
+    tv.tv_sec=time/1000; tv.tv_usec = (time%1000)*1000;
+    retval=select(1, &rfds, NULL, NULL, &tv);
+    if(!retval) return -1;
+    /* Data is available now. */
+    retval=read(0,&getch2_buf[getch2_len],BUF_LEN-getch2_len);
+    if(retval<1) return -1;
+    getch2_len+=retval;
+  }
+
+    /* First find in the TERMCAP database: */
+    for(i=0;i<getch2_key_db;i++){
+      if((len=getch2_keys[i].len)<=getch2_len)
+        if(memcmp(getch2_keys[i].chars,getch2_buf,len)==0){
+          code=getch2_keys[i].code; goto found;
+        }
+    }
+    len=1;code=getch2_buf[0];
+    /* Check the well-known codes... */
+    if(code!=27){
+      if(code=='A'-64){ code=KEY_HOME; goto found;}
+      if(code=='E'-64){ code=KEY_END; goto found;}
+      if(code=='D'-64){ code=KEY_DEL; goto found;}
+      if(code=='H'-64){ code=KEY_BS; goto found;}
+      if(code=='U'-64){ code=KEY_PGUP; goto found;}
+      if(code=='V'-64){ code=KEY_PGDWN; goto found;}
+      if(code==8 || code==127){ code=KEY_BS; goto found;}
+      if(code==10 || code==13){
+        if(getch2_len>1){
+          int c=getch2_buf[1];
+          if(c==10 || c==13) if(c!=code) len=2;
+        }
+        code=KEY_ENTER;
+        goto found;
+      }
+    } else if(getch2_len>1){
+      int c=getch2_buf[1];
+      if(c==27){ code=KEY_ESC; len=2; goto found;}
+      if(c>='0' && c<='9'){ code=c-'0'+KEY_F; len=2; goto found;}
+      if(getch2_len>=4 && c=='[' && getch2_buf[2]=='['){
+        int c=getch2_buf[3];
+        if(c>='A' && c<'A'+12){ code=KEY_F+1+c-'A';len=4;goto found;}
+      }
+      if(c=='[' || c=='O') if(getch2_len>=3){
+        int c=getch2_buf[2];
+        static short int ctable[]={ KEY_UP,KEY_DOWN,KEY_RIGHT,KEY_LEFT,0,
+                       KEY_END,KEY_PGDWN,KEY_HOME,KEY_PGUP,0,0,KEY_INS,0,0,0,
+                       KEY_F+1,KEY_F+2,KEY_F+3,KEY_F+4};
+        if(c>='A' && c<='S')
+          if(ctable[c-'A']){ code=ctable[c-'A']; len=3; goto found;}
+      }
+      if(getch2_len>=4 && c=='[' && getch2_buf[3]=='~'){
+        int c=getch2_buf[2];
+        int ctable[8]={KEY_HOME,KEY_INS,KEY_DEL,KEY_END,KEY_PGUP,KEY_PGDWN,KEY_HOME,KEY_END};
+        if(c>='1' && c<='8'){ code=ctable[c-'1']; len=4; goto found;}
+      }
+      if(getch2_len>=5 && c=='[' && getch2_buf[4]=='~'){
+        int i=getch2_buf[2]-'0';
+        int j=getch2_buf[3]-'0';
+        if(i>=0 && i<=9 && j>=0 && j<=9){
+          static short int ftable[20]={
+            11,12,13,14,15, 17,18,19,20,21,
+            23,24,25,26,28, 29,31,32,33,34 };
+          int a=i*10+j;
+          for(i=0;i<20;i++) if(ftable[i]==a){ code=KEY_F+1+i;len=5;goto found;}
+        }
+      }
+    }
+found:
+  if((getch2_len-=len)>0){
+    int i;
+    for(i=0;i<getch2_len;i++) getch2_buf[i]=getch2_buf[len+i];
+  }
+  return code;
+}
+
+void getch2_enable(){
+struct termios tio_new;
+    ioctl(0,TCGETS,&tio_orig); /*  tcgetattr(0,&tio_orig); */
+    tio_new=tio_orig;
+    tio_new.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */
+    tio_new.c_cc[VMIN] = 1;
+    tio_new.c_cc[VTIME] = 0;
+    ioctl(0,TCSETS,&tio_new); /*   tcsetattr(0,TCSANOW,&tio_new); */
+}
+
+void getch2_disable(){
+    ioctl(0,TCSETS,&tio_orig); /*   tcsetattr(0,TCSANOW,&tio_orig); */
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/linux/getch2.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,20 @@
+/* GyS-TermIO v2.0 (for GySmail v3)          (C) 1999 A'rpi/ESP-team */
+/* a very small replacement of ncurses library */
+
+/* Screen size. Initialized by load_termcap() and get_screen_size() */
+extern int screen_width;
+extern int screen_height;
+
+/* Get screen-size using IOCTL call. */
+extern void get_screen_size();
+
+/* Load key definitions from the TERMCAP database. 'termtype' can be NULL */
+extern int load_termcap(char *termtype);
+
+/* Enable and disable STDIN line-buffering */
+extern void getch2_enable();
+extern void getch2_disable();
+
+/* Read a character or a special key code (see keycodes.h) */
+extern int getch2(int halfdelay_time);
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/linux/keycodes.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,36 @@
+/*  KEY code definitions for GyS-TermIO v2.0  (C) 1999 A'rpi/ESP-team */
+
+#define KEY_ENTER 13
+#define KEY_TAB 9
+
+#define KEY_BASE 0x100
+
+/*  Function keys  */
+#define KEY_F (KEY_BASE+64)
+
+/* Control keys */
+#define KEY_CTRL (KEY_BASE)
+#define KEY_BACKSPACE (KEY_CTRL+0)
+#define KEY_DELETE (KEY_CTRL+1)
+#define KEY_INSERT (KEY_CTRL+2)
+#define KEY_HOME (KEY_CTRL+3)
+#define KEY_END (KEY_CTRL+4)
+#define KEY_PAGE_UP (KEY_CTRL+5)
+#define KEY_PAGE_DOWN (KEY_CTRL+6)
+#define KEY_ESC (KEY_CTRL+7)
+
+/* Control keys short name */
+#define KEY_BS KEY_BACKSPACE
+#define KEY_DEL KEY_DELETE
+#define KEY_INS KEY_INSERT
+#define KEY_PGUP KEY_PAGE_UP
+#define KEY_PGDOWN KEY_PAGE_DOWN
+#define KEY_PGDWN KEY_PAGE_DOWN
+
+/* Cursor movement */
+#define KEY_CRSR (KEY_BASE+16)
+#define KEY_RIGHT (KEY_CRSR+0)
+#define KEY_LEFT (KEY_CRSR+1)
+#define KEY_DOWN (KEY_CRSR+2)
+#define KEY_UP (KEY_CRSR+3)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/linux/shmem.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,83 @@
+/*
+ *   shmem.c - Shared memory allocation
+ *   
+ *   based on mpg123's xfermem.c by
+ *   Oliver Fromme  <oliver.fromme@heim3.tu-clausthal.de>
+ *   Sun Apr  6 02:26:26 MET DST 1997
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/uio.h>
+#include <sys/mman.h>
+#include <sys/socket.h>
+#include <fcntl.h>
+
+#ifdef AIX
+#include <sys/select.h>
+#endif
+
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+extern int errno;
+
+#if defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
+#define MAP_ANON MAP_ANONYMOUS
+#endif
+
+static int shmem_type=0;
+
+void* shmem_alloc(int size){
+void* p;
+int devzero;
+while(1){
+  switch(shmem_type){
+  case 0:  // ========= MAP_ANON|MAP_SHARED ==========
+    p=mmap(0,size,PROT_READ|PROT_WRITE,MAP_ANON|MAP_SHARED,-1,0);
+    if(p==MAP_FAILED) break; // failed
+    printf("shmem: %d bytes allocated using mmap anon (%X)\n",size,p);
+    return p;
+  case 1:  // ========= MAP_SHARED + /dev/zero ==========
+	  if ((devzero = open("/dev/zero", O_RDWR, 0)) == -1) break;
+    p=mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,devzero,0);
+    if(p==MAP_FAILED) break; // failed
+    printf("shmem: %d bytes allocated using mmap /dev/zero (%X)\n",size,p);
+    return p;
+  case 2: { // ========= shmget() ==========
+    struct shmid_ds shmemds;
+    int shmemid;
+    if ((shmemid = shmget(IPC_PRIVATE, size, IPC_CREAT | 0600)) == -1) break;
+    if ((int)(p = shmat(shmemid, 0, 0)) == -1){
+      perror ("shmat()");
+      shmctl (shmemid, IPC_RMID, &shmemds);
+      break;
+    }
+    if (shmctl(shmemid, IPC_RMID, &shmemds) == -1) {
+      perror ("shmctl()");
+      if (shmdt(p) == -1) perror ("shmdt()");
+      break;
+    }
+    printf("shmem: %d bytes allocated using shmget() & shmat() (%X)\n",size,p);
+    return p;
+	}
+  default:
+    printf("FATAL: Cannot alloate %d bytes shared memory :(\n",size);
+    return NULL;
+  }
+  ++shmem_type;
+}
+}
+
+void shmem_free(void* p){
+  switch(shmem_type){
+    case 2:
+	    if (shmdt(p) == -1) perror ("shmdt()");
+      break;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/linux/shmem.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,4 @@
+
+void* shmem_alloc(int size);
+void shmem_free(void* p);
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/linux/timer-lx.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,49 @@
+// Precise timer routines for LINUX  (C) LGB & A'rpi/ASTRAL
+
+#include <unistd.h>
+#include <sys/time.h>
+
+// Returns current time in seconds
+unsigned int GetTimer(){
+  struct timeval tv;
+  struct timezone tz;
+//  float s;
+  gettimeofday(&tv,&tz);
+//  s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
+  return (tv.tv_sec*1000000+tv.tv_usec);
+}  
+
+// Returns current time in microseconds
+int uGetTimer(){
+  struct timeval tv;
+  struct timezone tz;
+  gettimeofday(&tv,&tz);
+  return (int)(tv.tv_usec+1000000*tv.tv_sec);
+}  
+
+static unsigned int RelativeTime=0;
+
+// Returns time spent between now and last call in seconds
+float GetRelativeTime(){
+unsigned int t,r;
+  t=GetTimer();
+//  t*=16;printf("time=%ud\n",t);
+  r=t-RelativeTime;
+  RelativeTime=t;
+  return (float)r * 0.000001F;
+}
+
+// Initialize timer, must be called at least once at start
+void InitTimer(){
+  GetRelativeTime();
+}
+
+
+#if 0
+void main(){
+  float t=0;
+  InitTimer();
+  while(1){ t+=GetRelativeTime();printf("time= %10.6f\r",t);fflush(stdout); }
+}
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/linux/timer.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,6 @@
+
+void InitTimer();
+int GetTimer();
+//int uGetTimer();
+float GetRelativeTime();
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lirc_mp.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,143 @@
+/*
+
+ lirc support for MPLayer (see www.lirc.org)
+
+ v0.1
+ 
+ written 15/2/2001 by Andreas Ackermann (acki@acki-netz.de) 
+
+ file comes without warranty and all 
+
+*/
+
+// hack, will be remove later when ./configure fixed...
+#include "config.h"
+#ifdef HAVE_LIRC
+
+// start of LIRC support
+
+#include <lirc/lirc_client.h>
+#include <errno.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <string.h>
+#include <fcntl.h>
+#include "linux/keycodes.h"
+
+// global stuff ----------------------------------------------------
+
+static struct lirc_config *lirc_config;
+static int    lirc_is_setup = 0;
+
+// setup routine ---------------------------------------------------
+
+void lirc_mp_setup(void){
+
+  int lirc_flags;
+  int lirc_sock;
+
+  printf("Setting up lirc support...\n");
+  if((lirc_sock=lirc_init("mplayer_lirc",1))==-1){
+    printf("Failed opening lirc support!\n");
+    printf("You won't be able to use your remote control\n");
+    return;
+  }
+
+  fcntl(lirc_sock,F_SETOWN,getpid());
+  lirc_flags=fcntl(lirc_sock,F_GETFL,0);
+  if(lirc_flags!=-1)
+  {
+     fcntl(lirc_sock,F_SETFL,lirc_flags|O_NONBLOCK);
+  }else{
+    lirc_deinit();
+    printf("Something's wrong with the lirc socket: %s\n", 
+            strerror(errno));
+    printf("You won't be able to use your remote control\n");
+    return;
+  }
+
+
+  if(lirc_readconfig( NULL,&lirc_config,NULL )!=0 ){
+    printf("Failed to read standard config (~/.lircrc)!\n" );
+    printf("You won't be able to use your remote control\n");
+    lirc_deinit();
+    return;
+  }
+  printf("LIRC init was successful.\n");
+  lirc_is_setup = 1;
+}
+
+// cleanup routine -------------------------------------------
+
+void lirc_mp_cleanup(void){
+  if(lirc_is_setup != 0){
+    printf("Cleaning up lirc stuff.\n");
+    lirc_mp_getinput(NULL);
+    lirc_freeconfig(lirc_config);
+    lirc_deinit();
+    lirc_is_setup = 0;
+  }
+}
+
+// get some events -------------------------------------------
+
+
+struct lirc_cmd {
+  unsigned char *lc_lirccmd;
+  int mplayer_cmd;
+};
+
+int lirc_mp_getinput(){
+
+  static struct lirc_cmd lirc_cmd[] = {
+    {"QUIT", KEY_ESC},
+    {"FWD" , KEY_RIGHT},
+    {"FFWD" , KEY_UP},
+    {"RWND" , KEY_LEFT},
+    {"FRWND" , KEY_DOWN},
+    {"PAUSE", 'p'}    
+  };
+       
+  char *code;
+  char *c;
+  int ret;
+  int i;
+  int retval = 0;
+
+  if( lirc_is_setup == 0)return 0;
+  
+  if(lirc_config == NULL ){
+    // do some cleanupstuff like freeing memory or the like
+    // (if we ever should do it the right way and loop over all
+    // all strings delivered by lirc_code2char() )
+  }else{
+
+    if(lirc_nextcode(&code)==0){
+      if(code!=NULL){
+        // this should be a while loop 
+        // but we would have to introduce state since we need to keep 
+        // code
+        if((ret=lirc_code2char(lirc_config,code,&c))==0 && c!=NULL){
+          fprintf(stderr, "LIRC: Got string \"%s\"",c);
+          for(i=0; i< (sizeof(lirc_cmd)/sizeof(struct lirc_cmd)); i++){
+	    if(!(strcmp(lirc_cmd[i].lc_lirccmd, c))){
+              retval = lirc_cmd[i].mplayer_cmd;
+	      break;
+	    }
+
+          }
+        }
+        free(code);
+        if(ret==-1){ 
+           printf("LIRC: lirc_code2char() returned an error!\n");
+        }
+      }
+    }
+  }
+  return retval;
+}
+
+// end lirc support
+
+#endif // HAVE_LIRC
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lirc_mp.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,23 @@
+/*
+
+ definitions for LIRC support in mplayer
+ written in 2/2001 by Andreas Ackermann
+ acki@acki-netz.de
+
+*/
+
+#ifndef LIRC_MP_H_
+#define LIRC_MP_H_
+
+#include <lirc/lirc_client.h>
+
+//extern struct lirc_config *lirc_config;
+//extern int    lirc_is_setup;
+
+
+void lirc_mp_setup(void);
+void lirc_mp_cleanup(void);
+int  lirc_mp_getinput(void);
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/Makefile	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,30 @@
+include ../config.mak
+
+# Generated automatically from Makefile.in by configure.
+DEFINES=-rdynamic -fPIC $(WIN32_PATH) $(CDOPT) -D__WINE__ -Ddbg_printf=__vprintf \
+	-DTRACE=__vprintf
+# -DDETAILED_OUT
+
+LIB_OBJECTS= pe_image.o module.o \
+ext.o win32.o driver.o pe_resource.o \
+resource.o registry.o elfdll.o afl.o vfl.o
+
+CFLAGS=-g -I.
+
+CDOPT=-g
+all: libloader.a
+    
+clean:
+	-rm -f *.o libloader.a
+
+distclean: clean
+
+.c.o: $@
+	$(CC) $(CFLAGS) $(DEFINES) -c $<
+
+libloader.a:  $(LIB_OBJECTS) stubs.s
+	$(CC) -c ./stubs.s -o stubs.o
+	$(AR) -r libloader.a $(LIB_OBJECTS) stubs.o
+
+dep:
+	echo "dependency not required/supported"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/afl.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,763 @@
+/**************************************************************************
+
+
+  This file will contain an interface to ACM drivers.
+  Its content will be based mainly on wine/dlls/msacm32
+  actually, for audio decompression only the following functions
+  are needed:
+  
+  acmStreamOpen ( takes formats of src and dest, returns stream handle )
+  acmStreamPrepareHeader ( takes stream handler and info on data )
+  acmStreamConvert ( the same as PrepareHeader )
+  acmStreamUnprepareHeader
+  acmStreamClose
+  acmStreamSize
+  maybe acmStreamReset
+  
+  In future I'll also add functions for format enumeration, 
+  but not right now.
+
+  
+***************************************************************************/
+#include <config.h>
+
+#include <stdio.h>
+#include <string.h>
+
+#include <wine/winbase.h>
+#include <wine/windef.h>
+#include <wine/winuser.h>
+#include <wine/vfw.h>
+#include <wine/winestring.h>
+#include <wine/driver.h>
+#include <wine/winerror.h>
+#include <wine/msacm.h>
+#include <wine/msacmdrv.h>
+#include "wineacm.h"
+#pragma pack(1)
+#define OpenDriverA DrvOpen
+extern HDRVR VFWAPI DrvOpen(long);
+#define CloseDriver DrvClose
+extern HDRVR VFWAPI DrvClose(long);
+
+static PWINE_ACMSTREAM	ACM_GetStream(HACMSTREAM has)
+{
+    return (PWINE_ACMSTREAM)has;
+}
+
+/***********************************************************************
+ *           acmDriverAddA (MSACM32.2)
+ */
+MMRESULT WINAPI acmDriverAddA(PHACMDRIVERID phadid, HINSTANCE hinstModule,
+			      LPARAM lParam, DWORD dwPriority, DWORD fdwAdd)
+{
+    if (!phadid)
+	return MMSYSERR_INVALPARAM;
+    
+    /* Check if any unknown flags */
+    if (fdwAdd & 
+	~(ACM_DRIVERADDF_FUNCTION|ACM_DRIVERADDF_NOTIFYHWND|
+	  ACM_DRIVERADDF_GLOBAL))
+	return MMSYSERR_INVALFLAG;
+    
+    /* Check if any incompatible flags */
+    if ((fdwAdd & ACM_DRIVERADDF_FUNCTION) && 
+	(fdwAdd & ACM_DRIVERADDF_NOTIFYHWND))
+	return MMSYSERR_INVALFLAG;
+    
+    /* FIXME: in fact, should GetModuleFileName(hinstModule) and do a 
+     * LoadDriver on it, to be sure we can call SendDriverMessage on the
+     * hDrvr handle.
+     */
+    *phadid = (HACMDRIVERID) MSACM_RegisterDriver(NULL, NULL, hinstModule);
+    
+    /* FIXME: lParam, dwPriority and fdwAdd ignored */
+    
+    return MMSYSERR_NOERROR;
+}
+
+/***********************************************************************
+ *           acmDriverClose (MSACM32.4)
+ */
+MMRESULT WINAPI acmDriverClose(HACMDRIVER had, DWORD fdwClose)
+{
+    PWINE_ACMDRIVER  p;
+    PWINE_ACMDRIVER* tp;
+    
+    if (fdwClose)
+	return MMSYSERR_INVALFLAG;
+    
+    p = MSACM_GetDriver(had);
+    if (!p)
+	return MMSYSERR_INVALHANDLE;
+
+    for (tp = &(p->obj.pACMDriverID->pACMDriverList); *tp; *tp = (*tp)->pNextACMDriver) {
+	if (*tp == p) {
+	    *tp = (*tp)->pNextACMDriver;
+	    break;
+	}
+    }
+    
+    if (p->hDrvr && !p->obj.pACMDriverID->pACMDriverList)
+	CloseDriver(p->hDrvr);
+    
+    HeapFree(MSACM_hHeap, 0, p);
+    
+    return MMSYSERR_NOERROR;
+}
+
+/***********************************************************************
+ *           acmDriverEnum (MSACM32.7)
+ */
+MMRESULT WINAPI acmDriverEnum(ACMDRIVERENUMCB fnCallback, DWORD dwInstance, DWORD fdwEnum)
+{
+    PWINE_ACMDRIVERID	p;
+    DWORD		fdwSupport;
+
+    if (!fnCallback) {
+	return MMSYSERR_INVALPARAM;
+    }
+    
+    if (fdwEnum && ~(ACM_DRIVERENUMF_NOLOCAL|ACM_DRIVERENUMF_DISABLED)) {
+	return MMSYSERR_INVALFLAG;
+    }
+    
+    for (p = MSACM_pFirstACMDriverID; p; p = p->pNextACMDriverID) {
+	fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CODEC;
+	if (!p->bEnabled) {
+	    if (fdwEnum & ACM_DRIVERENUMF_DISABLED)
+		fdwSupport |= ACMDRIVERDETAILS_SUPPORTF_DISABLED;
+	    else
+		continue;
+	}
+	(*fnCallback)((HACMDRIVERID) p, dwInstance, fdwSupport);
+    }
+    
+    return MMSYSERR_NOERROR;
+}
+
+/***********************************************************************
+ *           acmDriverID (MSACM32.8)
+ */
+MMRESULT WINAPI acmDriverID(HACMOBJ hao, PHACMDRIVERID phadid, DWORD fdwDriverID)
+{
+    PWINE_ACMOBJ pao;
+    
+    pao = MSACM_GetObj(hao);
+    if (!pao)
+	return MMSYSERR_INVALHANDLE;
+    
+    if (!phadid)
+	return MMSYSERR_INVALPARAM;
+    
+    if (fdwDriverID)
+	return MMSYSERR_INVALFLAG;
+    
+    *phadid = (HACMDRIVERID) pao->pACMDriverID;
+    
+    return MMSYSERR_NOERROR;
+}
+
+/***********************************************************************
+ *           acmDriverMessage (MSACM32.9)
+ * FIXME
+ *   Not implemented
+ */
+LRESULT WINAPI acmDriverMessage(HACMDRIVER had, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
+{
+    PWINE_ACMDRIVER pad = MSACM_GetDriver(had);
+    if (!pad)
+	return MMSYSERR_INVALPARAM;
+    
+    /* FIXME: Check if uMsg legal */
+    
+    if (!SendDriverMessage(pad->hDrvr, uMsg, lParam1, lParam2))
+	return MMSYSERR_NOTSUPPORTED;
+    
+    return MMSYSERR_NOERROR;
+}
+
+
+/***********************************************************************
+ *           acmDriverOpen (MSACM32.10)
+ */
+MMRESULT WINAPI acmDriverOpen(PHACMDRIVER phad, HACMDRIVERID hadid, DWORD fdwOpen)
+{
+    PWINE_ACMDRIVERID	padid;
+    PWINE_ACMDRIVER	pad;
+    ICOPEN		icopen;
+    HDRVR		hdrv;
+
+
+
+    TRACE("(%p, %x, %08lu)\n", phad, hadid, fdwOpen);
+
+    if (!phad)
+	return MMSYSERR_INVALPARAM;
+    
+    padid = MSACM_GetDriverID(hadid); 
+    if (!padid)
+	return MMSYSERR_INVALHANDLE;
+    
+    if (fdwOpen)
+	return MMSYSERR_INVALFLAG;
+    
+    pad = HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMDRIVER));
+    if (!pad) return MMSYSERR_NOMEM;
+
+    pad->obj.pACMDriverID = padid;
+    icopen.fccType		= mmioFOURCC('a', 'u', 'd', 'c');
+    icopen.fccHandler		= (long)padid->pszFileName;
+    icopen.dwSize		= sizeof(ICOPEN);
+    icopen.dwFlags		= 0;
+
+   if (!padid->hInstModule)
+	pad->hDrvr = OpenDriverA((long)&icopen);
+    else
+	pad->hDrvr = padid->hInstModule;
+    
+    if (!pad->hDrvr) {
+	HeapFree(MSACM_hHeap, 0, pad);
+	return MMSYSERR_ERROR;
+    }
+    
+    pad->pfnDriverProc = GetProcAddress(pad->hDrvr, "DriverProc");
+
+    /* insert new pad at beg of list */
+    pad->pNextACMDriver = padid->pACMDriverList;
+    padid->pACMDriverList = pad;
+
+    /* FIXME: Create a WINE_ACMDRIVER32 */
+    *phad = (HACMDRIVER)pad;
+    
+    return MMSYSERR_NOERROR;
+}
+
+/***********************************************************************
+ *           acmDriverRemove (MSACM32.12)
+ */
+MMRESULT WINAPI acmDriverRemove(HACMDRIVERID hadid, DWORD fdwRemove)
+{
+    PWINE_ACMDRIVERID padid;
+    
+    padid = MSACM_GetDriverID(hadid);
+    if (!padid)
+	return MMSYSERR_INVALHANDLE;
+    
+    if (fdwRemove)
+	return MMSYSERR_INVALFLAG;
+    
+    MSACM_UnregisterDriver(padid);
+    
+    return MMSYSERR_NOERROR;
+}
+
+
+
+/**********************************************************************/
+
+HANDLE MSACM_hHeap = (HANDLE) NULL;
+PWINE_ACMDRIVERID MSACM_pFirstACMDriverID = NULL;
+PWINE_ACMDRIVERID MSACM_pLastACMDriverID = NULL;
+
+/***********************************************************************
+ *           MSACM_RegisterDriver32() 
+ */
+PWINE_ACMDRIVERID MSACM_RegisterDriver(LPSTR pszDriverAlias, LPSTR pszFileName,
+				       HINSTANCE hinstModule)
+//
+// File names are stored in driver.c. I reuse this variable to store driver ID
+// in it. If it's <0x10000, it is primary codec for corresponding format.
+//				       
+{ 
+    PWINE_ACMDRIVERID padid;
+
+    TRACE("('%s', '%x', 0x%08x)\n", pszDriverAlias, pszFileName, hinstModule);
+
+    padid = (PWINE_ACMDRIVERID) HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMDRIVERID));
+    padid->pszDriverAlias = (char*)malloc(strlen(pszDriverAlias)+1);
+    strcpy(padid->pszDriverAlias, pszDriverAlias);
+//    1~strdup(pszDriverAlias);
+    padid->pszFileName = pszFileName;
+    padid->hInstModule = hinstModule;
+    padid->bEnabled = TRUE;
+    padid->pACMDriverList = NULL;
+    padid->pNextACMDriverID = NULL;
+    padid->pPrevACMDriverID = MSACM_pLastACMDriverID;
+    if (MSACM_pLastACMDriverID)
+	MSACM_pLastACMDriverID->pNextACMDriverID = padid;
+    MSACM_pLastACMDriverID = padid;
+    if (!MSACM_pFirstACMDriverID)
+	MSACM_pFirstACMDriverID = padid;
+    
+    return padid;
+}
+
+/***********************************************************************
+ *           MSACM_RegisterAllDrivers32() 
+ */
+void MSACM_RegisterAllDrivers(void)
+{
+    LPSTR pszBuffer;
+    DWORD dwBufferLength;
+    
+    if (MSACM_pFirstACMDriverID)
+	return;
+    
+    MSACM_RegisterDriver("divxa32", (LPSTR)0x161, 0);  // DivX/WMA     [07]
+    MSACM_RegisterDriver("msadp32", (LPSTR)0x2, 0);    // MS ADPCM     [08]
+    MSACM_RegisterDriver("l3codeca", (LPSTR)0x55, 0);  // MPEG Layer-3 [12]
+//    MSACM_RegisterDriver("imaadp32", (LPSTR)0x11, 0);  // IMA ADPCM    [13]
+//    MSACM_RegisterDriver("msgsm32", (LPSTR)0x32, 0);   // MS GSM 6.10  [14]
+}
+
+/***********************************************************************
+ *           MSACM_UnregisterDriver32()
+ */
+PWINE_ACMDRIVERID MSACM_UnregisterDriver(PWINE_ACMDRIVERID p)
+{
+    PWINE_ACMDRIVERID pNextACMDriverID;
+    
+    while (p->pACMDriverList)
+	acmDriverClose((HACMDRIVER) p->pACMDriverList, 0);
+    
+    if (p->pszDriverAlias)
+	HeapFree(MSACM_hHeap, 0, p->pszDriverAlias);
+//    if (p->pszFileName)
+//	HeapFree(MSACM_hHeap, 0, p->pszFileName);
+    
+    if (p == MSACM_pFirstACMDriverID)
+	MSACM_pFirstACMDriverID = p->pNextACMDriverID;
+    if (p == MSACM_pLastACMDriverID)
+	MSACM_pLastACMDriverID = p->pPrevACMDriverID;
+
+    if (p->pPrevACMDriverID)
+	p->pPrevACMDriverID->pNextACMDriverID = p->pNextACMDriverID;
+    if (p->pNextACMDriverID)
+	p->pNextACMDriverID->pPrevACMDriverID = p->pPrevACMDriverID;
+    
+    pNextACMDriverID = p->pNextACMDriverID;
+    
+    HeapFree(MSACM_hHeap, 0, p);
+    
+    return pNextACMDriverID;
+}
+
+/***********************************************************************
+ *           MSACM_UnregisterAllDrivers32()
+ * FIXME
+ *   Where should this function be called?
+ */
+void MSACM_UnregisterAllDrivers(void)
+{
+    PWINE_ACMDRIVERID p;
+
+    for (p = MSACM_pFirstACMDriverID; p; p = MSACM_UnregisterDriver(p));
+}
+
+/***********************************************************************
+ *           MSACM_GetDriverID32() 
+ */
+PWINE_ACMDRIVERID MSACM_GetDriverID(HACMDRIVERID hDriverID)
+{
+    return (PWINE_ACMDRIVERID)hDriverID;
+}
+
+/***********************************************************************
+ *           MSACM_GetDriver32()
+ */
+PWINE_ACMDRIVER MSACM_GetDriver(HACMDRIVER hDriver)
+{
+    return (PWINE_ACMDRIVER)hDriver;
+}
+
+/***********************************************************************
+ *           MSACM_GetObj32()
+ */
+PWINE_ACMOBJ MSACM_GetObj(HACMOBJ hObj)
+{
+    return (PWINE_ACMOBJ)hObj;
+}
+
+
+
+/***********************************************************************
+ *           acmStreamOpen (MSACM32.40)
+ */
+MMRESULT WINAPI acmStreamOpen(PHACMSTREAM phas, HACMDRIVER had, PWAVEFORMATEX pwfxSrc,
+			      PWAVEFORMATEX pwfxDst, PWAVEFILTER pwfltr, DWORD dwCallback,
+			      DWORD dwInstance, DWORD fdwOpen)
+{
+    PWINE_ACMSTREAM	was;
+    PWINE_ACMDRIVER	wad;
+    MMRESULT		ret;
+    int			wfxSrcSize;
+    int			wfxDstSize;
+    
+    TRACE("(%p, 0x%08x, %p, %p, %p, %ld, %ld, %ld)\n",
+	  phas, had, pwfxSrc, pwfxDst, pwfltr, dwCallback, dwInstance, fdwOpen);
+
+    TRACE("src [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%lu, nAvgBytesPerSec=%lu, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n", 
+	  pwfxSrc->wFormatTag, pwfxSrc->nChannels, pwfxSrc->nSamplesPerSec, pwfxSrc->nAvgBytesPerSec, 
+	  pwfxSrc->nBlockAlign, pwfxSrc->wBitsPerSample, pwfxSrc->cbSize);
+
+    TRACE("dst [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%lu, nAvgBytesPerSec=%lu, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n", 
+	  pwfxDst->wFormatTag, pwfxDst->nChannels, pwfxDst->nSamplesPerSec, pwfxDst->nAvgBytesPerSec, 
+	  pwfxDst->nBlockAlign, pwfxDst->wBitsPerSample, pwfxDst->cbSize);
+
+#define SIZEOF_WFX(wfx) (sizeof(WAVEFORMATEX) + ((wfx->wFormatTag == WAVE_FORMAT_PCM) ? 0 : wfx->cbSize))
+    wfxSrcSize = SIZEOF_WFX(pwfxSrc);
+    wfxDstSize = SIZEOF_WFX(pwfxDst);
+#undef SIZEOF_WFX
+
+    was = HeapAlloc(MSACM_hHeap, 0, sizeof(*was) + wfxSrcSize + wfxDstSize + ((pwfltr) ? sizeof(WAVEFILTER) : 0));
+    if (was == NULL)
+	return MMSYSERR_NOMEM;
+    
+    was->drvInst.cbStruct = sizeof(was->drvInst);
+    was->drvInst.pwfxSrc = (PWAVEFORMATEX)((LPSTR)was + sizeof(*was));
+    memcpy(was->drvInst.pwfxSrc, pwfxSrc, wfxSrcSize);
+    was->drvInst.pwfxDst = (PWAVEFORMATEX)((LPSTR)was + sizeof(*was) + wfxSrcSize);
+    memcpy(was->drvInst.pwfxDst, pwfxDst, wfxDstSize);
+    if (pwfltr) {
+	was->drvInst.pwfltr = (PWAVEFILTER)((LPSTR)was + sizeof(*was) + wfxSrcSize + wfxDstSize);
+	memcpy(was->drvInst.pwfltr, pwfltr, sizeof(WAVEFILTER));
+    } else {
+	was->drvInst.pwfltr = NULL;
+    }
+    was->drvInst.dwCallback = dwCallback;    
+    was->drvInst.dwInstance = dwInstance;
+    was->drvInst.fdwOpen = fdwOpen;
+    was->drvInst.fdwDriver = 0L;  
+    was->drvInst.dwDriver = 0L;     
+    was->drvInst.has = (HACMSTREAM)was;
+    
+    if (had) {
+	if (!(wad = MSACM_GetDriver(had))) {
+	    ret = MMSYSERR_INVALPARAM;
+	    goto errCleanUp;
+	}
+	
+	was->obj.pACMDriverID = wad->obj.pACMDriverID;
+	was->pDrv = wad;
+	was->hAcmDriver = 0; /* not to close it in acmStreamClose */
+
+	ret = SendDriverMessage(wad->hDrvr, ACMDM_STREAM_OPEN, (DWORD)&was->drvInst, 0L);
+	if (ret != MMSYSERR_NOERROR)
+	    goto errCleanUp;
+    } else {
+	PWINE_ACMDRIVERID wadi;
+	short drv_tag;
+	ret = ACMERR_NOTPOSSIBLE;
+/*	if(pwfxSrc->wFormatTag==1)//compression
+	    drv_tag=pwfxDst->wFormatTag;
+	    else
+	    if(pwfxDst->wFormatTag==1)//decompression
+		drv_tag=pwfxSrc->wFormatTag;
+		else
+		goto errCleanUp;
+
+	    ret=acmDriverOpen2(drv_tag); 
+	    if (ret == MMSYSERR_NOERROR) {
+		if ((wad = MSACM_GetDriver(had)) != 0) {
+		    was->obj.pACMDriverID = wad->obj.pACMDriverID;
+		    was->pDrv = wad;
+		    was->hAcmDriver = had;
+		    
+		    ret = SendDriverMessage(wad->hDrvr, ACMDM_STREAM_OPEN, (DWORD)&was->drvInst, 0L);
+		    if (ret == MMSYSERR_NOERROR) {
+			if (fdwOpen & ACM_STREAMOPENF_QUERY) {
+			    acmDriverClose(had, 0L);
+			}
+			break;
+		    }
+		}
+		acmDriverClose(had, 0L);*/
+	if(MSACM_pFirstACMDriverID==NULL)
+	    MSACM_RegisterAllDrivers();	
+	
+	for (wadi = MSACM_pFirstACMDriverID; wadi; wadi = wadi->pNextACMDriverID) {
+	    ret = acmDriverOpen(&had, (HACMDRIVERID)wadi, 0L);
+	    if (ret == MMSYSERR_NOERROR) {
+		if ((wad = MSACM_GetDriver(had)) != 0) {
+		    was->obj.pACMDriverID = wad->obj.pACMDriverID;
+		    was->pDrv = wad;
+		    was->hAcmDriver = had;
+		    
+		    ret = SendDriverMessage(wad->hDrvr, ACMDM_STREAM_OPEN, (DWORD)&was->drvInst, 0L);
+		    if (ret == MMSYSERR_NOERROR) {
+			if (fdwOpen & ACM_STREAMOPENF_QUERY) {
+			    acmDriverClose(had, 0L);
+			}
+			break;
+		    }
+		}
+		// no match, close this acm driver and try next one 
+		acmDriverClose(had, 0L);
+	    }
+	}
+	if (ret != MMSYSERR_NOERROR) {
+	    ret = ACMERR_NOTPOSSIBLE;
+	    goto errCleanUp;
+	}
+    }
+    ret = MMSYSERR_NOERROR;
+    if (!(fdwOpen & ACM_STREAMOPENF_QUERY)) {
+	if (phas)
+	    *phas = (HACMSTREAM)was;
+	TRACE("=> (%d)\n", ret);
+	return ret;
+    }
+errCleanUp:		
+    if (phas)
+	*phas = (HACMSTREAM)0;
+    HeapFree(MSACM_hHeap, 0, was);
+    TRACE("=> (%d)\n", ret);
+    return ret;
+}
+
+
+MMRESULT WINAPI acmStreamClose(HACMSTREAM has, DWORD fdwClose)
+{
+    PWINE_ACMSTREAM	was;
+    MMRESULT		ret;
+		
+    TRACE("(0x%08x, %ld)\n", has, fdwClose);
+    
+    if ((was = ACM_GetStream(has)) == NULL) {
+	return MMSYSERR_INVALHANDLE;
+    }
+    ret = SendDriverMessage(was->pDrv->hDrvr, ACMDM_STREAM_CLOSE, (DWORD)&was->drvInst, 0);
+    if (ret == MMSYSERR_NOERROR) {
+	if (was->hAcmDriver)
+	    acmDriverClose(was->hAcmDriver, 0L);	
+	HeapFree(MSACM_hHeap, 0, was);
+    }
+    TRACE("=> (%d)\n", ret);
+    return ret;
+}
+
+/***********************************************************************
+ *           acmStreamConvert (MSACM32.38)
+ */
+MMRESULT WINAPI acmStreamConvert(HACMSTREAM has, PACMSTREAMHEADER pash, 
+				 DWORD fdwConvert)
+{
+    PWINE_ACMSTREAM	was;
+    MMRESULT		ret = MMSYSERR_NOERROR;
+    PACMDRVSTREAMHEADER	padsh;
+
+    TRACE("(0x%08x, %p, %ld)\n", has, pash, fdwConvert);
+    
+    if ((was = ACM_GetStream(has)) == NULL)
+	return MMSYSERR_INVALHANDLE;
+    if (!pash || pash->cbStruct < sizeof(ACMSTREAMHEADER))
+	return MMSYSERR_INVALPARAM;
+
+    if (!(pash->fdwStatus & ACMSTREAMHEADER_STATUSF_PREPARED))
+	return ACMERR_UNPREPARED;
+
+    /* Note: the ACMSTREAMHEADER and ACMDRVSTREAMHEADER structs are of same
+     * size. some fields are private to msacm internals, and are exposed
+     * in ACMSTREAMHEADER in the dwReservedDriver array
+     */
+    padsh = (PACMDRVSTREAMHEADER)pash;
+
+    /* check that pointers have not been modified */
+    if (padsh->pbPreparedSrc != padsh->pbSrc ||
+	padsh->cbPreparedSrcLength < padsh->cbSrcLength ||
+	padsh->pbPreparedDst != padsh->pbDst ||
+	padsh->cbPreparedDstLength < padsh->cbDstLength) {
+	return MMSYSERR_INVALPARAM;
+    }	
+
+    padsh->fdwConvert = fdwConvert;
+
+    ret = SendDriverMessage(was->pDrv->hDrvr, ACMDM_STREAM_CONVERT, (DWORD)&was->drvInst, (DWORD)padsh);
+    if (ret == MMSYSERR_NOERROR) {
+	padsh->fdwStatus |= ACMSTREAMHEADER_STATUSF_DONE;
+    }
+    TRACE("=> (%d)\n", ret);
+    return ret;
+}
+
+
+/***********************************************************************
+ *           acmStreamPrepareHeader (MSACM32.41)
+ */
+MMRESULT WINAPI acmStreamPrepareHeader(HACMSTREAM has, PACMSTREAMHEADER pash, 
+				       DWORD fdwPrepare)
+{
+    PWINE_ACMSTREAM	was;
+    MMRESULT		ret = MMSYSERR_NOERROR;
+    PACMDRVSTREAMHEADER	padsh;
+
+    TRACE("(0x%08x, %p, %ld)\n", has, pash, fdwPrepare);
+    
+    if ((was = ACM_GetStream(has)) == NULL)
+	return MMSYSERR_INVALHANDLE;
+    if (!pash || pash->cbStruct < sizeof(ACMSTREAMHEADER))
+	return MMSYSERR_INVALPARAM;
+    if (fdwPrepare)
+	ret = MMSYSERR_INVALFLAG;
+
+    if (pash->fdwStatus & ACMSTREAMHEADER_STATUSF_DONE)
+	return MMSYSERR_NOERROR;
+
+    /* Note: the ACMSTREAMHEADER and ACMDRVSTREAMHEADER structs are of same
+     * size. some fields are private to msacm internals, and are exposed
+     * in ACMSTREAMHEADER in the dwReservedDriver array
+     */
+    padsh = (PACMDRVSTREAMHEADER)pash;
+
+    padsh->fdwConvert = fdwPrepare;
+    padsh->padshNext = NULL;
+    padsh->fdwDriver = padsh->dwDriver = 0L;
+
+    padsh->fdwPrepared = 0;
+    padsh->dwPrepared = 0;
+    padsh->pbPreparedSrc = 0;
+    padsh->cbPreparedSrcLength = 0;
+    padsh->pbPreparedDst = 0;
+    padsh->cbPreparedDstLength = 0;
+
+    ret = SendDriverMessage(was->pDrv->hDrvr, ACMDM_STREAM_PREPARE, (DWORD)&was->drvInst, (DWORD)padsh);
+    if (ret == MMSYSERR_NOERROR || ret == MMSYSERR_NOTSUPPORTED) {
+	ret = MMSYSERR_NOERROR;
+	padsh->fdwStatus &= ~(ACMSTREAMHEADER_STATUSF_DONE|ACMSTREAMHEADER_STATUSF_INQUEUE);
+	padsh->fdwStatus |= ACMSTREAMHEADER_STATUSF_PREPARED;
+	padsh->fdwPrepared = padsh->fdwStatus;
+	padsh->dwPrepared = 0;
+	padsh->pbPreparedSrc = padsh->pbSrc;
+	padsh->cbPreparedSrcLength = padsh->cbSrcLength;
+	padsh->pbPreparedDst = padsh->pbDst;
+	padsh->cbPreparedDstLength = padsh->cbDstLength;
+    } else {
+	padsh->fdwPrepared = 0;
+	padsh->dwPrepared = 0;
+	padsh->pbPreparedSrc = 0;
+	padsh->cbPreparedSrcLength = 0;
+	padsh->pbPreparedDst = 0;
+	padsh->cbPreparedDstLength = 0;
+    }
+    TRACE("=> (%d)\n", ret);
+    return ret;
+}
+
+/***********************************************************************
+ *           acmStreamReset (MSACM32.42)
+ */
+MMRESULT WINAPI acmStreamReset(HACMSTREAM has, DWORD fdwReset)
+{
+    PWINE_ACMSTREAM	was;
+    MMRESULT		ret = MMSYSERR_NOERROR;
+
+    TRACE("(0x%08x, %ld)\n", has, fdwReset);
+
+    if (fdwReset) {
+	ret = MMSYSERR_INVALFLAG;
+    } else if ((was = ACM_GetStream(has)) == NULL) {
+	return MMSYSERR_INVALHANDLE;
+    } else if (was->drvInst.fdwOpen & ACM_STREAMOPENF_ASYNC) {
+	ret = SendDriverMessage(was->pDrv->hDrvr, ACMDM_STREAM_RESET, (DWORD)&was->drvInst, 0);
+    }
+    TRACE("=> (%d)\n", ret);
+    return ret;
+}
+
+/***********************************************************************
+ *           acmStreamSize (MSACM32.43)
+ */
+MMRESULT WINAPI acmStreamSize(HACMSTREAM has, DWORD cbInput, 
+			      LPDWORD pdwOutputBytes, DWORD fdwSize)
+{
+    PWINE_ACMSTREAM	was;
+    ACMDRVSTREAMSIZE	adss;
+    MMRESULT		ret;
+    
+    TRACE("(0x%08x, %ld, %p, %ld)\n", has, cbInput, pdwOutputBytes, fdwSize);
+    
+    if ((was = ACM_GetStream(has)) == NULL) {
+	return MMSYSERR_INVALHANDLE;
+    }
+    if ((fdwSize & ~ACM_STREAMSIZEF_QUERYMASK) != 0) {
+	return MMSYSERR_INVALFLAG;
+    }
+
+    *pdwOutputBytes = 0L;
+    
+    switch (fdwSize & ACM_STREAMSIZEF_QUERYMASK) {
+    case ACM_STREAMSIZEF_DESTINATION:
+	adss.cbDstLength = cbInput;
+	adss.cbSrcLength = 0;
+	break;
+    case ACM_STREAMSIZEF_SOURCE:
+	adss.cbSrcLength = cbInput;
+	adss.cbDstLength = 0;
+	break;
+    default:	
+	return MMSYSERR_INVALFLAG;
+    }
+    
+    adss.cbStruct = sizeof(adss);
+    adss.fdwSize = fdwSize;
+    ret = SendDriverMessage(was->pDrv->hDrvr, ACMDM_STREAM_SIZE, 
+			    (DWORD)&was->drvInst, (DWORD)&adss);
+    if (ret == MMSYSERR_NOERROR) {
+	switch (fdwSize & ACM_STREAMSIZEF_QUERYMASK) {
+	case ACM_STREAMSIZEF_DESTINATION:
+	    *pdwOutputBytes = adss.cbSrcLength;
+	    break;
+	case ACM_STREAMSIZEF_SOURCE:
+	    *pdwOutputBytes = adss.cbDstLength;
+	    break;
+	}
+    }
+    TRACE("=> (%d) [%lu]\n", ret, *pdwOutputBytes);
+    return ret;
+}
+
+/***********************************************************************
+ *           acmStreamUnprepareHeader (MSACM32.44)
+ */
+MMRESULT WINAPI acmStreamUnprepareHeader(HACMSTREAM has, PACMSTREAMHEADER pash, 
+					 DWORD fdwUnprepare)
+{
+    PWINE_ACMSTREAM	was;
+    MMRESULT		ret = MMSYSERR_NOERROR;
+    PACMDRVSTREAMHEADER	padsh;
+
+    TRACE("(0x%08x, %p, %ld)\n", has, pash, fdwUnprepare);
+    
+    if ((was = ACM_GetStream(has)) == NULL)
+	return MMSYSERR_INVALHANDLE;
+    if (!pash || pash->cbStruct < sizeof(ACMSTREAMHEADER))
+	return MMSYSERR_INVALPARAM;
+
+    if (!(pash->fdwStatus & ACMSTREAMHEADER_STATUSF_PREPARED))
+	return ACMERR_UNPREPARED;
+
+    /* Note: the ACMSTREAMHEADER and ACMDRVSTREAMHEADER structs are of same
+     * size. some fields are private to msacm internals, and are exposed
+     * in ACMSTREAMHEADER in the dwReservedDriver array
+     */
+    padsh = (PACMDRVSTREAMHEADER)pash;
+
+    /* check that pointers have not been modified */
+    if (padsh->pbPreparedSrc != padsh->pbSrc ||
+	padsh->cbPreparedSrcLength < padsh->cbSrcLength ||
+	padsh->pbPreparedDst != padsh->pbDst ||
+	padsh->cbPreparedDstLength < padsh->cbDstLength) {
+	return MMSYSERR_INVALPARAM;
+    }	
+
+    padsh->fdwConvert = fdwUnprepare;
+
+    ret = SendDriverMessage(was->pDrv->hDrvr, ACMDM_STREAM_UNPREPARE, (DWORD)&was->drvInst, (DWORD)padsh);
+    if (ret == MMSYSERR_NOERROR || ret == MMSYSERR_NOTSUPPORTED) {
+	ret = MMSYSERR_NOERROR;
+	padsh->fdwStatus &= ~(ACMSTREAMHEADER_STATUSF_DONE|ACMSTREAMHEADER_STATUSF_INQUEUE|ACMSTREAMHEADER_STATUSF_PREPARED);
+    }
+    TRACE("=> (%d)\n", ret);
+    return ret;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/com.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,66 @@
+/**
+ * Internal functions and structures for COM emulation code.
+ */
+
+#ifndef COM_H
+#define COM_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void* CoTaskMemAlloc(unsigned long cb);
+void CoTaskMemFree(void* cb);
+
+typedef struct
+{
+    long f1;
+    short f2;
+    short f3;
+    char f4[8];
+} GUID;
+
+extern GUID IID_IUnknown;
+extern GUID IID_IClassFactory;
+
+typedef long (*GETCLASSOBJECT) (GUID* clsid, GUID* iid, void** ppv);
+int RegisterComClass(GUID* clsid, GETCLASSOBJECT gcs);
+
+#ifndef STDCALL
+#define STDCALL __attribute__((__stdcall__))	
+#endif
+
+struct IUnknown;
+struct IClassFactory;
+struct IUnknown_vt
+{
+    long STDCALL (*QueryInterface)(struct IUnknown* _this, GUID* iid, void** ppv);
+    long STDCALL (*AddRef)(struct IUnknown* _this) ;
+    long STDCALL (*Release)(struct IUnknown* _this) ;
+} ;
+struct IUnknown
+{
+    struct IUnknown_vt* vt;
+};
+
+struct IClassFactory_vt
+{
+    long STDCALL (*QueryInterface)(struct IUnknown* _this, GUID* iid, void** ppv);
+    long STDCALL (*AddRef)(struct IUnknown* _this) ;
+    long STDCALL (*Release)(struct IUnknown* _this) ;
+    long STDCALL (*CreateInstance)(struct IClassFactory* _this, struct IUnknown* pUnkOuter, GUID* riid, void** ppvObject);
+};
+
+struct IClassFactory
+{
+    struct IClassFactory_vt* vt;
+};
+
+long CoCreateInstance(GUID* rclsid, struct IUnknown* pUnkOuter,
+                    long dwClsContext, GUID* riid, void** ppv);
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/config.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,74 @@
+
+/* include/config.h.  Generated automatically by configure.  */
+/* include/config.h.in.  Generated automatically from configure.in by autoheader.  */
+#define USE_SDL 1
+/* #undef QUIET */
+/* #undef TIMING */
+/* #undef DETAILED_OUT */
+#define MMX 1
+#define HAVE_LIBXXF86DGA 1
+#define HAVE_LIBXXF86VM 1
+#define USE_TSC 1
+
+/* Define to empty if the keyword does not work.  */
+/* #undef const */
+
+/* Define if you don't have vprintf but do have _doprnt.  */
+/* #undef HAVE_DOPRNT */
+
+/* Define if you have a working `mmap' system call.  */
+#define HAVE_MMAP 1
+
+/* Define if you have the vprintf function.  */
+#define HAVE_VPRINTF 1
+
+/* Define as __inline if that's what the C compiler calls it.  */
+/* #undef inline */
+
+/* Define as the return type of signal handlers (int or void).  */
+#define RETSIGTYPE void
+
+/* Define if you have the ANSI C header files.  */
+#define STDC_HEADERS 1
+
+/* Define if you can safely include both <sys/time.h> and <time.h>.  */
+#define TIME_WITH_SYS_TIME 1
+
+/* Define if you have the ftime function.  */
+#define HAVE_FTIME 1
+
+/* Define if you have the getpagesize function.  */
+#define HAVE_GETPAGESIZE 1
+
+/* Define if you have the gettimeofday function.  */
+#define HAVE_GETTIMEOFDAY 1
+
+/* Define if you have the strdup function.  */
+#define HAVE_STRDUP 1
+
+/* Define if you have the strstr function.  */
+#define HAVE_STRSTR 1
+
+/* Define if you have the <fcntl.h> header file.  */
+#define HAVE_FCNTL_H 1
+
+/* Define if you have the <limits.h> header file.  */
+#define HAVE_LIMITS_H 1
+
+/* Define if you have the <malloc.h> header file.  */
+#define HAVE_MALLOC_H 1
+
+/* Define if you have the <sys/ioctl.h> header file.  */
+#define HAVE_SYS_IOCTL_H 1
+
+/* Define if you have the <sys/time.h> header file.  */
+#define HAVE_SYS_TIME_H 1
+
+/* Define if you have the <unistd.h> header file.  */
+#define HAVE_UNISTD_H 1
+
+/* Define if you have the dl library (-ldl).  */
+#define HAVE_LIBDL 1
+
+/* Define if you have the jpeg library (-ljpeg).  */
+#define HAVE_LIBJPEG 1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/driver.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,223 @@
+#include <config.h>
+#include <stdio.h>
+
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#else
+#include <stdlib.h>
+#endif
+
+#include <wine/driver.h>
+#include <wine/pe_image.h>
+#include <wine/winreg.h>
+#include <wine/vfw.h>
+#include <registry.h>
+
+//#include "com.h"
+//typedef long STDCALL (*GETCLASS) (GUID*, GUID*, void**);
+
+
+#ifdef __FreeBSD__
+#include <sys/time.h>
+#endif
+
+
+#define STORE_ALL \
+    __asm__ ( \
+    "push %%ebx\n\t" \
+    "push %%ecx\n\t" \
+    "push %%edx\n\t" \
+    "push %%esi\n\t" \
+    "push %%edi\n\t"::)
+
+#define REST_ALL \
+    __asm__ ( \
+    "pop %%edi\n\t" \
+    "pop %%esi\n\t" \
+    "pop %%edx\n\t" \
+    "pop %%ecx\n\t" \
+    "pop %%ebx\n\t"::)
+
+
+
+typedef struct {
+    UINT             uDriverSignature;
+    HINSTANCE        hDriverModule;
+    DRIVERPROC       DriverProc;
+    DWORD            dwDriverID;
+} DRVR;
+
+typedef DRVR  *PDRVR;
+typedef DRVR  *NPDRVR;
+typedef DRVR  *LPDRVR;
+    
+static DWORD dwDrvID = 0;
+
+
+LRESULT WINAPI SendDriverMessage( HDRVR hDriver, UINT message,
+                                    LPARAM lParam1, LPARAM lParam2 )
+{
+    DRVR* module=(DRVR*)hDriver;
+    int result;
+#ifdef DETAILED_OUT    
+    printf("SendDriverMessage: driver %X, message %X, arg1 %X, arg2 %X\n", hDriver, message, lParam1, lParam2);
+#endif
+    if(module==0)return -1;
+    if(module->hDriverModule==0)return -1;
+    if(module->DriverProc==0)return -1;
+    STORE_ALL;
+    result=module->DriverProc(module->dwDriverID,1,message,lParam1,lParam2);
+    REST_ALL;
+#ifdef DETAILED_OUT    
+    printf("\t\tResult: %X\n", result);
+#endif    
+    return result;
+}				    
+
+static NPDRVR DrvAlloc(HDRVR*lpDriver, LPUINT lpDrvResult)
+{
+    NPDRVR npDriver;
+    /* allocate and lock handle */
+    if (lpDriver)
+    {
+      if ( (*lpDriver = (HDRVR) malloc(sizeof(DRVR))) )
+        {
+            if ((npDriver = (NPDRVR) *lpDriver))
+            {
+                    *lpDrvResult = MMSYSERR_NOERROR;
+                    return (npDriver);
+            }
+            free((NPDRVR)*lpDriver);
+        }
+        return (*lpDrvResult = MMSYSERR_NOMEM, (NPDRVR) 0);
+    }
+    return (*lpDrvResult = MMSYSERR_INVALPARAM, (NPDRVR) 0);
+}
+
+                                                                                                                    
+static void DrvFree(HDRVR hDriver)
+{
+    int i;
+    if(hDriver)
+    	if(((DRVR*)hDriver)->hDriverModule)
+    	if(((DRVR*)hDriver)->DriverProc)
+	(((DRVR*)hDriver)->DriverProc)(((DRVR*)hDriver)->dwDriverID, hDriver, DRV_CLOSE, 0, 0);
+    if(hDriver)	{
+            if(((DRVR*)hDriver)->hDriverModule)
+    		if(((DRVR*)hDriver)->DriverProc)
+			(((DRVR*)hDriver)->DriverProc)(0, hDriver, DRV_FREE, 0, 0);
+		FreeLibrary(((DRVR*)hDriver)->hDriverModule);
+        	free((NPDRVR)hDriver);
+		return;	
+    }
+}
+
+void DrvClose(HDRVR hdrvr)
+{
+    DrvFree(hdrvr);
+}
+
+
+char* def_path=WIN32_PATH;    // path to codecs
+char* win32_codec_name=NULL;  // must be set before calling DrvOpen() !!!
+
+HDRVR
+DrvOpen(LPARAM lParam2)
+{
+    ICOPEN *icopen=(ICOPEN *) lParam2;
+    UINT uDrvResult;
+    HDRVR hDriver;
+    NPDRVR npDriver;
+    char unknown[0x24];
+//    char* codec_name=icopen->fccHandler;
+
+    if (!(npDriver = DrvAlloc(&hDriver, &uDrvResult)))
+	return ((HDRVR) 0);
+
+    if (!(npDriver->hDriverModule = expLoadLibraryA(win32_codec_name))) {
+     	printf("Can't open library %s\n", win32_codec_name);
+        DrvFree(hDriver);
+        return ((HDRVR) 0);
+    }
+
+#if 0
+    {
+        unsigned char *p=((char*)npDriver->hDriverModule);
+        double *dp;
+        int i;
+        p+=0x14c0;
+        for(i=0;i<16;i++)printf(" %02X",p[i]); printf("\n");
+        dp=(double*)p;
+        printf("divx bitrate = %f\n",(float)(*dp));
+//    	*(double*)((char*)npDriver->hDriverModule+0x14c0)=bitrate;
+    }
+#endif
+   
+    if (!(npDriver->DriverProc = (DRIVERPROC)
+             GetProcAddress(npDriver->hDriverModule, "DriverProc"))) {
+#if 1
+         printf("Library %s is not a VfW/ACM valid codec\n", win32_codec_name);
+#else
+        // Try DirectShow...
+         GETCLASS func=(GETCLASS)GetProcAddress(npDriver->hDriverModule,"DllGetClassObject");
+         if(!func)
+           printf("Library %s is not a valid VfW/ACM/DShow codec\n", win32_codec_name);
+         else {
+            HRESULT result;
+            struct IClassFactory* factory=0;
+	    struct IUnknown* object=0;
+            GUID CLSID_Voxware={0x73f7a062, 0x8829, 0x11d1,
+                {0xb5, 0x50, 0x00, 0x60, 0x97, 0x24, 0x2d, 0x8d}};
+            GUID* id=&CLSID_Voxware;
+            
+            result=func(id, &IID_IClassFactory, (void**)&factory);
+            if(result || (!factory)) printf("No such class object\n");
+
+            printf("Calling factory->vt->CreateInstance()\n");
+            printf("addr = %X\n",(unsigned int)factory->vt->CreateInstance);
+            result=factory->vt->CreateInstance(factory, 0, &IID_IUnknown, (void**)&object);
+            printf("Calling factory->vt->Release()\n");
+            factory->vt->Release((struct IUnknown*)factory);
+            if(result || (!object)) printf("Class factory failure\n");
+
+            printf("DirectShow codecs not yet supported...\n");
+         }
+#endif
+
+         FreeLibrary(npDriver->hDriverModule);
+         DrvFree(hDriver);
+         return ((HDRVR) 0);
+
+    }
+
+    //TRACE("DriverProc == %X\n", npDriver->DriverProc);
+     npDriver->dwDriverID = ++dwDrvID;
+
+	STORE_ALL;
+        (npDriver->DriverProc)(0, hDriver, DRV_LOAD, 0, 0);
+	REST_ALL;
+	//TRACE("DRV_LOAD Ok!\n");
+	STORE_ALL;
+	(npDriver->DriverProc)(0, hDriver, DRV_ENABLE, 0, 0);
+	REST_ALL;
+	//TRACE("DRV_ENABLE Ok!\n");
+
+     // open driver 
+    STORE_ALL;
+     npDriver->dwDriverID=(npDriver->DriverProc)(npDriver->dwDriverID, hDriver, DRV_OPEN,
+         (LPARAM) (LPSTR) unknown, lParam2);
+    REST_ALL;
+
+    //TRACE("DRV_OPEN Ok!(%X)\n", npDriver->dwDriverID);
+
+    if (uDrvResult)
+    {
+         DrvFree(hDriver);
+         hDriver = (HDRVR) 0;
+     }
+     
+     printf("Successfully loaded codec %s\n",win32_codec_name);
+     
+     return (hDriver);
+}
+  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/elfdll.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,305 @@
+/*
+ * Elf-dll loader functions
+ *
+ * Copyright 1999 Bertho A. Stultiens
+ */
+#include <config.h>
+
+#ifdef HAVE_LIBDL
+
+#include <string.h>
+#include <ctype.h>
+#include <stdlib.h>
+
+#include <wine/config.h>
+#include <wine/windef.h>
+//#include <wine/global.h>
+//#include <wine/process.h>
+#include <wine/module.h>
+#include <wine/heap.h>
+#include <wine/elfdll.h>
+#include <wine/debugtools.h>
+#include <wine/winerror.h>
+
+//DEFAULT_DEBUG_CHANNEL(elfdll)
+
+#include <dlfcn.h>
+
+struct modref_list_t;
+
+typedef struct modref_list_t
+{
+    WINE_MODREF* wm;
+    struct modref_list_t *next;
+    struct modref_list_t *prev;    
+}
+modref_list;
+
+
+//WINE_MODREF *local_wm=NULL;
+extern modref_list* local_wm;
+
+
+/*------------------ HACKS -----------------*/
+extern DWORD fixup_imports(WINE_MODREF *wm);
+extern void dump_exports(HMODULE hModule);
+/*---------------- END HACKS ---------------*/
+
+//char *extra_ld_library_path = "/usr/lib/win32";
+extern char* def_path;
+
+struct elfdll_image
+{
+	HMODULE		pe_module_start;
+	DWORD		pe_module_size;
+};
+
+
+/****************************************************************************
+ *	ELFDLL_dlopen
+ *
+ * Wrapper for dlopen to search the EXTRA_LD_LIBRARY_PATH from wine.conf
+ * manually because libdl.so caches the environment and does not accept our
+ * changes.
+ */
+void *ELFDLL_dlopen(const char *libname, int flags)
+{
+	char buffer[256];
+	int namelen;
+	void *handle;
+	char *ldpath;
+
+	/* First try the default path search of dlopen() */
+	handle = dlopen(libname, flags);
+	if(handle)
+		return handle;
+
+	/* Now try to construct searches through our extra search-path */
+	namelen = strlen(libname);
+	ldpath = def_path;
+	while(ldpath && *ldpath)
+	{
+		int len;
+		char *cptr;
+		char *from;
+
+		from = ldpath;
+		cptr = strchr(ldpath, ':');
+		if(!cptr)
+		{
+			len = strlen(ldpath);
+			ldpath = NULL;
+		}
+		else
+		{
+			len = cptr - ldpath;
+			ldpath = cptr + 1;
+		}
+
+		if(len + namelen + 1 >= sizeof(buffer))
+		{
+			ERR("Buffer overflow! Check EXTRA_LD_LIBRARY_PATH or increase buffer size.\n");
+			return NULL;
+		}
+
+		strncpy(buffer, from, len);
+		if(len)
+		{
+			buffer[len] = '/';
+			strcpy(buffer + len + 1, libname);
+		}
+		else
+			strcpy(buffer + len, libname);
+
+		TRACE("Trying dlopen('%s', %d)\n", buffer, flags);
+
+		handle = dlopen(buffer, flags);
+		if(handle)
+			return handle;
+	}
+	return NULL;
+}
+
+
+/****************************************************************************
+ *	get_sobasename	(internal)
+ *
+ */
+static LPSTR get_sobasename(LPCSTR path, LPSTR name)
+{
+	char *cptr;
+
+	/* Strip the path from the library name */
+	if((cptr = strrchr(path, '/')))
+	{
+		char *cp = strrchr(cptr+1, '\\');
+		if(cp && cp > cptr)
+			cptr = cp;
+	}
+	else
+		cptr = strrchr(path, '\\');
+
+	if(!cptr)
+		cptr = (char *)path;	/* No '/' nor '\\' in path */
+	else
+		cptr++;
+
+	strcpy(name, cptr);
+	cptr = strrchr(name, '.');
+	if(cptr)
+		*cptr = '\0';	/* Strip extension */
+
+	/* Convert to lower case.
+	 * This must be done manually because it is not sure that
+	 * other modules are accessible.
+	 */
+	for(cptr = name; *cptr; cptr++)
+		*cptr = tolower(*cptr);
+
+	return name;
+}
+
+
+/****************************************************************************
+ *	ELFDLL_CreateModref	(internal)
+ *
+ * INPUT
+ *	hModule	- the header from the elf-dll's data-segment
+ *	path	- requested path from original call
+ *
+ * OUTPUT
+ *	A WINE_MODREF pointer to the new object
+ *
+ * BUGS
+ *	- Does not handle errors due to dependencies correctly
+ *	- path can be wrong
+ */
+#define RVA(base, va)	(((DWORD)base) + ((DWORD)va))
+
+static WINE_MODREF *ELFDLL_CreateModref(HMODULE hModule, LPCSTR path)
+{
+//	IMAGE_NT_HEADERS *nt = PE_HEADER(hModule);
+	IMAGE_DATA_DIRECTORY *dir;
+	IMAGE_IMPORT_DESCRIPTOR *pe_import = NULL;
+	WINE_MODREF *wm;
+	int len;
+	HANDLE procheap = GetProcessHeap();
+
+	wm = (WINE_MODREF *)HeapAlloc(procheap, HEAP_ZERO_MEMORY, sizeof(*wm));
+	if(!wm)
+		return NULL;
+
+	wm->module = hModule;
+	wm->type = MODULE32_ELF;		/* FIXME */
+
+//	dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_EXPORT;
+//	if(dir->Size)
+//		wm->binfmt.pe.pe_export = (PIMAGE_EXPORT_DIRECTORY)RVA(hModule, dir->VirtualAddress);
+
+//	dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_IMPORT;
+//	if(dir->Size)
+//		pe_import = wm->binfmt.pe.pe_import = (PIMAGE_IMPORT_DESCRIPTOR)RVA(hModule, dir->VirtualAddress);
+
+//	dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_RESOURCE;
+//	if(dir->Size)
+//		wm->binfmt.pe.pe_resource = (PIMAGE_RESOURCE_DIRECTORY)RVA(hModule, dir->VirtualAddress);
+
+
+	wm->filename = malloc(strlen(path)+1);
+	strcpy(wm->filename, path);
+	wm->modname = strrchr( wm->filename, '\\' );
+	if (!wm->modname) wm->modname = wm->filename;
+	else wm->modname++;
+/*
+	len = GetShortPathNameA( wm->filename, NULL, 0 );
+	wm->short_filename = (char *)HeapAlloc( procheap, 0, len+1 );
+	GetShortPathNameA( wm->filename, wm->short_filename, len+1 );
+	wm->short_modname = strrchr( wm->short_filename, '\\' );
+	if (!wm->short_modname) wm->short_modname = wm->short_filename;
+	else wm->short_modname++;
+*/
+	/* Link MODREF into process list */
+
+//	EnterCriticalSection( &PROCESS_Current()->crit_section );
+	
+	if(local_wm)
+        {
+    	    local_wm->next=malloc(sizeof(modref_list));
+    	    local_wm->next->prev=local_wm;
+    	    local_wm->next->next=NULL;
+            local_wm->next->wm=wm;
+    	    local_wm=local_wm->next;
+	}
+	else
+        {
+	    local_wm=malloc(sizeof(modref_list));
+	    local_wm->next=local_wm->prev=NULL;
+    	    local_wm->wm=wm;
+	}	
+
+//	LeaveCriticalSection( &PROCESS_Current()->crit_section );
+	return wm;
+}
+
+/****************************************************************************
+ *	ELFDLL_LoadLibraryExA	(internal)
+ *
+ * Implementation of elf-dll loading for PE modules
+ */
+WINE_MODREF *ELFDLL_LoadLibraryExA(LPCSTR path, DWORD flags)
+{
+	LPVOID dlhandle;
+	struct elfdll_image *image;
+	char name[129];
+	char soname[129];
+	WINE_MODREF *wm;
+
+	get_sobasename(path, name);
+	strcpy(soname, name);
+	strcat(soname, ".so");
+
+	/* Try to open the elf-dll */
+	dlhandle = ELFDLL_dlopen(soname, RTLD_LAZY);
+	if(!dlhandle)
+	{
+		WARN("Could not load %s (%s)\n", soname, dlerror());
+		SetLastError( ERROR_FILE_NOT_FOUND );
+		return NULL;
+	}
+
+	/* Get the 'dllname_elfdll_image' variable */
+/*	strcpy(soname, name);
+	strcat(soname, "_elfdll_image");
+	image = (struct elfdll_image *)dlsym(dlhandle, soname);
+	if(!image) 
+	{
+		ERR("Could not get elfdll image descriptor %s (%s)\n", soname, dlerror());
+		dlclose(dlhandle);
+		SetLastError( ERROR_BAD_FORMAT );
+		return NULL;
+	}
+
+*/
+	wm = ELFDLL_CreateModref((int)dlhandle, path);
+	if(!wm)
+	{
+		ERR("Could not create WINE_MODREF for %s\n", path);
+		dlclose(dlhandle);
+		SetLastError( ERROR_OUTOFMEMORY );
+		return NULL;
+	}
+
+	return wm;
+}
+
+
+/****************************************************************************
+ *	ELFDLL_UnloadLibrary	(internal)
+ *
+ * Unload an elf-dll completely from memory and deallocate the modref
+ */
+void ELFDLL_UnloadLibrary(WINE_MODREF *wm)
+{
+}
+
+#endif /*HAVE_LIBDL*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/ext.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,565 @@
+/********************************************************
+ * 
+ *
+ *      Stub functions for Wine module
+ *
+ *
+ ********************************************************/
+#include <config.h>
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#else
+#include <stdlib.h>
+#endif
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdarg.h>
+#include <wine/windef.h>
+//#include <wine/winbase.h>
+int dbg_header_err( const char *dbg_channel, const char *func )
+{
+    return 0; 
+}
+int dbg_header_warn( const char *dbg_channel, const char *func )
+{
+    return 0; 
+}
+int dbg_header_fixme( const char *dbg_channel, const char *func )
+{
+    return 0; 
+}
+int dbg_header_trace( const char *dbg_channel, const char *func )
+{
+    return 0; 
+}
+int dbg_vprintf( const char *format, ... )
+{
+    return 0; 
+}
+int __vprintf( const char *format, ... )
+{
+#ifdef DETAILED_OUT
+    va_list va;
+    va_start(va, format);
+    vprintf(format, va);
+    va_end(va);
+    fflush(stdout);
+#endif
+    return 0; 
+}
+    
+int GetProcessHeap()
+{
+    return 1;
+}
+
+void* HeapAlloc(int heap, int flags, int size)
+{
+    if(flags & 0x8)
+	return calloc(size, 1);
+	else
+	return malloc(size);
+}
+
+int HeapFree(int heap, int flags, void* mem)
+{
+    free(mem);
+    return 1;
+}     	
+
+static int last_error;
+
+int GetLastError()
+{
+    return last_error;
+}
+
+int SetLastError(int error)
+{ 
+    return last_error=error;
+}    
+
+int ReadFile(int handle, void* mem, unsigned long size, long* result, long flags)
+{
+    *result=read(handle, mem, size);
+    return *result;
+}    
+int lstrcmpiA(const char* c1, const char* c2)
+{
+    return strcasecmp(c1,c2);
+}
+int lstrcpynA(char* dest, const char* src, int num)
+{
+    return strncmp(dest,src,num);
+}
+int lstrlenA(const char* s)
+{
+    return strlen(s);
+}   
+int lstrlenW(const short* s)
+{
+    int l;
+    if(!s)
+	return 0;
+    l=0;
+    while(s[l])
+	l++;
+     return l;
+}
+int lstrcpynWtoA(char* dest, const char* src, int count)
+{
+    int moved=0;
+    if((dest==0) || (src==0))
+	return 0;
+    while(moved<count)
+    {
+        *dest=*src;
+	moved++;
+	if(*src==0)
+	    return moved;
+	src++;
+	dest++;
+    }
+}
+int wcsnicmp(const unsigned short* s1, const unsigned short* s2, int n)
+{
+    if(s1==0)
+	return;
+    if(s2==0)
+        return;
+    while(n>0)
+    {
+	if(*s1<*s2)
+	    return -1;
+	else
+    	    if(*s1>*s2)
+		return 1;
+	    else
+		if(*s1==0)
+		    return 0;
+    s1++;
+    s2++;
+    n--;
+    }
+    return 0;
+}			
+		
+		
+int IsBadReadPtr(void* data, int size)
+{
+    if(size==0)
+	return 0;
+    if(data==NULL)
+        return 1;
+    return 0;
+}   
+char* HEAP_strdupA(const char* string)
+{
+//    return strdup(string);
+    char* answ=malloc(strlen(string)+1);
+    strcpy(answ, string);
+    return answ;
+}
+short* HEAP_strdupAtoW(void* heap, void* hz, const char* string)
+{
+    int size, i;
+    short* answer;
+    if(string==0)
+	return 0;
+    size=strlen(string);
+    answer=malloc(size+size+2);
+    for(i=0; i<=size; i++)
+	answer[i]=(short)string[i];
+    return answer;	
+}
+char* HEAP_strdupWtoA(void* heap, void* hz, const short* string)
+{
+    int size, i;
+    char* answer;
+    if(string==0)
+	return 0;
+    size=0;
+    while(string[size])
+       size++;
+    answer=malloc(size+2);
+    for(i=0; i<=size; i++)
+	answer[i]=(char)string[i];
+    return answer;	
+}
+
+/***********************************************************************
+ *           FILE_dommap
+ */
+
+//#define MAP_PRIVATE
+//#define MAP_SHARED
+#undef MAP_ANON
+LPVOID FILE_dommap( int unix_handle, LPVOID start,
+                    DWORD size_high, DWORD size_low,
+                    DWORD offset_high, DWORD offset_low,
+                    int prot, int flags )
+{
+    int fd = -1;
+    int pos;
+    LPVOID ret;
+
+    if (size_high || offset_high)
+        printf("offsets larger than 4Gb not supported\n");
+
+    if (unix_handle == -1)
+    {
+#ifdef MAP_ANON
+//	printf("Anonymous\n");
+        flags |= MAP_ANON;
+#else
+        static int fdzero = -1;
+
+        if (fdzero == -1)
+        {
+            if ((fdzero = open( "/dev/zero", O_RDONLY )) == -1)
+            {
+                perror( "/dev/zero: open" );
+                exit(1);
+            }
+        }
+        fd = fdzero;
+#endif  /* MAP_ANON */
+	/* Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap */
+#ifdef MAP_SHARED
+	flags &= ~MAP_SHARED;
+#endif
+#ifdef MAP_PRIVATE
+	flags |= MAP_PRIVATE;
+#endif
+    }
+    else fd = unix_handle;
+//    printf("fd %x, start %x, size %x, pos %x, prot %x\n",fd,start,size_low, offset_low, prot);
+//    if ((ret = mmap( start, size_low, prot,
+//                     flags, fd, offset_low )) != (LPVOID)-1)
+    if ((ret = mmap( start, size_low, prot,
+                     MAP_PRIVATE | MAP_FIXED, fd, offset_low )) != (LPVOID)-1)
+    {
+//	    printf("address %08x\n", *(int*)ret);
+//	printf("%x\n", ret);		     
+	    return ret;
+    }		
+
+//    printf("mmap %d\n", errno);
+
+    /* mmap() failed; if this is because the file offset is not    */
+    /* page-aligned (EINVAL), or because the underlying filesystem */
+    /* does not support mmap() (ENOEXEC), we do it by hand.        */
+
+    if (unix_handle == -1) return ret;
+    if ((errno != ENOEXEC) && (errno != EINVAL)) return ret;
+    if (prot & PROT_WRITE)
+    {
+        /* We cannot fake shared write mappings */
+#ifdef MAP_SHARED
+	if (flags & MAP_SHARED) return ret;
+#endif
+#ifdef MAP_PRIVATE
+	if (!(flags & MAP_PRIVATE)) return ret;
+#endif
+    }
+/*    printf( "FILE_mmap: mmap failed (%d), faking it\n", errno );*/
+    /* Reserve the memory with an anonymous mmap */
+    ret = FILE_dommap( -1, start, size_high, size_low, 0, 0,
+                       PROT_READ | PROT_WRITE, flags );
+    if (ret == (LPVOID)-1)
+//    {
+//	perror(
+	 return ret;
+    /* Now read in the file */
+    if ((pos = lseek( fd, offset_low, SEEK_SET )) == -1)
+    {
+        FILE_munmap( ret, size_high, size_low );
+//	printf("lseek\n");
+        return (LPVOID)-1;
+    }
+    read( fd, ret, size_low );
+    lseek( fd, pos, SEEK_SET );  /* Restore the file pointer */
+    mprotect( ret, size_low, prot );  /* Set the right protection */
+//    printf("address %08x\n", *(int*)ret);
+    return ret;
+}
+
+
+/***********************************************************************
+ *           FILE_munmap
+ */
+int FILE_munmap( LPVOID start, DWORD size_high, DWORD size_low )
+{
+    if (size_high)
+      printf("offsets larger than 4Gb not supported\n");
+    return munmap( start, size_low );
+}
+static int mapping_size=0;
+
+struct file_mapping_s;
+typedef struct file_mapping_s
+{
+    int mapping_size;
+    char* name;
+    HANDLE handle;
+    struct file_mapping_s* next;
+    struct file_mapping_s* prev;
+}file_mapping;
+static file_mapping* fm=0;
+
+
+
+#define	PAGE_NOACCESS		0x01
+#define	PAGE_READONLY		0x02
+#define	PAGE_READWRITE		0x04
+#define	PAGE_WRITECOPY		0x08
+#define	PAGE_EXECUTE		0x10
+#define	PAGE_EXECUTE_READ	0x20
+#define	PAGE_EXECUTE_READWRITE	0x40
+#define	PAGE_EXECUTE_WRITECOPY	0x80
+#define	PAGE_GUARD		0x100
+#define	PAGE_NOCACHE		0x200
+
+HANDLE CreateFileMappingA(int hFile, void* lpAttr,
+DWORD flProtect, DWORD dwMaxHigh, DWORD dwMaxLow, const char* name)
+{
+    unsigned int len;
+    HANDLE answer;
+    int anon=0;
+    int mmap_access=0;
+    if(hFile<0)
+    {
+	anon=1;
+	hFile=open("/dev/zero", O_RDWR);
+	if(hFile<0)
+	    return 0;
+    }	    
+    if(!anon)
+    {	
+        len=lseek(hFile, 0, SEEK_END);
+	lseek(hFile, 0, SEEK_SET);
+    }
+    else len=dwMaxLow;
+
+    if(flProtect & PAGE_READONLY)
+	mmap_access |=PROT_READ;
+    else
+	mmap_access |=PROT_READ|PROT_WRITE;
+	
+    answer=(HANDLE)mmap(NULL, len, mmap_access, MAP_PRIVATE, hFile, 0);    
+    if(anon)
+        close(hFile);
+    if(answer!=(HANDLE)-1)
+    {
+	if(fm==0)
+	{
+	    fm=malloc(sizeof(file_mapping));
+	    fm->prev=NULL;
+	}    
+	else
+	{
+	    fm->next=malloc(sizeof(file_mapping));
+	    fm->next->prev=fm;
+	    fm=fm->next;
+	}
+	fm->next=NULL;    
+	fm->handle=answer;
+	if(name)
+	{
+	    fm->name=malloc(strlen(name)+1);
+	    strcpy(fm->name, name);
+	}    
+	else
+	    fm->name=NULL;
+	fm->mapping_size=len;
+	
+	if(anon)
+	    close(hFile);
+	return answer;
+    }
+    return (HANDLE)0;
+}        
+int UnmapViewOfFile(HANDLE handle)
+{
+    file_mapping* p;
+    int result;
+    if(fm==0)
+	return (HANDLE)0;
+    for(p=fm; p; p=p->next)
+    {
+	if(p->handle==handle)
+	{
+	    result=munmap((void*)handle, p->mapping_size);
+	    if(p->next)p->next->prev=p->prev;
+	    if(p->prev)p->prev->next=p->next;
+	    if(p->name)
+		free(p->name);
+	    if(p==fm)
+		fm=p->prev;
+	    free(p);
+	    return result;
+	}        
+    }
+    return 0;	
+}    
+//static int va_size=0;
+struct virt_alloc_s;
+typedef struct virt_alloc_s
+{
+    int mapping_size;
+    char* address;
+    struct virt_alloc_s* next;
+    struct virt_alloc_s* prev;
+    int state;
+}virt_alloc;
+static virt_alloc* vm=0;
+#define MEM_COMMIT              0x00001000
+#define MEM_RESERVE             0x00002000
+
+void* VirtualAlloc(void* address, DWORD size, DWORD type,  DWORD protection)
+{
+    void* answer;
+    int fd=open("/dev/zero", O_RDWR);
+    size=(size+0xffff)&(~0xffff);
+//    printf("VirtualAlloc(0x%08X, %d)\n", address
+    if(address!=0)
+    {
+    //check whether we can allow to allocate this 
+        virt_alloc* str=vm;
+        while(str)
+        {
+	    if((unsigned)address>=(unsigned)str->address+str->mapping_size)
+	    {
+		str=str->prev;
+		continue;
+	    }	
+	    if((unsigned)address+size<(unsigned)str->address)
+	    {
+		str=str->prev;
+		continue;
+	    }
+	    if(str->state==0)
+	    {
+#warning FIXME
+		if(((unsigned)address+size<(unsigned)str->address+str->mapping_size) && (type & MEM_COMMIT))
+		{
+		    close(fd);
+		    return address; //returning previously reserved memory
+		}
+		return NULL;    
+	    }
+	    close(fd);
+	    return NULL;
+	}
+	answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC, 
+	    MAP_FIXED | MAP_PRIVATE, fd, 0);
+    }	    
+    else
+    answer=mmap(address, size, PROT_READ | PROT_WRITE | PROT_EXEC, 
+	 MAP_PRIVATE, fd, 0);
+//    answer=FILE_dommap(-1, address, 0, size, 0, 0,
+//	PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
+     close(fd);
+    if(answer==(void*)-1)
+    {
+	printf("Error no %d\n", errno);
+	printf("VirtualAlloc(0x%08X, %d) failed\n", address, size);
+	return NULL;
+    }
+    else
+    {
+	virt_alloc *new_vm=malloc(sizeof(virt_alloc));
+	new_vm->mapping_size=size;
+	new_vm->address=answer;
+        new_vm->prev=vm;
+	if(type == MEM_RESERVE)
+	    new_vm->state=0;
+	else
+	    new_vm->state=1;
+	if(vm)
+	    vm->next=new_vm;
+    	vm=new_vm;
+	vm->next=0;
+//	if(va_size!=0)
+//	    printf("Multiple VirtualAlloc!\n");	    
+//	printf("answer=0x%08x\n", answer);
+        return answer;
+    }	
+}    	
+int VirtualFree(void*  address, int t1, int t2)//not sure
+{
+    virt_alloc* str=vm;
+    int answer;
+    while(str)
+    {
+    if(address!=str->address)
+    {
+	str=str->prev;
+	continue;
+    }	
+    answer=munmap(str->address, str->mapping_size);
+    if(str->next)str->next->prev=str->prev;
+    if(str->prev)str->prev->next=str->next;
+    if(vm==str)vm=0;
+    free(str);
+    return 0;
+    }
+    return -1;
+}
+
+int WideCharToMultiByte(unsigned int codepage, long flags, const short* src,
+     int srclen,char* dest, int destlen, const char* defch, int* used_defch)
+{
+    int i;
+    if(src==0)
+	return 0;
+    for(i=0; i<srclen; i++)
+	printf("%c", src[i]);
+    printf("\n");		
+    if(dest==0)
+    {
+    for(i=0; i<srclen; i++)
+    {
+	src++;
+    	if(*src==0)
+	    return i+1;
+    }
+	return srclen+1;	    
+    }	
+    if(used_defch)
+	*used_defch=0;	
+    for(i=0; i<min(srclen, destlen); i++)
+    {
+	*dest=(char)*src;
+	dest++;
+	src++;
+	if(*src==0)
+	    return i+1;
+    }	    
+    return min(srclen, destlen);
+}
+int MultiByteToWideChar(unsigned int codepage,long flags, const char* src, int srclen,
+    short* dest, int destlen)
+{
+    return 0;
+}
+HANDLE OpenFileMappingA(long access, long prot, char* name)
+{
+    file_mapping* p;
+    if(fm==0)
+	return (HANDLE)0;
+    if(name==0)
+	return (HANDLE)0;
+    for(p=fm; p; p=p->prev)
+    {
+	if(p->name==0)
+	    continue;
+	if(strcmp(p->name, name)==0)
+	    return p->handle;
+    }
+    return 0;	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/loader.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,286 @@
+/********************************************************
+
+	Win32 binary loader interface
+	Copyright 2000 Eugene Smith (divx@euro.ru)
+	Shamelessly stolen from Wine project
+
+*********************************************************/
+
+#ifndef _LOADER_H
+#define _LOADER_H
+#include <wine/windef.h>
+#include <wine/driver.h>
+#include <wine/mmreg.h>
+#include <wine/vfw.h>
+#include <wine/msacm.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void SetCodecPath(const char* path);
+unsigned int _GetPrivateProfileIntA(const char* appname, const char* keyname, int default_value, const char* filename);
+int _GetPrivateProfileStringA(const char* appname, const char* keyname,
+	const char* def_val, char* dest, unsigned int len, const char* filename);
+int _WritePrivateProfileStringA(const char* appname, const char* keyname,
+	const char* string, const char* filename);
+
+
+/**********************************************
+
+    MS VFW ( Video For Windows ) interface
+	    
+**********************************************/	    
+
+long VFWAPIV ICCompress(
+	HIC hic,long dwFlags,LPBITMAPINFOHEADER lpbiOutput,void* lpData,
+	LPBITMAPINFOHEADER lpbiInput,void* lpBits,long* lpckid,
+	long* lpdwFlags,long lFrameNum,long dwFrameSize,long dwQuality,
+	LPBITMAPINFOHEADER lpbiPrev,void* lpPrev
+);
+
+long VFWAPIV ICDecompress(HIC hic,long dwFlags,LPBITMAPINFOHEADER lpbiFormat,void* lpData,LPBITMAPINFOHEADER lpbi,void* lpBits);
+
+WIN_BOOL	VFWAPI	ICInfo(long fccType, long fccHandler, ICINFO * lpicinfo);
+LRESULT	VFWAPI	ICGetInfo(HIC hic,ICINFO *picinfo, long cb);
+HIC	VFWAPI	ICOpen(long fccType, long fccHandler, UINT wMode);
+HIC	VFWAPI	ICOpenFunction(long fccType, long fccHandler, unsigned int wMode, void* lpfnHandler);
+
+LRESULT VFWAPI ICClose(HIC hic);
+LRESULT	VFWAPI ICSendMessage(HIC hic, unsigned int msg, long dw1, long dw2);
+HIC	VFWAPI ICLocate(long fccType, long fccHandler, LPBITMAPINFOHEADER lpbiIn, LPBITMAPINFOHEADER lpbiOut, short wFlags);
+
+int VFWAPI ICDoSomething();
+
+#define ICCompressGetFormat(hic, lpbiInput, lpbiOutput) 		\
+	ICSendMessage(							\
+	    hic,ICM_COMPRESS_GET_FORMAT,(long)(void*)(lpbiInput),	\
+	    (long)(void*)(lpbiOutput)					\
+	)
+
+#define ICCompressGetFormatSize(hic,lpbi) ICCompressGetFormat(hic,lpbi,NULL)
+
+#define ICGetDefaultKeyFrameRate(hic,lpint) 		\
+	ICSendMessage(					\
+	    hic, ICM_GETDEFAULTKEYFRAMERATE,		\
+	    (long)(void*)(lpint), 			\
+	    0	)		
+
+#define ICGetDefaultQuality(hic,lpint) 			\
+	ICSendMessage(					\
+	    hic, ICM_GETDEFAULTQUALITY,			\
+	    (long)(void*)(lpint), 			\
+	    0	)		
+	    	
+
+#define ICCompressBegin(hic, lpbiInput, lpbiOutput) 			\
+    ICSendMessage(							\
+    	hic, ICM_COMPRESS_BEGIN, (long)(void*)(lpbiInput),		\
+	(long)(void*)(lpbiOutput)					\
+    )
+
+#define ICCompressGetSize(hic, lpbiInput, lpbiOutput) 		\
+    ICSendMessage(							\
+    	hic, ICM_COMPRESS_GET_SIZE, (long)(void*)(lpbiInput), 	\
+	(long)(void*)(lpbiOutput)					\
+    )
+
+#define ICCompressQuery(hic, lpbiInput, lpbiOutput)		\
+    ICSendMessage(						\
+    	hic, ICM_COMPRESS_QUERY, (long)(void*)(lpbiInput),	\
+	(long)(void*)(lpbiOutput)				\
+    )
+
+
+#define ICCompressEnd(hic) ICSendMessage(hic, ICM_COMPRESS_END, 0, 0)
+
+
+
+#define ICDecompressBegin(hic, lpbiInput, lpbiOutput) 	\
+    ICSendMessage(						\
+    	hic, ICM_DECOMPRESS_BEGIN, (long)(void*)(lpbiInput),	\
+	(long)(void*)(lpbiOutput)				\
+    )
+
+#define ICDecompressQuery(hic, lpbiInput, lpbiOutput) 	\
+    ICSendMessage(						\
+    	hic,ICM_DECOMPRESS_QUERY, (long)(void*)(lpbiInput),	\
+	(long) (void*)(lpbiOutput)				\
+    )
+
+#define ICDecompressGetFormat(hic, lpbiInput, lpbiOutput)		\
+    ((long)ICSendMessage(						\
+    	hic,ICM_DECOMPRESS_GET_FORMAT, (long)(void*)(lpbiInput),	\
+	(long)(void*)(lpbiOutput)					\
+    ))
+
+#define ICDecompressGetFormatSize(hic, lpbi) 				\
+	ICDecompressGetFormat(hic, lpbi, NULL)
+
+#define ICDecompressGetPalette(hic, lpbiInput, lpbiOutput)		\
+    ICSendMessage(							\
+    	hic, ICM_DECOMPRESS_GET_PALETTE, (long)(void*)(lpbiInput), 	\
+	(long)(void*)(lpbiOutput)					\
+    )
+
+#define ICDecompressSetPalette(hic,lpbiPalette)	\
+        ICSendMessage(				\
+		hic,ICM_DECOMPRESS_SET_PALETTE,		\
+		(long)(void*)(lpbiPalette),0		\
+	)
+
+#define ICDecompressEnd(hic) ICSendMessage(hic, ICM_DECOMPRESS_END, 0, 0)
+
+
+/*****************************************************
+
+    MS ACM ( Audio Compression Manager ) interface
+	    
+******************************************************/	    
+
+
+MMRESULT WINAPI acmDriverAddA(
+  PHACMDRIVERID phadid, HINSTANCE hinstModule,
+  LPARAM lParam, DWORD dwPriority, DWORD fdwAdd
+);
+MMRESULT WINAPI acmDriverAddW(
+  PHACMDRIVERID phadid, HINSTANCE hinstModule,
+  LPARAM lParam, DWORD dwPriority, DWORD fdwAdd
+);
+MMRESULT WINAPI acmDriverClose(
+  HACMDRIVER had, DWORD fdwClose
+);
+MMRESULT WINAPI acmDriverDetailsA(
+  HACMDRIVERID hadid, PACMDRIVERDETAILSA padd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmDriverDetailsW(
+  HACMDRIVERID hadid, PACMDRIVERDETAILSW padd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmDriverEnum(
+  ACMDRIVERENUMCB fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT WINAPI acmDriverID(
+  HACMOBJ hao, PHACMDRIVERID phadid, DWORD fdwDriverID
+);
+LRESULT WINAPI acmDriverMessage(
+  HACMDRIVER had, UINT uMsg, LPARAM lParam1, LPARAM lParam2
+);
+MMRESULT WINAPI acmDriverOpen(
+  PHACMDRIVER phad, HACMDRIVERID hadid, DWORD fdwOpen
+);
+MMRESULT WINAPI acmDriverPriority(
+  HACMDRIVERID hadid, DWORD dwPriority, DWORD fdwPriority
+);
+MMRESULT WINAPI acmDriverRemove(
+  HACMDRIVERID hadid, DWORD fdwRemove
+);
+MMRESULT WINAPI acmFilterChooseA(
+  PACMFILTERCHOOSEA pafltrc
+);
+MMRESULT WINAPI acmFilterChooseW(
+  PACMFILTERCHOOSEW pafltrc
+);
+MMRESULT WINAPI acmFilterDetailsA(
+  HACMDRIVER had, PACMFILTERDETAILSA pafd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmFilterDetailsW(
+  HACMDRIVER had, PACMFILTERDETAILSW pafd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmFilterEnumA(
+  HACMDRIVER had, PACMFILTERDETAILSA pafd, 
+  ACMFILTERENUMCBA fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT WINAPI acmFilterEnumW(
+  HACMDRIVER had, PACMFILTERDETAILSW pafd, 
+  ACMFILTERENUMCBW fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT WINAPI acmFilterTagDetailsA(
+  HACMDRIVER had, PACMFILTERTAGDETAILSA paftd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmFilterTagDetailsW(
+  HACMDRIVER had, PACMFILTERTAGDETAILSW paftd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmFilterTagEnumA(
+  HACMDRIVER had, PACMFILTERTAGDETAILSA paftd,
+  ACMFILTERTAGENUMCBA fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT WINAPI acmFilterTagEnumW(
+  HACMDRIVER had, PACMFILTERTAGDETAILSW paftd,
+  ACMFILTERTAGENUMCBW fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT WINAPI acmFormatChooseA(
+  PACMFORMATCHOOSEA pafmtc
+);
+MMRESULT WINAPI acmFormatChooseW(
+  PACMFORMATCHOOSEW pafmtc
+);
+MMRESULT WINAPI acmFormatDetailsA(
+  HACMDRIVER had, PACMFORMATDETAILSA pafd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmFormatDetailsW(
+  HACMDRIVER had, PACMFORMATDETAILSW pafd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmFormatEnumA(
+  HACMDRIVER had, PACMFORMATDETAILSA pafd,
+  ACMFORMATENUMCBA fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT WINAPI acmFormatEnumW(
+  HACMDRIVER had, PACMFORMATDETAILSW pafd,
+  ACMFORMATENUMCBW fnCallback, DWORD dwInstance,  DWORD fdwEnum
+);
+MMRESULT WINAPI acmFormatSuggest(
+  HACMDRIVER had, PWAVEFORMATEX pwfxSrc, PWAVEFORMATEX pwfxDst,
+  DWORD cbwfxDst, DWORD fdwSuggest
+);
+MMRESULT WINAPI acmFormatTagDetailsA(
+  HACMDRIVER had, PACMFORMATTAGDETAILSA paftd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmFormatTagDetailsW(
+  HACMDRIVER had, PACMFORMATTAGDETAILSW paftd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmFormatTagEnumA(
+  HACMDRIVER had, PACMFORMATTAGDETAILSA paftd,
+  ACMFORMATTAGENUMCBA fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT WINAPI acmFormatTagEnumW(
+  HACMDRIVER had, PACMFORMATTAGDETAILSW paftd,
+  ACMFORMATTAGENUMCBW fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+DWORD WINAPI acmGetVersion(
+);
+MMRESULT WINAPI acmMetrics(
+  HACMOBJ hao, UINT  uMetric, LPVOID  pMetric
+);
+MMRESULT WINAPI acmStreamClose(
+  HACMSTREAM has, DWORD fdwClose
+);
+MMRESULT WINAPI acmStreamConvert(
+  HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwConvert
+);
+MMRESULT WINAPI acmStreamMessage(
+  HACMSTREAM has, UINT uMsg, LPARAM lParam1, LPARAM lParam2
+);
+MMRESULT WINAPI acmStreamOpen(
+  PHACMSTREAM phas, HACMDRIVER had, PWAVEFORMATEX pwfxSrc,
+  PWAVEFORMATEX pwfxDst, PWAVEFILTER pwfltr, DWORD dwCallback,
+  DWORD dwInstance, DWORD fdwOpen
+);
+MMRESULT WINAPI acmStreamPrepareHeader(
+  HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwPrepare
+);
+MMRESULT WINAPI acmStreamReset(
+  HACMSTREAM has, DWORD fdwReset
+);
+MMRESULT WINAPI acmStreamSize(
+  HACMSTREAM has, DWORD cbInput, 
+  LPDWORD pdwOutputBytes, DWORD fdwSize
+);
+MMRESULT WINAPI acmStreamUnprepareHeader(
+  HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwUnprepare
+);
+void MSACM_RegisterAllDrivers(void);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __LOADER_H */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/module.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,618 @@
+/*
+ * Modules
+ *
+ * Copyright 1995 Alexandre Julliard
+ */
+#include <config.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+#include <sys/types.h>
+/*
+#ifdef __linux__
+#include <asm/unistd.h>
+#include <asm/ldt.h>
+#else
+#define LDT_ENTRIES     8192
+#define LDT_ENTRY_SIZE  8
+
+struct modify_ldt_ldt_s {
+        unsigned int  entry_number;
+        unsigned long base_addr;
+        unsigned int  limit;
+        unsigned int  seg_32bit:1;
+        unsigned int  contents:2;
+        unsigned int  read_exec_only:1;
+        unsigned int  limit_in_pages:1;
+        unsigned int  seg_not_present:1;
+        unsigned int  useable:1;
+};
+
+#define MODIFY_LDT_CONTENTS_DATA        0
+#define MODIFY_LDT_CONTENTS_STACK       1
+#define MODIFY_LDT_CONTENTS_CODE        2
+#define __NR_modify_ldt         123
+#endif
+
+*/
+#include <wine/windef.h>
+#include <wine/winerror.h>
+#include <wine/heap.h>
+#include <wine/module.h>
+#include <wine/pe_image.h>
+#include <wine/debugtools.h>
+
+struct modref_list_t;
+
+typedef struct modref_list_t
+{
+    WINE_MODREF* wm;
+    struct modref_list_t *next;
+    struct modref_list_t *prev;    
+}
+modref_list;
+
+
+/***********************************************************************
+ *           LDT_EntryToBytes
+ *
+ * Convert an ldt_entry structure to the raw bytes of the descriptor.
+ */
+/*static void LDT_EntryToBytes( unsigned long *buffer, const struct modify_ldt_ldt_s *content )
+{
+    *buffer++ = ((content->base_addr & 0x0000ffff) << 16) |
+                 (content->limit & 0x0ffff);
+    *buffer = (content->base_addr & 0xff000000) |
+              ((content->base_addr & 0x00ff0000)>>16) |
+              (content->limit & 0xf0000) |
+              (content->contents << 10) |
+              ((content->read_exec_only == 0) << 9) |
+              ((content->seg_32bit != 0) << 22) |
+              ((content->limit_in_pages != 0) << 23) |
+              0xf000;
+}
+*/
+
+//
+// funcs:
+//
+// 0 read LDT
+// 1 write old mode
+// 0x11 write
+//
+/*
+static int modify_ldt( int func, struct modify_ldt_ldt_s *ptr,
+                                  unsigned long count )
+{
+    int res;
+#ifdef __PIC__
+    __asm__ __volatile__( "pushl %%ebx\n\t"
+                          "movl %2,%%ebx\n\t"
+                          "int $0x80\n\t"
+                          "popl %%ebx"
+                          : "=a" (res)
+                          : "0" (__NR_modify_ldt),
+                            "r" (func),
+                            "c" (ptr),
+                            "d" (sizeof(struct modify_ldt_ldt_s)*count) );
+#else
+    __asm__ __volatile__("int $0x80"
+                         : "=a" (res)
+                         : "0" (__NR_modify_ldt),
+                           "b" (func),
+                           "c" (ptr),
+                           "d" (sizeof(struct modify_ldt_ldt_s)*count) );
+#endif  
+    if (res >= 0) return res;
+    errno = -res;
+    return -1;
+}
+static int fs_installed=0;
+static char* fs_seg=0;
+static int install_fs()
+{
+    struct modify_ldt_ldt_s array;
+    int fd;
+    int ret;
+    void* prev_struct;
+    
+    if(fs_installed)
+	return 0;
+
+    fd=open("/dev/zero", O_RDWR);
+    fs_seg=mmap((void*)0xbf000000, 0x30000, PROT_READ | PROT_WRITE, MAP_PRIVATE,
+	fd, 0);
+    if(fs_seg==0)
+    {
+	printf("ERROR: Couldn't allocate memory for fs segment\n");
+	return -1;
+    }	
+    array.base_addr=((int)fs_seg+0xffff) & 0xffff0000;
+    array.entry_number=0x1;
+    array.limit=array.base_addr+getpagesize()-1;
+    array.seg_32bit=1;
+    array.read_exec_only=0;
+    array.seg_not_present=0;
+    array.contents=MODIFY_LDT_CONTENTS_DATA;
+    array.limit_in_pages=0;
+#ifdef linux
+    ret=modify_ldt(0x1, &array, 1);
+    if(ret<0)
+    {
+	perror("install_fs");
+	MESSAGE("Couldn't install fs segment, expect segfault\n");
+    }	
+#endif 
+
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+    {
+        long d[2];
+
+        LDT_EntryToBytes( d, &array );
+        ret = i386_set_ldt(0x1, (union descriptor *)d, 1);
+        if (ret < 0)
+        {
+            perror("install_fs");
+            MESSAGE("Did you reconfigure the kernel with \"options USER_LDT\"?\n");
+        }
+    }
+#endif 
+    __asm__
+    (
+    "movl $0xf,%eax\n\t"
+//    "pushw %ax\n\t"
+    "movw %ax, %fs\n\t"
+    );
+    prev_struct=malloc(8);
+    *(void**)array.base_addr=prev_struct;
+    printf("prev_struct: 0x%X\n", prev_struct);
+    close(fd);
+    
+    fs_installed=1;
+    return 0;
+};    	
+static int uninstall_fs()
+{
+    printf("Uninstalling FS segment\n");
+    if(fs_seg==0)
+	return -1;
+    munmap(fs_seg, 0x30000);
+    fs_installed=0;
+    return 0;
+}
+
+*/
+//WINE_MODREF *local_wm=NULL;
+modref_list* local_wm=NULL;
+
+WINE_MODREF *MODULE_FindModule(LPCSTR m)
+{
+    modref_list* list=local_wm;
+    TRACE("Module %s request\n", m);
+    if(list==NULL)
+	return NULL;
+    while(strcmp(m, list->wm->filename))
+    {
+//	printf("%s: %x\n", list->wm->filename, list->wm->module);
+	list=list->prev;
+	if(list==NULL)
+	    return NULL;
+    }	
+    TRACE("Resolved to %s\n", list->wm->filename);
+    return list->wm;
+}    
+
+void MODULE_RemoveFromList(WINE_MODREF *mod)
+{
+    modref_list* list=local_wm;
+    if(list==0)
+	return;
+    if(mod==0)
+	return;
+    if((list->prev==NULL)&&(list->next==NULL))
+    {
+	free(list);
+	local_wm=NULL;
+//	uninstall_fs();
+	return;
+    }
+    for(;list;list=list->prev)
+    {
+	if(list->wm==mod)
+	{
+	    if(list->prev)
+		list->prev->next=list->next;
+	    if(list->next)
+		list->next->prev=list->prev;
+	    if(list==local_wm)
+		local_wm=list->prev;
+	    free(list);
+	    return;
+	}
+    }
+}    		    	
+		
+WINE_MODREF *MODULE32_LookupHMODULE(HMODULE m)
+{
+    modref_list* list=local_wm;
+    TRACE("Module %X request\n", m);
+    if(list==NULL)
+	return NULL;
+    while(m!=list->wm->module)
+    {
+//      printf("Checking list %X wm %X module %X\n",
+//	list, list->wm, list->wm->module);
+	list=list->prev;
+	if(list==NULL)
+	    return NULL;
+    }	
+    TRACE("LookupHMODULE hit %X\n", list->wm);
+    return list->wm;
+}    
+
+/*************************************************************************
+ *		MODULE_InitDll
+ */
+static WIN_BOOL MODULE_InitDll( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
+{
+    WIN_BOOL retv = TRUE;
+
+    static LPCSTR typeName[] = { "PROCESS_DETACH", "PROCESS_ATTACH", 
+                                 "THREAD_ATTACH", "THREAD_DETACH" };
+    assert( wm );
+
+
+    /* Skip calls for modules loaded with special load flags */
+
+    if (    ( wm->flags & WINE_MODREF_DONT_RESOLVE_REFS )
+         || ( wm->flags & WINE_MODREF_LOAD_AS_DATAFILE ) )
+        return TRUE;
+
+
+    TRACE("(%s,%s,%p) - CALL\n", wm->modname, typeName[type], lpReserved );
+
+    /* Call the initialization routine */
+    switch ( wm->type )
+    {
+    case MODULE32_PE:
+        retv = PE_InitDLL( wm, type, lpReserved );
+        break;
+
+    case MODULE32_ELF:
+        /* no need to do that, dlopen() already does */
+        break;
+
+    default:
+        ERR("wine_modref type %d not handled.\n", wm->type );
+        retv = FALSE;
+        break;
+    }
+
+    /* The state of the module list may have changed due to the call
+       to PE_InitDLL. We cannot assume that this module has not been
+       deleted.  */
+    TRACE("(%p,%s,%p) - RETURN %d\n", wm, typeName[type], lpReserved, retv );
+
+    return retv;
+}
+
+/*************************************************************************
+ *		MODULE_DllProcessAttach
+ * 
+ * Send the process attach notification to all DLLs the given module
+ * depends on (recursively). This is somewhat complicated due to the fact that
+ *
+ * - we have to respect the module dependencies, i.e. modules implicitly
+ *   referenced by another module have to be initialized before the module
+ *   itself can be initialized
+ * 
+ * - the initialization routine of a DLL can itself call LoadLibrary,
+ *   thereby introducing a whole new set of dependencies (even involving
+ *   the 'old' modules) at any time during the whole process
+ *
+ * (Note that this routine can be recursively entered not only directly
+ *  from itself, but also via LoadLibrary from one of the called initialization
+ *  routines.)
+ *
+ * Furthermore, we need to rearrange the main WINE_MODREF list to allow
+ * the process *detach* notifications to be sent in the correct order.
+ * This must not only take into account module dependencies, but also 
+ * 'hidden' dependencies created by modules calling LoadLibrary in their
+ * attach notification routine.
+ *
+ * The strategy is rather simple: we move a WINE_MODREF to the head of the
+ * list after the attach notification has returned.  This implies that the
+ * detach notifications are called in the reverse of the sequence the attach
+ * notifications *returned*.
+ *
+ * NOTE: Assumes that the process critical section is held!
+ *
+ */
+WIN_BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved )
+{
+    WIN_BOOL retv = TRUE;
+    int i;
+    assert( wm );
+
+    /* prevent infinite recursion in case of cyclical dependencies */
+    if (    ( wm->flags & WINE_MODREF_MARKER )
+         || ( wm->flags & WINE_MODREF_PROCESS_ATTACHED ) )
+        return retv;
+
+    TRACE("(%s,%p) - START\n", wm->modname, lpReserved );
+
+    /* Tag current MODREF to prevent recursive loop */
+    wm->flags |= WINE_MODREF_MARKER;
+
+    /* Recursively attach all DLLs this one depends on */
+/*    for ( i = 0; retv && i < wm->nDeps; i++ )
+        if ( wm->deps[i] )
+            retv = MODULE_DllProcessAttach( wm->deps[i], lpReserved );
+*/
+    /* Call DLL entry point */
+
+    //local_wm=wm;
+    if(local_wm)
+    {
+        local_wm->next=malloc(sizeof(modref_list));
+        local_wm->next->prev=local_wm;
+        local_wm->next->next=NULL;
+        local_wm->next->wm=wm;
+        local_wm=local_wm->next;
+    }
+    else
+    {
+	local_wm=malloc(sizeof(modref_list));
+	local_wm->next=local_wm->prev=NULL;
+	local_wm->wm=wm;
+    }		
+    /* Remove recursion flag */
+    wm->flags &= ~WINE_MODREF_MARKER;
+    
+    if ( retv )
+    {
+        retv = MODULE_InitDll( wm, DLL_PROCESS_ATTACH, lpReserved );
+        if ( retv )
+            wm->flags |= WINE_MODREF_PROCESS_ATTACHED;
+    }
+
+
+    TRACE("(%s,%p) - END\n", wm->modname, lpReserved );
+
+    return retv;
+}
+
+/*************************************************************************
+ *		MODULE_DllProcessDetach
+ * 
+ * Send DLL process detach notifications.  See the comment about calling 
+ * sequence at MODULE_DllProcessAttach.  Unless the bForceDetach flag
+ * is set, only DLLs with zero refcount are notified.
+ */
+void MODULE_DllProcessDetach( WINE_MODREF* wm, WIN_BOOL bForceDetach, LPVOID lpReserved )
+{
+//    WINE_MODREF *wm=local_wm;
+    wm->flags &= ~WINE_MODREF_PROCESS_ATTACHED;
+    MODULE_InitDll( wm, DLL_PROCESS_DETACH, lpReserved );
+}
+
+
+/***********************************************************************
+ *           LoadLibraryExA   (KERNEL32)
+ */
+HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags)
+{
+	WINE_MODREF *wm;
+
+	if(!libname)
+	{
+		SetLastError(ERROR_INVALID_PARAMETER);
+		return 0;
+	}
+//	if(fs_installed==0)
+//	    install_fs();
+	    
+
+	wm = MODULE_LoadLibraryExA( libname, hfile, flags );
+	if ( wm )
+	{
+		if ( !MODULE_DllProcessAttach( wm, NULL ) )
+		{
+			WARN_(module)("Attach failed for module '%s', \n", libname);
+			MODULE_FreeLibrary(wm);
+			SetLastError(ERROR_DLL_INIT_FAILED);
+			MODULE_RemoveFromList(wm);
+			wm = NULL;
+		}
+	}
+
+	return wm ? wm->module : 0;
+}
+
+
+/***********************************************************************
+ *	MODULE_LoadLibraryExA	(internal)
+ *
+ * Load a PE style module according to the load order.
+ *
+ * The HFILE parameter is not used and marked reserved in the SDK. I can
+ * only guess that it should force a file to be mapped, but I rather
+ * ignore the parameter because it would be extremely difficult to
+ * integrate this with different types of module represenations.
+ *
+ */
+WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags )
+{
+	DWORD err = GetLastError();
+	WINE_MODREF *pwm;
+	int i;
+//	module_loadorder_t *plo;
+
+
+        SetLastError( ERROR_FILE_NOT_FOUND );
+	TRACE("Trying native dll '%s'\n", libname);
+	pwm = PE_LoadLibraryExA(libname, flags);
+#ifdef HAVE_LIBDL
+	if(!pwm)
+	{
+    	    TRACE("Trying ELF dll '%s'\n", libname);
+	    pwm=(WINE_MODREF*)ELFDLL_LoadLibraryExA(libname, flags);
+	}	
+#endif	
+//		printf("0x%08x\n", pwm);
+//		break;
+	if(pwm)
+	{
+		/* Initialize DLL just loaded */
+		TRACE("Loaded module '%s' at 0x%08x, \n", libname, pwm->module);
+		/* Set the refCount here so that an attach failure will */
+		/* decrement the dependencies through the MODULE_FreeLibrary call. */
+		pwm->refCount++;
+
+                SetLastError( err );  /* restore last error */
+		return pwm;
+	}
+
+	
+	WARN("Failed to load module '%s'; error=0x%08lx, \n", libname, GetLastError());
+	return NULL;
+}
+
+/***********************************************************************
+ *           LoadLibraryA         (KERNEL32)
+ */
+HMODULE WINAPI LoadLibraryA(LPCSTR libname) {
+	return LoadLibraryExA(libname,0,0);
+}
+
+
+/***********************************************************************
+ *           FreeLibrary
+ */
+WIN_BOOL WINAPI FreeLibrary(HINSTANCE hLibModule)
+{
+    WIN_BOOL retv = FALSE;
+    WINE_MODREF *wm;
+
+    wm=MODULE32_LookupHMODULE(hLibModule);
+//    wm=local_wm;
+
+    if ( !wm || !hLibModule )
+    {
+        SetLastError( ERROR_INVALID_HANDLE );
+	return 0;
+    }	
+    else
+        retv = MODULE_FreeLibrary( wm );
+    
+    MODULE_RemoveFromList(wm);
+
+    return retv;
+}
+
+/***********************************************************************
+ *           MODULE_DecRefCount
+ *
+ * NOTE: Assumes that the process critical section is held!
+ */
+static void MODULE_DecRefCount( WINE_MODREF *wm )
+{
+    int i;
+
+    if ( wm->flags & WINE_MODREF_MARKER )
+        return;
+
+    if ( wm->refCount <= 0 )
+        return;
+
+    --wm->refCount;
+    TRACE("(%s) refCount: %d\n", wm->modname, wm->refCount );
+
+    if ( wm->refCount == 0 )
+    {
+        wm->flags |= WINE_MODREF_MARKER;
+
+        for ( i = 0; i < wm->nDeps; i++ )
+            if ( wm->deps[i] )
+                MODULE_DecRefCount( wm->deps[i] );
+
+        wm->flags &= ~WINE_MODREF_MARKER;
+    }
+}
+
+/***********************************************************************
+ *           MODULE_FreeLibrary
+ *
+ * NOTE: Assumes that the process critical section is held!
+ */
+WIN_BOOL MODULE_FreeLibrary( WINE_MODREF *wm )
+{
+    TRACE("(%s) - START\n", wm->modname );
+
+    /* Recursively decrement reference counts */
+    //MODULE_DecRefCount( wm );
+
+    /* Call process detach notifications */
+    MODULE_DllProcessDetach( wm, FALSE, NULL );
+
+    PE_UnloadLibrary(wm);
+
+    TRACE("END\n");
+
+    return TRUE;
+}
+
+/***********************************************************************
+ *           GetProcAddress   		(KERNEL32.257)
+ */
+FARPROC WINAPI GetProcAddress( HMODULE hModule, LPCSTR function )
+{
+    return MODULE_GetProcAddress( hModule, function, TRUE );
+}
+
+/***********************************************************************
+ *           MODULE_GetProcAddress   		(internal)
+ */
+FARPROC MODULE_GetProcAddress( 
+	HMODULE hModule, 	/* [in] current module handle */
+	LPCSTR function,	/* [in] function to be looked up */
+	WIN_BOOL snoop )
+{
+    WINE_MODREF	*wm = MODULE32_LookupHMODULE( hModule );
+//    WINE_MODREF *wm=local_wm;    
+    FARPROC	retproc;
+
+    if (HIWORD(function))
+	TRACE_(win32)("(%08lx,%s)\n",(DWORD)hModule,function);
+    else
+	TRACE_(win32)("(%08lx,%p)\n",(DWORD)hModule,function);
+    if (!wm) {
+    	SetLastError(ERROR_INVALID_HANDLE);
+        return (FARPROC)0;
+    }
+    switch (wm->type)
+    {
+    case MODULE32_PE:
+     	retproc = PE_FindExportedFunction( wm, function, snoop );
+	if (!retproc) SetLastError(ERROR_PROC_NOT_FOUND);
+	return retproc;
+#ifdef HAVE_LIBDL	
+    case MODULE32_ELF:
+	retproc = (FARPROC) dlsym( wm->module, function);
+	if (!retproc) SetLastError(ERROR_PROC_NOT_FOUND);
+	return retproc;
+#endif
+    default:
+    	ERR("wine_modref type %d not handled.\n",wm->type);
+    	SetLastError(ERROR_INVALID_HANDLE);
+    	return (FARPROC)0;
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/pe_image.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,936 @@
+/* 
+ *  Copyright	1994	Eric Youndale & Erik Bos
+ *  Copyright	1995	Martin von Löwis
+ *  Copyright   1996-98 Marcus Meissner
+ *
+ *	based on Eric Youndale's pe-test and:
+ *
+ *	ftp.microsoft.com:/pub/developer/MSDN/CD8/PEFILE.ZIP
+ * make that:
+ *	ftp.microsoft.com:/developr/MSDN/OctCD/PEFILE.ZIP
+ */
+/* Notes:
+ * Before you start changing something in this file be aware of the following:
+ *
+ * - There are several functions called recursively. In a very subtle and 
+ *   obscure way. DLLs can reference each other recursively etc.
+ * - If you want to enhance, speed up or clean up something in here, think
+ *   twice WHY it is implemented in that strange way. There is usually a reason.
+ *   Though sometimes it might just be lazyness ;)
+ * - In PE_MapImage, right before fixup_imports() all external and internal 
+ *   state MUST be correct since this function can be called with the SAME image
+ *   AGAIN. (Thats recursion for you.) That means MODREF.module and
+ *   NE_MODULE.module32.
+ * - Sometimes, we can't use Linux mmap() to mmap() the images directly.
+ *
+ *   The problem is, that there is not direct 1:1 mapping from a diskimage and
+ *   a memoryimage. The headers at the start are mapped linear, but the sections
+ *   are not. Older x86 pe binaries are 512 byte aligned in file and 4096 byte
+ *   aligned in memory. Linux likes them 4096 byte aligned in memory (due to
+ *   x86 pagesize, this cannot be fixed without a rather large kernel rewrite)
+ *   and 'blocksize' file-aligned (offsets). Since we have 512/1024/2048 (CDROM)
+ *   and other byte blocksizes, we can't always do this.  We *can* do this for
+ *   newer pe binaries produced by MSVC 5 and later, since they are also aligned
+ *   to 4096 byte boundaries on disk.
+ */
+#include <config.h>
+#include <wine/config.h>
+
+#include <errno.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#ifdef HAVE_SYS_MMAN_H
+#include <sys/mman.h>
+#endif
+#include <wine/windef.h>
+#include <wine/winbase.h>
+#include <wine/winerror.h>
+#include <wine/heap.h>
+#include <wine/pe_image.h>
+#include <wine/module.h>
+#include <wine/debugtools.h>
+
+#include "win32.h"
+
+#define RVA(x) ((void *)((char *)load_addr+(unsigned int)(x)))
+
+#define AdjustPtr(ptr,delta) ((char *)(ptr) + (delta))
+
+extern void* LookupExternal(const char* library, int ordinal);
+extern void* LookupExternalByName(const char* library, const char* name);
+
+void dump_exports( HMODULE hModule )
+{ 
+  char		*Module;
+  int		i, j;
+  u_short	*ordinal;
+  u_long	*function,*functions;
+  u_char	**name;
+  unsigned int load_addr = hModule;
+
+  DWORD rva_start = PE_HEADER(hModule)->OptionalHeader
+                   .DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
+  DWORD rva_end = rva_start + PE_HEADER(hModule)->OptionalHeader
+                   .DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size;
+  IMAGE_EXPORT_DIRECTORY *pe_exports = (IMAGE_EXPORT_DIRECTORY*)RVA(rva_start);
+
+  Module = (char*)RVA(pe_exports->Name);
+  TRACE("*******EXPORT DATA*******\n");
+  TRACE("Module name is %s, %ld functions, %ld names\n", 
+        Module, pe_exports->NumberOfFunctions, pe_exports->NumberOfNames);
+
+  ordinal=(u_short*) RVA(pe_exports->AddressOfNameOrdinals);
+  functions=function=(u_long*) RVA(pe_exports->AddressOfFunctions);
+  name=(u_char**) RVA(pe_exports->AddressOfNames);
+
+  TRACE(" Ord    RVA     Addr   Name\n" );
+  for (i=0;i<pe_exports->NumberOfFunctions;i++, function++)
+  {
+      if (!*function) continue;  
+      if (TRACE_ON(win32))
+      {
+	DPRINTF( "%4ld %08lx %p", i + pe_exports->Base, *function, RVA(*function) );
+	
+	for (j = 0; j < pe_exports->NumberOfNames; j++)
+          if (ordinal[j] == i)
+          {
+              DPRINTF( "  %s", (char*)RVA(name[j]) );
+              break;
+          }
+	if ((*function >= rva_start) && (*function <= rva_end))
+	  DPRINTF(" (forwarded -> %s)", (char *)RVA(*function));
+	DPRINTF("\n");
+      }
+  }
+}
+
+/* Look up the specified function or ordinal in the exportlist:
+ * If it is a string:
+ * 	- look up the name in the Name list. 
+ *	- look up the ordinal with that index.
+ *	- use the ordinal as offset into the functionlist
+ * If it is a ordinal:
+ *	- use ordinal-pe_export->Base as offset into the functionlist
+ */
+FARPROC PE_FindExportedFunction( 
+	WINE_MODREF *wm,	
+	LPCSTR funcName,	
+        WIN_BOOL snoop )
+{
+	u_short				* ordinals;
+	u_long				* function;
+	u_char				** name, *ename = NULL;
+	int				i, ordinal;
+	PE_MODREF			*pem = &(wm->binfmt.pe);
+	IMAGE_EXPORT_DIRECTORY 		*exports = pem->pe_export;
+	unsigned int			load_addr = wm->module;
+	u_long				rva_start, rva_end, addr;
+	char				* forward;
+
+	if (HIWORD(funcName))
+		TRACE("(%s)\n",funcName);
+	else
+		TRACE("(%d)\n",(int)funcName);
+	if (!exports) {
+		/* Not a fatal problem, some apps do
+		 * GetProcAddress(0,"RegisterPenApp") which triggers this
+		 * case.
+		 */
+		WARN("Module %08x(%s)/MODREF %p doesn't have a exports table.\n",wm->module,wm->modname,pem);
+		return NULL;
+	}
+	ordinals= (u_short*)  RVA(exports->AddressOfNameOrdinals);
+	function= (u_long*)   RVA(exports->AddressOfFunctions);
+	name	= (u_char **) RVA(exports->AddressOfNames);
+	forward = NULL;
+	rva_start = PE_HEADER(wm->module)->OptionalHeader
+		.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
+	rva_end = rva_start + PE_HEADER(wm->module)->OptionalHeader
+		.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size;
+
+	if (HIWORD(funcName))
+        {
+            
+            int min = 0, max = exports->NumberOfNames - 1;
+            while (min <= max)
+            {
+                int res, pos = (min + max) / 2;
+                ename = RVA(name[pos]);
+                if (!(res = strcmp( ename, funcName )))
+                {
+                    ordinal = ordinals[pos];
+                    goto found;
+                }
+                if (res > 0) max = pos - 1;
+                else min = pos + 1;
+            }
+            
+            for (i = 0; i < exports->NumberOfNames; i++)
+            {
+                ename = RVA(name[i]);
+                if (!strcmp( ename, funcName ))
+                {
+                    ERR( "%s.%s required a linear search\n", wm->modname, funcName );
+                    ordinal = ordinals[i];
+                    goto found;
+                }
+            }
+            return NULL;
+	}
+        else  
+        {
+            ordinal = LOWORD(funcName) - exports->Base;
+            if (snoop && name)  
+            {
+                for (i = 0; i < exports->NumberOfNames; i++)
+                    if (ordinals[i] == ordinal)
+                    {
+                        ename = RVA(name[i]);
+                        break;
+                    }
+            }
+	}
+
+ found:
+        if (ordinal >= exports->NumberOfFunctions)
+        {
+            TRACE("	ordinal %ld out of range!\n", ordinal + exports->Base );
+            return NULL;
+        }
+        addr = function[ordinal];
+        if (!addr) return NULL;
+        if ((addr < rva_start) || (addr >= rva_end))
+        {
+            FARPROC proc = RVA(addr);
+            if (snoop)
+            {
+                if (!ename) ename = "@";
+//                proc = SNOOP_GetProcAddress(wm->module,ename,ordinal,proc);
+		TRACE("SNOOP_GetProcAddress n/a\n");
+		
+            }
+            return proc;
+        }
+        else  
+        {
+                WINE_MODREF *wm;
+                char *forward = RVA(addr);
+		char module[256];
+		char *end = strchr(forward, '.');
+
+		if (!end) return NULL;
+                if (end - forward >= sizeof(module)) return NULL;
+                memcpy( module, forward, end - forward );
+		module[end-forward] = 0;
+                if (!(wm = MODULE_FindModule( module )))
+                {
+                    ERR("module not found for forward '%s'\n", forward );
+                    return NULL;
+                }
+		return MODULE_GetProcAddress( wm->module, end + 1, snoop );
+	}
+}
+
+DWORD fixup_imports( WINE_MODREF *wm )
+{
+    IMAGE_IMPORT_DESCRIPTOR	*pe_imp;
+    PE_MODREF			*pem;
+    unsigned int load_addr	= wm->module;
+    int				i,characteristics_detection=1;
+    char			*modname;
+    
+    assert(wm->type==MODULE32_PE);
+    pem = &(wm->binfmt.pe);
+    if (pem->pe_export)
+    	modname = (char*) RVA(pem->pe_export->Name);
+    else
+        modname = "<unknown>";
+
+    
+    TRACE("Dumping imports list\n");
+
+    
+    pe_imp = pem->pe_import;
+    if (!pe_imp) return 0;
+
+    /* We assume that we have at least one import with !0 characteristics and
+     * detect broken imports with all characteristsics 0 (notably Borland) and
+     * switch the detection off for them.
+     */
+    for (i = 0; pe_imp->Name ; pe_imp++) {
+	if (!i && !pe_imp->u.Characteristics)
+		characteristics_detection = 0;
+	if (characteristics_detection && !pe_imp->u.Characteristics)
+		break;
+	i++;
+    }
+    if (!i) return 0;  
+
+    
+    wm->nDeps = i;
+    wm->deps  = HeapAlloc( GetProcessHeap(), 0, i*sizeof(WINE_MODREF *) );
+
+    /* load the imported modules. They are automatically 
+     * added to the modref list of the process.
+     */
+ 
+    for (i = 0, pe_imp = pem->pe_import; pe_imp->Name ; pe_imp++) {
+    	WINE_MODREF		*wmImp;
+	IMAGE_IMPORT_BY_NAME	*pe_name;
+	PIMAGE_THUNK_DATA	import_list,thunk_list;
+ 	char			*name = (char *) RVA(pe_imp->Name);
+
+	if (characteristics_detection && !pe_imp->u.Characteristics)
+		break;
+
+//#warning FIXME: here we should fill imports
+        TRACE("Loading imports for %s.dll\n", name);
+    
+	if (pe_imp->u.OriginalFirstThunk != 0) { 
+	    TRACE("Microsoft style imports used\n");
+	    import_list =(PIMAGE_THUNK_DATA) RVA(pe_imp->u.OriginalFirstThunk);
+	    thunk_list = (PIMAGE_THUNK_DATA) RVA(pe_imp->FirstThunk);
+
+	    while (import_list->u1.Ordinal) {
+		if (IMAGE_SNAP_BY_ORDINAL(import_list->u1.Ordinal)) {
+		    int ordinal = IMAGE_ORDINAL(import_list->u1.Ordinal);
+
+//		    TRACE("--- Ordinal %s,%d\n", name, ordinal);
+		    
+		    thunk_list->u1.Function=LookupExternal(
+		      name, ordinal);
+		} else {		
+		    pe_name = (PIMAGE_IMPORT_BY_NAME)RVA(import_list->u1.AddressOfData);
+//		    TRACE("--- %s %s.%d\n", pe_name->Name, name, pe_name->Hint);
+		    thunk_list->u1.Function=LookupExternalByName(
+		      name, pe_name->Name);
+		}
+		import_list++;
+		thunk_list++;
+	    }
+	} else {	
+	    TRACE("Borland style imports used\n");
+	    thunk_list = (PIMAGE_THUNK_DATA) RVA(pe_imp->FirstThunk);
+	    while (thunk_list->u1.Ordinal) {
+		if (IMAGE_SNAP_BY_ORDINAL(thunk_list->u1.Ordinal)) {
+		    
+		    int ordinal = IMAGE_ORDINAL(thunk_list->u1.Ordinal);
+
+		    TRACE("--- Ordinal %s.%d\n",name,ordinal);
+		    thunk_list->u1.Function=LookupExternal(
+		      name, ordinal);
+		} else {
+		    pe_name=(PIMAGE_IMPORT_BY_NAME) RVA(thunk_list->u1.AddressOfData);
+		    TRACE("--- %s %s.%d\n",
+		   		  pe_name->Name,name,pe_name->Hint);
+		    thunk_list->u1.Function=LookupExternalByName(
+		      name, pe_name->Name);
+		}
+		thunk_list++;
+	    }
+	}
+
+
+    }
+    return 0;
+}
+
+static int calc_vma_size( HMODULE hModule )
+{
+    int i,vma_size = 0;
+    IMAGE_SECTION_HEADER *pe_seg = PE_SECTIONS(hModule);
+
+    TRACE("Dump of segment table\n");
+    TRACE("   Name    VSz  Vaddr     SzRaw   Fileadr  *Reloc *Lineum #Reloc #Linum Char\n");
+    for (i = 0; i< PE_HEADER(hModule)->FileHeader.NumberOfSections; i++)
+    {
+        TRACE("%8s: %4.4lx %8.8lx %8.8lx %8.8lx %8.8lx %8.8lx %4.4x %4.4x %8.8lx\n", 
+                      pe_seg->Name, 
+                      pe_seg->Misc.VirtualSize,
+                      pe_seg->VirtualAddress,
+                      pe_seg->SizeOfRawData,
+                      pe_seg->PointerToRawData,
+                      pe_seg->PointerToRelocations,
+                      pe_seg->PointerToLinenumbers,
+                      pe_seg->NumberOfRelocations,
+                      pe_seg->NumberOfLinenumbers,
+                      pe_seg->Characteristics);
+        vma_size=max(vma_size, pe_seg->VirtualAddress+pe_seg->SizeOfRawData);
+        vma_size=max(vma_size, pe_seg->VirtualAddress+pe_seg->Misc.VirtualSize);
+        pe_seg++;
+    }
+    return vma_size;
+}
+
+static void do_relocations( unsigned int load_addr, IMAGE_BASE_RELOCATION *r )
+{
+    int delta = load_addr - PE_HEADER(load_addr)->OptionalHeader.ImageBase;
+    int	hdelta = (delta >> 16) & 0xFFFF;
+    int	ldelta = delta & 0xFFFF;
+
+	if(delta == 0)
+		
+		return;
+	while(r->VirtualAddress)
+	{
+		char *page = (char*) RVA(r->VirtualAddress);
+		int count = (r->SizeOfBlock - 8)/2;
+		int i;
+		TRACE_(fixup)("%x relocations for page %lx\n",
+			count, r->VirtualAddress);
+		
+		for(i=0;i<count;i++)
+		{
+			int offset = r->TypeOffset[i] & 0xFFF;
+			int type = r->TypeOffset[i] >> 12;
+//			TRACE_(fixup)("patching %x type %x\n", offset, type);
+			switch(type)
+			{
+			case IMAGE_REL_BASED_ABSOLUTE: break;
+			case IMAGE_REL_BASED_HIGH:
+				*(short*)(page+offset) += hdelta;
+				break;
+			case IMAGE_REL_BASED_LOW:
+				*(short*)(page+offset) += ldelta;
+				break;
+			case IMAGE_REL_BASED_HIGHLOW:
+				*(int*)(page+offset) += delta;
+				
+				break;
+			case IMAGE_REL_BASED_HIGHADJ:
+				FIXME("Don't know what to do with IMAGE_REL_BASED_HIGHADJ\n");
+				break;
+			case IMAGE_REL_BASED_MIPS_JMPADDR:
+				FIXME("Is this a MIPS machine ???\n");
+				break;
+			default:
+				FIXME("Unknown fixup type\n");
+				break;
+			}
+		}
+		r = (IMAGE_BASE_RELOCATION*)((char*)r + r->SizeOfBlock);
+	}
+}
+		
+
+	
+	
+
+/**********************************************************************
+ *			PE_LoadImage
+ * Load one PE format DLL/EXE into memory
+ * 
+ * Unluckily we can't just mmap the sections where we want them, for 
+ * (at least) Linux does only support offsets which are page-aligned.
+ *
+ * BUT we have to map the whole image anyway, for Win32 programs sometimes
+ * want to access them. (HMODULE32 point to the start of it)
+ */
+HMODULE PE_LoadImage( int handle, LPCSTR filename, WORD *version )
+{
+    HMODULE	hModule;
+    HANDLE	mapping;
+
+    IMAGE_NT_HEADERS *nt;
+    IMAGE_SECTION_HEADER *pe_sec;
+    IMAGE_DATA_DIRECTORY *dir;
+    BY_HANDLE_FILE_INFORMATION bhfi;
+    int	i, rawsize, lowest_va, vma_size, file_size = 0;
+    DWORD load_addr = 0, aoep, reloc = 0;
+//    struct get_read_fd_request *req = get_req_buffer();
+    int unix_handle = handle;
+    int page_size = getpagesize();
+
+    
+//    if ( GetFileInformationByHandle( hFile, &bhfi ) ) 
+//    	file_size = bhfi.nFileSizeLow; 
+    file_size=lseek(handle, 0, SEEK_END);
+    lseek(handle, 0, SEEK_SET);
+
+//#warning fix CreateFileMappingA
+    mapping = CreateFileMappingA( handle, NULL, PAGE_READONLY | SEC_COMMIT,
+                                    0, 0, NULL );
+    if (!mapping)
+    {
+        WARN("CreateFileMapping error %ld\n", GetLastError() );
+        return 0;
+    }
+//    hModule = (HMODULE)MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 0 );
+    hModule=(HMODULE)mapping;
+//    CloseHandle( mapping );
+    if (!hModule)
+    {
+        WARN("MapViewOfFile error %ld\n", GetLastError() );
+        return 0;
+    }
+    if ( *(WORD*)hModule !=IMAGE_DOS_SIGNATURE)
+    {
+        WARN("%s image doesn't have DOS signature, but 0x%04x\n", filename,*(WORD*)hModule);
+        goto error;
+    }
+
+    nt = PE_HEADER( hModule );
+
+    
+    if ( nt->Signature != IMAGE_NT_SIGNATURE )
+    {
+        WARN("%s image doesn't have PE signature, but 0x%08lx\n", filename, nt->Signature );
+        goto error;
+    }
+
+    
+    if ( nt->FileHeader.Machine != IMAGE_FILE_MACHINE_I386 )
+    {
+        MESSAGE("Trying to load PE image for unsupported architecture (");
+        switch (nt->FileHeader.Machine)
+        {
+        case IMAGE_FILE_MACHINE_UNKNOWN: MESSAGE("Unknown"); break;
+        case IMAGE_FILE_MACHINE_I860:    MESSAGE("I860"); break;
+        case IMAGE_FILE_MACHINE_R3000:   MESSAGE("R3000"); break;
+        case IMAGE_FILE_MACHINE_R4000:   MESSAGE("R4000"); break;
+        case IMAGE_FILE_MACHINE_R10000:  MESSAGE("R10000"); break;
+        case IMAGE_FILE_MACHINE_ALPHA:   MESSAGE("Alpha"); break;
+        case IMAGE_FILE_MACHINE_POWERPC: MESSAGE("PowerPC"); break;
+        default: MESSAGE("Unknown-%04x", nt->FileHeader.Machine); break;
+        }
+        MESSAGE(")\n");
+        goto error;
+    }
+
+    
+    pe_sec = PE_SECTIONS( hModule );
+    rawsize = 0; lowest_va = 0x10000;
+    for (i = 0; i < nt->FileHeader.NumberOfSections; i++) 
+    {
+        if (lowest_va > pe_sec[i].VirtualAddress)
+           lowest_va = pe_sec[i].VirtualAddress;
+    	if (pe_sec[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
+	    continue;
+	if (pe_sec[i].PointerToRawData+pe_sec[i].SizeOfRawData > rawsize)
+	    rawsize = pe_sec[i].PointerToRawData+pe_sec[i].SizeOfRawData;
+    }
+ 
+    
+    if ( file_size && file_size < rawsize )
+    {
+        ERR("PE module is too small (header: %d, filesize: %d), "
+                    "probably truncated download?\n", 
+                    rawsize, file_size );
+        goto error;
+    }
+
+    
+    aoep = nt->OptionalHeader.AddressOfEntryPoint;
+    if (aoep && (aoep < lowest_va))
+        FIXME("VIRUS WARNING: '%s' has an invalid entrypoint (0x%08lx) "
+                      "below the first virtual address (0x%08x) "
+                      "(possibly infected by Tchernobyl/SpaceFiller virus)!\n",
+                       filename, aoep, lowest_va );
+
+
+    /* FIXME:  Hack!  While we don't really support shared sections yet,
+     *         this checks for those special cases where the whole DLL
+     *         consists only of shared sections and is mapped into the
+     *         shared address space > 2GB.  In this case, we assume that
+     *         the module got mapped at its base address. Thus we simply
+     *         check whether the module has actually been mapped there
+     *         and use it, if so.  This is needed to get Win95 USER32.DLL
+     *         to work (until we support shared sections properly).
+     */
+
+    if ( nt->OptionalHeader.ImageBase & 0x80000000 )
+    {
+        HMODULE sharedMod = (HMODULE)nt->OptionalHeader.ImageBase; 
+        IMAGE_NT_HEADERS *sharedNt = (PIMAGE_NT_HEADERS)
+               ( (LPBYTE)sharedMod + ((LPBYTE)nt - (LPBYTE)hModule) );
+
+        /* Well, this check is not really comprehensive, 
+           but should be good enough for now ... */
+        if (    !IsBadReadPtr( (LPBYTE)sharedMod, sizeof(IMAGE_DOS_HEADER) )
+             && memcmp( (LPBYTE)sharedMod, (LPBYTE)hModule, sizeof(IMAGE_DOS_HEADER) ) == 0
+             && !IsBadReadPtr( sharedNt, sizeof(IMAGE_NT_HEADERS) )
+             && memcmp( sharedNt, nt, sizeof(IMAGE_NT_HEADERS) ) == 0 )
+        {
+            UnmapViewOfFile( (LPVOID)hModule );
+            return sharedMod;
+        }
+    }
+
+
+    
+    load_addr = nt->OptionalHeader.ImageBase;
+    vma_size = calc_vma_size( hModule );
+
+    load_addr = (DWORD)VirtualAlloc( (void*)load_addr, vma_size,
+                                     MEM_RESERVE | MEM_COMMIT,
+                                     PAGE_EXECUTE_READWRITE );
+    if (load_addr == 0) 
+    {
+        
+        FIXME("We need to perform base relocations for %s\n", filename);
+	dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_BASERELOC;
+        if (dir->Size)
+            reloc = dir->VirtualAddress;
+        else 
+        {
+            FIXME( "FATAL: Need to relocate %s, but no relocation records present (%s). Try to run that file directly !\n",
+                   filename,
+                   (nt->FileHeader.Characteristics&IMAGE_FILE_RELOCS_STRIPPED)?
+                   "stripped during link" : "unknown reason" );
+            goto error;
+        }
+
+        /* FIXME: If we need to relocate a system DLL (base > 2GB) we should
+         *        really make sure that the *new* base address is also > 2GB.
+         *        Some DLLs really check the MSB of the module handle :-/
+         */
+        if ( nt->OptionalHeader.ImageBase & 0x80000000 )
+            ERR( "Forced to relocate system DLL (base > 2GB). This is not good.\n" );
+
+        load_addr = (DWORD)VirtualAlloc( NULL, vma_size,
+					 MEM_RESERVE | MEM_COMMIT,
+					 PAGE_EXECUTE_READWRITE );
+	if (!load_addr) {
+            FIXME_(win32)(
+                   "FATAL: Couldn't load module %s (out of memory, %d needed)!\n", filename, vma_size);
+            goto error;
+	}
+    }
+
+    TRACE("Load addr is %lx (base %lx), range %x\n",
+          load_addr, nt->OptionalHeader.ImageBase, vma_size );
+    TRACE_(segment)("Loading %s at %lx, range %x\n",
+                    filename, load_addr, vma_size );
+
+#if 0
+    
+    *(PIMAGE_DOS_HEADER)load_addr = *(PIMAGE_DOS_HEADER)hModule;
+    *PE_HEADER( load_addr ) = *nt;
+    memcpy( PE_SECTIONS(load_addr), PE_SECTIONS(hModule),
+            sizeof(IMAGE_SECTION_HEADER) * nt->FileHeader.NumberOfSections );
+
+    
+    memcpy( load_addr, hModule, lowest_fa );
+#endif
+
+    if ((void*)FILE_dommap( handle, (void *)load_addr, 0, nt->OptionalHeader.SizeOfHeaders,
+                     0, 0, PROT_EXEC | PROT_WRITE | PROT_READ,
+                     MAP_PRIVATE | MAP_FIXED ) != (void*)load_addr)
+    {
+        ERR_(win32)( "Critical Error: failed to map PE header to necessary address.\n");	
+        goto error;
+    }
+
+    
+    pe_sec = PE_SECTIONS( hModule );
+    for (i = 0; i < nt->FileHeader.NumberOfSections; i++, pe_sec++)
+    {
+        if (!pe_sec->SizeOfRawData || !pe_sec->PointerToRawData) continue;
+        TRACE("%s: mmaping section %s at %p off %lx size %lx/%lx\n",
+              filename, pe_sec->Name, (void*)RVA(pe_sec->VirtualAddress),
+              pe_sec->PointerToRawData, pe_sec->SizeOfRawData, pe_sec->Misc.VirtualSize );
+        if ((void*)FILE_dommap( unix_handle, (void*)RVA(pe_sec->VirtualAddress),
+                         0, pe_sec->SizeOfRawData, 0, pe_sec->PointerToRawData,
+                         PROT_EXEC | PROT_WRITE | PROT_READ,
+                         MAP_PRIVATE | MAP_FIXED ) != (void*)RVA(pe_sec->VirtualAddress))
+        {
+            
+            ERR_(win32)( "Critical Error: failed to map PE section to necessary address.\n");
+            goto error;
+        }
+        if ((pe_sec->SizeOfRawData < pe_sec->Misc.VirtualSize) &&
+            (pe_sec->SizeOfRawData & (page_size-1)))
+        {
+            DWORD end = (pe_sec->SizeOfRawData & ~(page_size-1)) + page_size;
+            if (end > pe_sec->Misc.VirtualSize) end = pe_sec->Misc.VirtualSize;
+            TRACE("clearing %p - %p\n",
+                  RVA(pe_sec->VirtualAddress) + pe_sec->SizeOfRawData,
+                  RVA(pe_sec->VirtualAddress) + end );
+            memset( (char*)RVA(pe_sec->VirtualAddress) + pe_sec->SizeOfRawData, 0,
+                    end - pe_sec->SizeOfRawData );
+        }
+    }
+
+    
+    if ( reloc )
+        do_relocations( load_addr, (IMAGE_BASE_RELOCATION *)RVA(reloc) );
+
+    
+    *version =   ( (nt->OptionalHeader.MajorSubsystemVersion & 0xff) << 8 )
+               |   (nt->OptionalHeader.MinorSubsystemVersion & 0xff);
+
+    
+    UnmapViewOfFile( (LPVOID)hModule );
+    return (HMODULE)load_addr;
+
+error:
+    if (unix_handle != -1) close( unix_handle );
+    if (load_addr) VirtualFree( (LPVOID)load_addr, 0, MEM_RELEASE );
+    UnmapViewOfFile( (LPVOID)hModule );
+    return 0;
+}
+
+/**********************************************************************
+ *                 PE_CreateModule
+ *
+ * Create WINE_MODREF structure for loaded HMODULE32, link it into
+ * process modref_list, and fixup all imports.
+ *
+ * Note: hModule must point to a correctly allocated PE image,
+ *       with base relocations applied; the 16-bit dummy module
+ *       associated to hModule must already exist.
+ *
+ * Note: This routine must always be called in the context of the
+ *       process that is to own the module to be created.
+ */
+WINE_MODREF *PE_CreateModule( HMODULE hModule, 
+                              LPCSTR filename, DWORD flags, WIN_BOOL builtin )
+{
+    DWORD load_addr = (DWORD)hModule;  
+    IMAGE_NT_HEADERS *nt = PE_HEADER(hModule);
+    IMAGE_DATA_DIRECTORY *dir;
+    IMAGE_IMPORT_DESCRIPTOR *pe_import = NULL;
+    IMAGE_EXPORT_DIRECTORY *pe_export = NULL;
+    IMAGE_RESOURCE_DIRECTORY *pe_resource = NULL;
+    WINE_MODREF *wm;
+    int	result;
+
+
+    
+
+    dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_EXPORT;
+    if (dir->Size)
+        pe_export = (PIMAGE_EXPORT_DIRECTORY)RVA(dir->VirtualAddress);
+
+    dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_IMPORT;
+    if (dir->Size)
+        pe_import = (PIMAGE_IMPORT_DESCRIPTOR)RVA(dir->VirtualAddress);
+
+    dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_RESOURCE;
+    if (dir->Size)
+        pe_resource = (PIMAGE_RESOURCE_DIRECTORY)RVA(dir->VirtualAddress);
+
+    dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_EXCEPTION;
+    if (dir->Size) FIXME("Exception directory ignored\n" );
+
+    dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_SECURITY;
+    if (dir->Size) FIXME("Security directory ignored\n" );
+
+    
+    
+
+    dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_DEBUG;
+    if (dir->Size) TRACE("Debug directory ignored\n" );
+
+    dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_COPYRIGHT;
+    if (dir->Size) FIXME("Copyright string ignored\n" );
+
+    dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_GLOBALPTR;
+    if (dir->Size) FIXME("Global Pointer (MIPS) ignored\n" );
+
+    
+
+    dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG;
+    if (dir->Size) FIXME("Load Configuration directory ignored\n" );
+
+    dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT;
+    if (dir->Size) TRACE("Bound Import directory ignored\n" );
+
+    dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_IAT;
+    if (dir->Size) TRACE("Import Address Table directory ignored\n" );
+
+    dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT;
+    if (dir->Size)
+    {
+		TRACE("Delayed import, stub calls LoadLibrary\n" );
+		/*
+		 * Nothing to do here.
+		 */
+
+#ifdef ImgDelayDescr
+		/*
+		 * This code is useful to observe what the heck is going on.
+		 */
+		{
+		ImgDelayDescr *pe_delay = NULL;
+        pe_delay = (PImgDelayDescr)RVA(dir->VirtualAddress);
+        TRACE_(delayhlp)("pe_delay->grAttrs = %08x\n", pe_delay->grAttrs);
+        TRACE_(delayhlp)("pe_delay->szName = %s\n", pe_delay->szName);
+        TRACE_(delayhlp)("pe_delay->phmod = %08x\n", pe_delay->phmod);
+        TRACE_(delayhlp)("pe_delay->pIAT = %08x\n", pe_delay->pIAT);
+        TRACE_(delayhlp)("pe_delay->pINT = %08x\n", pe_delay->pINT);
+        TRACE_(delayhlp)("pe_delay->pBoundIAT = %08x\n", pe_delay->pBoundIAT);
+        TRACE_(delayhlp)("pe_delay->pUnloadIAT = %08x\n", pe_delay->pUnloadIAT);
+        TRACE_(delayhlp)("pe_delay->dwTimeStamp = %08x\n", pe_delay->dwTimeStamp);
+        }
+#endif 
+	}
+
+    dir = nt->OptionalHeader.DataDirectory+IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR;
+    if (dir->Size) FIXME("Unknown directory 14 ignored\n" );
+
+    dir = nt->OptionalHeader.DataDirectory+15;
+    if (dir->Size) FIXME("Unknown directory 15 ignored\n" );
+
+
+    
+
+    wm = (WINE_MODREF *)HeapAlloc( GetProcessHeap(), 
+                                   HEAP_ZERO_MEMORY, sizeof(*wm) );
+    wm->module = hModule;
+
+    if ( builtin ) 
+        wm->flags |= WINE_MODREF_INTERNAL;
+    if ( flags & DONT_RESOLVE_DLL_REFERENCES )
+        wm->flags |= WINE_MODREF_DONT_RESOLVE_REFS;
+    if ( flags & LOAD_LIBRARY_AS_DATAFILE )
+        wm->flags |= WINE_MODREF_LOAD_AS_DATAFILE;
+
+    wm->type = MODULE32_PE;
+    wm->binfmt.pe.pe_export = pe_export;
+    wm->binfmt.pe.pe_import = pe_import;
+    wm->binfmt.pe.pe_resource = pe_resource;
+    wm->binfmt.pe.tlsindex = -1;
+
+    wm->filename = malloc(strlen(filename)+1);
+    strcpy(wm->filename, filename );
+    wm->modname = strrchr( wm->filename, '\\' );
+    if (!wm->modname) wm->modname = wm->filename;
+    else wm->modname++;
+
+    if ( pe_export )
+        dump_exports( hModule );
+
+    /* Fixup Imports */
+
+    if (    pe_import
+         && !( wm->flags & WINE_MODREF_LOAD_AS_DATAFILE )
+         && !( wm->flags & WINE_MODREF_DONT_RESOLVE_REFS ) 
+         && fixup_imports( wm ) ) 
+    {
+        /* remove entry from modref chain */
+         return NULL;
+    }
+
+    return wm;
+
+    return wm;
+}
+
+/******************************************************************************
+ * The PE Library Loader frontend. 
+ * FIXME: handle the flags.
+ */
+WINE_MODREF *PE_LoadLibraryExA (LPCSTR name, DWORD flags)
+{
+	HMODULE		hModule32;
+	WINE_MODREF	*wm;
+	char        	filename[256];
+	int hFile;
+	WORD		version = 0;
+
+	
+	strncpy(filename, name, sizeof(filename));      
+	hFile=open(filename, O_RDONLY);
+	if(hFile==-1)
+	    return NULL;
+	
+	
+	hModule32 = PE_LoadImage( hFile, filename, &version );
+	if (!hModule32)
+	{
+		SetLastError( ERROR_OUTOFMEMORY );	
+		return NULL;
+	}
+
+	if ( !(wm = PE_CreateModule( hModule32, filename, flags, FALSE )) )
+	{
+		ERR( "can't load %s\n", filename );
+		SetLastError( ERROR_OUTOFMEMORY );
+		return NULL;
+	}
+	close(hFile);
+	return wm;
+}
+
+
+/*****************************************************************************
+ *	PE_UnloadLibrary
+ *
+ * Unload the library unmapping the image and freeing the modref structure.
+ */
+void PE_UnloadLibrary(WINE_MODREF *wm)
+{
+    TRACE(" unloading %s\n", wm->filename);
+
+    HeapFree( GetProcessHeap(), 0, wm->filename );
+    HeapFree( GetProcessHeap(), 0, wm->short_filename );
+    HeapFree( GetProcessHeap(), 0, wm );
+}
+
+/*****************************************************************************
+ * Load the PE main .EXE. All other loading is done by PE_LoadLibraryExA
+ * FIXME: this function should use PE_LoadLibraryExA, but currently can't
+ * due to the PROCESS_Create stuff.
+ */
+
+/* Called if the library is loaded or freed.
+ * NOTE: if a thread attaches a DLL, the current thread will only do
+ * DLL_PROCESS_ATTACH. Only new created threads do DLL_THREAD_ATTACH
+ * (SDK)
+ */
+WIN_BOOL PE_InitDLL( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
+{
+    WIN_BOOL retv = TRUE;
+    assert( wm->type == MODULE32_PE );
+
+    
+    if ((PE_HEADER(wm->module)->FileHeader.Characteristics & IMAGE_FILE_DLL) &&
+        (PE_HEADER(wm->module)->OptionalHeader.AddressOfEntryPoint)
+    ) {
+	DLLENTRYPROC entry ;
+	entry = (void*)PE_FindExportedFunction(wm, "DllMain", 0);
+	if(entry==NULL)
+	    entry = (void*)RVA_PTR( wm->module,OptionalHeader.AddressOfEntryPoint );
+        
+	TRACE_(relay)("CallTo32(entryproc=%p,module=%08x,type=%ld,res=%p)\n",
+                       entry, wm->module, type, lpReserved );
+	printf("Entering DllMain(");
+	switch(type)
+	{
+	    case DLL_PROCESS_DETACH:
+	        printf("DLL_PROCESS_DETACH) ");
+		break;
+	    case DLL_PROCESS_ATTACH:
+	        printf("DLL_PROCESS_ATTACH) ");
+		break;
+	    case DLL_THREAD_DETACH:
+	        printf("DLL_THREAD_DETACH) ");
+		break;
+	    case DLL_THREAD_ATTACH:
+	        printf("DLL_THREAD_ATTACH) ");
+		break;
+	}	
+	printf("for %s\n", wm->filename);
+        retv = entry( wm->module, type, lpReserved );
+    }
+
+    return retv;
+}
+
+static LPVOID
+_fixup_address(PIMAGE_OPTIONAL_HEADER opt,int delta,LPVOID addr) {
+	if (	((DWORD)addr>opt->ImageBase) &&
+		((DWORD)addr<opt->ImageBase+opt->SizeOfImage)
+	)
+		
+		return (LPVOID)(((DWORD)addr)+delta);
+	else
+		
+		return addr;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/pe_resource.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,391 @@
+/*
+ * PE (Portable Execute) File Resources
+ *
+ * Copyright 1995 Thomas Sandford
+ * Copyright 1996 Martin von Loewis
+ *
+ * Based on the Win16 resource handling code in loader/resource.c
+ * Copyright 1993 Robert J. Amstadt
+ * Copyright 1995 Alexandre Julliard
+ * Copyright 1997 Marcus Meissner
+ */
+#include <config.h>
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <wine/winestring.h>
+#include <wine/windef.h>
+#include <wine/pe_image.h>
+#include <wine/module.h>
+#include <wine/heap.h>
+//#include "task.h"
+//#include "process.h"
+//#include "stackframe.h"
+#include <wine/debugtools.h>
+
+/**********************************************************************
+ *  HMODULE32toPE_MODREF 
+ *
+ * small helper function to get a PE_MODREF from a passed HMODULE32
+ */
+static PE_MODREF*
+HMODULE32toPE_MODREF(HMODULE hmod) {
+	WINE_MODREF	*wm;
+
+	wm = MODULE32_LookupHMODULE( hmod );
+	if (!wm || wm->type!=MODULE32_PE)
+		return NULL;
+	return &(wm->binfmt.pe);
+}
+
+/**********************************************************************
+ *	    GetResDirEntryW
+ *
+ *	Helper function - goes down one level of PE resource tree
+ *
+ */
+PIMAGE_RESOURCE_DIRECTORY GetResDirEntryW(PIMAGE_RESOURCE_DIRECTORY resdirptr,
+					   LPCWSTR name,DWORD root,
+					   WIN_BOOL allowdefault)
+{
+    int entrynum;
+    PIMAGE_RESOURCE_DIRECTORY_ENTRY entryTable;
+    int namelen;
+
+    if (HIWORD(name)) {
+    	if (name[0]=='#') {
+		char	buf[10];
+
+		lstrcpynWtoA(buf,name+1,10);
+		return GetResDirEntryW(resdirptr,(LPCWSTR)atoi(buf),root,allowdefault);
+	}
+	entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (
+			(BYTE *) resdirptr + 
+                        sizeof(IMAGE_RESOURCE_DIRECTORY));
+	namelen = lstrlenW(name);
+	for (entrynum = 0; entrynum < resdirptr->NumberOfNamedEntries; entrynum++)
+	{
+		PIMAGE_RESOURCE_DIR_STRING_U str =
+		(PIMAGE_RESOURCE_DIR_STRING_U) (root + 
+			entryTable[entrynum].u1.s.NameOffset);
+		if(namelen != str->Length)
+			continue;
+		if(wcsnicmp(name,str->NameString,str->Length)==0)
+			return (PIMAGE_RESOURCE_DIRECTORY) (
+				root +
+				entryTable[entrynum].u2.s.OffsetToDirectory);
+	}
+	return NULL;
+    } else {
+	entryTable = (PIMAGE_RESOURCE_DIRECTORY_ENTRY) (
+			(BYTE *) resdirptr + 
+                        sizeof(IMAGE_RESOURCE_DIRECTORY) +
+			resdirptr->NumberOfNamedEntries * sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
+	for (entrynum = 0; entrynum < resdirptr->NumberOfIdEntries; entrynum++)
+	    if ((DWORD)entryTable[entrynum].u1.Name == (DWORD)name)
+		return (PIMAGE_RESOURCE_DIRECTORY) (
+			root +
+			entryTable[entrynum].u2.s.OffsetToDirectory);
+	/* just use first entry if no default can be found */
+	if (allowdefault && !name && resdirptr->NumberOfIdEntries)
+		return (PIMAGE_RESOURCE_DIRECTORY) (
+			root +
+			entryTable[0].u2.s.OffsetToDirectory);
+	return NULL;
+    }
+}
+
+/**********************************************************************
+ *	    GetResDirEntryA
+ */
+PIMAGE_RESOURCE_DIRECTORY GetResDirEntryA( PIMAGE_RESOURCE_DIRECTORY resdirptr,
+					   LPCSTR name, DWORD root,
+					   WIN_BOOL allowdefault )
+{
+    PIMAGE_RESOURCE_DIRECTORY retv;
+    LPWSTR nameW = HIWORD(name)? HEAP_strdupAtoW( GetProcessHeap(), 0, name ) 
+                               : (LPWSTR)name;
+
+    retv = GetResDirEntryW( resdirptr, nameW, root, allowdefault );
+
+    if ( HIWORD(name) ) HeapFree( GetProcessHeap(), 0, nameW );
+
+    return retv;
+}
+
+/**********************************************************************
+ *	    PE_FindResourceEx32W
+ */
+HANDLE PE_FindResourceExW(
+	WINE_MODREF *wm,LPCWSTR name,LPCWSTR type,WORD lang
+) {
+    PIMAGE_RESOURCE_DIRECTORY resdirptr;
+    DWORD root;
+    HANDLE result;
+    PE_MODREF	*pem = &(wm->binfmt.pe);
+
+    if (!pem || !pem->pe_resource)
+    	return 0;
+
+    resdirptr = pem->pe_resource;
+    root = (DWORD) resdirptr;
+    if ((resdirptr = GetResDirEntryW(resdirptr, type, root, FALSE)) == NULL)
+	return 0;
+    if ((resdirptr = GetResDirEntryW(resdirptr, name, root, FALSE)) == NULL)
+	return 0;
+    result = (HANDLE)GetResDirEntryW(resdirptr, (LPCWSTR)(UINT)lang, root, FALSE);
+	/* Try LANG_NEUTRAL, too */
+    if(!result)
+        return (HANDLE)GetResDirEntryW(resdirptr, (LPCWSTR)0, root, TRUE);
+    return result;
+}
+
+
+/**********************************************************************
+ *	    PE_LoadResource32
+ */
+HANDLE PE_LoadResource( WINE_MODREF *wm, HANDLE hRsrc )
+{
+    if (!hRsrc || !wm || wm->type!=MODULE32_PE)
+    	return 0;
+    return (HANDLE) (wm->module + ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->OffsetToData);
+}
+
+
+/**********************************************************************
+ *	    PE_SizeofResource32
+ */
+DWORD PE_SizeofResource( HINSTANCE hModule, HANDLE hRsrc )
+{
+    /* we don't need hModule */
+    if (!hRsrc)
+   	 return 0;
+    return ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->Size;
+}
+
+/**********************************************************************
+ *	    PE_EnumResourceTypes32A
+ */
+WIN_BOOL
+PE_EnumResourceTypesA(HMODULE hmod,ENUMRESTYPEPROCA lpfun,LONG lparam) {
+    PE_MODREF	*pem = HMODULE32toPE_MODREF(hmod);
+    int		i;
+    PIMAGE_RESOURCE_DIRECTORY		resdir;
+    PIMAGE_RESOURCE_DIRECTORY_ENTRY	et;
+    WIN_BOOL	ret;
+    HANDLE	heap = GetProcessHeap();	
+
+    if (!pem || !pem->pe_resource)
+    	return FALSE;
+
+    resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
+    et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
+    ret = FALSE;
+    for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
+    	LPSTR	name;
+
+	if (et[i].u1.s.NameIsString)
+		name = HEAP_strdupWtoA(heap,0,(LPWSTR)((LPBYTE)pem->pe_resource+et[i].u1.s.NameOffset));
+	else
+		name = (LPSTR)(int)et[i].u1.Id;
+	ret = lpfun(hmod,name,lparam);
+	if (HIWORD(name))
+		HeapFree(heap,0,name);
+	if (!ret)
+		break;
+    }
+    return ret;
+}
+
+/**********************************************************************
+ *	    PE_EnumResourceTypes32W
+ */
+WIN_BOOL
+PE_EnumResourceTypesW(HMODULE hmod,ENUMRESTYPEPROCW lpfun,LONG lparam) {
+    PE_MODREF	*pem = HMODULE32toPE_MODREF(hmod);
+    int		i;
+    PIMAGE_RESOURCE_DIRECTORY		resdir;
+    PIMAGE_RESOURCE_DIRECTORY_ENTRY	et;
+    WIN_BOOL	ret;
+
+    if (!pem || !pem->pe_resource)
+    	return FALSE;
+
+    resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
+    et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
+    ret = FALSE;
+    for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
+	LPWSTR	type;
+    	if (et[i].u1.s.NameIsString)
+		type = (LPWSTR)((LPBYTE)pem->pe_resource+et[i].u1.s.NameOffset);
+	else
+		type = (LPWSTR)(int)et[i].u1.Id;
+
+	ret = lpfun(hmod,type,lparam);
+	if (!ret)
+		break;
+    }
+    return ret;
+}
+
+/**********************************************************************
+ *	    PE_EnumResourceNames32A
+ */
+WIN_BOOL
+PE_EnumResourceNamesA(
+	HMODULE hmod,LPCSTR type,ENUMRESNAMEPROCA lpfun,LONG lparam
+) {
+    PE_MODREF	*pem = HMODULE32toPE_MODREF(hmod);
+    int		i;
+    PIMAGE_RESOURCE_DIRECTORY		resdir;
+    PIMAGE_RESOURCE_DIRECTORY_ENTRY	et;
+    WIN_BOOL	ret;
+    HANDLE	heap = GetProcessHeap();	
+    LPWSTR	typeW;
+
+    if (!pem || !pem->pe_resource)
+    	return FALSE;
+    resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
+    if (HIWORD(type))
+	typeW = HEAP_strdupAtoW(heap,0,type);
+    else
+	typeW = (LPWSTR)type;
+    resdir = GetResDirEntryW(resdir,typeW,(DWORD)pem->pe_resource,FALSE);
+    if (HIWORD(typeW))
+    	HeapFree(heap,0,typeW);
+    if (!resdir)
+    	return FALSE;
+    et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
+    ret = FALSE;
+    for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
+    	LPSTR	name;
+
+	if (et[i].u1.s.NameIsString)
+	    name = HEAP_strdupWtoA(heap,0,(LPWSTR)((LPBYTE)pem->pe_resource+et[i].u1.s.NameOffset));
+	else
+	    name = (LPSTR)(int)et[i].u1.Id;
+	ret = lpfun(hmod,type,name,lparam);
+	if (HIWORD(name)) HeapFree(heap,0,name);
+	if (!ret)
+		break;
+    }
+    return ret;
+}
+
+/**********************************************************************
+ *	    PE_EnumResourceNames32W
+ */
+WIN_BOOL
+PE_EnumResourceNamesW(
+	HMODULE hmod,LPCWSTR type,ENUMRESNAMEPROCW lpfun,LONG lparam
+) {
+    PE_MODREF	*pem = HMODULE32toPE_MODREF(hmod);
+    int		i;
+    PIMAGE_RESOURCE_DIRECTORY		resdir;
+    PIMAGE_RESOURCE_DIRECTORY_ENTRY	et;
+    WIN_BOOL	ret;
+
+    if (!pem || !pem->pe_resource)
+    	return FALSE;
+
+    resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
+    resdir = GetResDirEntryW(resdir,type,(DWORD)pem->pe_resource,FALSE);
+    if (!resdir)
+    	return FALSE;
+    et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
+    ret = FALSE;
+    for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
+	LPWSTR	name;
+    	if (et[i].u1.s.NameIsString)
+		name = (LPWSTR)((LPBYTE)pem->pe_resource+et[i].u1.s.NameOffset);
+	else
+		name = (LPWSTR)(int)et[i].u1.Id;
+	ret = lpfun(hmod,type,name,lparam);
+	if (!ret)
+		break;
+    }
+    return ret;
+}
+
+/**********************************************************************
+ *	    PE_EnumResourceNames32A
+ */
+WIN_BOOL
+PE_EnumResourceLanguagesA(
+	HMODULE hmod,LPCSTR name,LPCSTR type,ENUMRESLANGPROCA lpfun,
+	LONG lparam
+) {
+    PE_MODREF	*pem = HMODULE32toPE_MODREF(hmod);
+    int		i;
+    PIMAGE_RESOURCE_DIRECTORY		resdir;
+    PIMAGE_RESOURCE_DIRECTORY_ENTRY	et;
+    WIN_BOOL	ret;
+    HANDLE	heap = GetProcessHeap();	
+    LPWSTR	nameW,typeW;
+
+    if (!pem || !pem->pe_resource)
+    	return FALSE;
+
+    resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
+    if (HIWORD(name))
+	nameW = HEAP_strdupAtoW(heap,0,name);
+    else
+    	nameW = (LPWSTR)name;
+    resdir = GetResDirEntryW(resdir,nameW,(DWORD)pem->pe_resource,FALSE);
+    if (HIWORD(nameW))
+    	HeapFree(heap,0,nameW);
+    if (!resdir)
+    	return FALSE;
+    if (HIWORD(type))
+	typeW = HEAP_strdupAtoW(heap,0,type);
+    else
+	typeW = (LPWSTR)type;
+    resdir = GetResDirEntryW(resdir,typeW,(DWORD)pem->pe_resource,FALSE);
+    if (HIWORD(typeW))
+    	HeapFree(heap,0,typeW);
+    if (!resdir)
+    	return FALSE;
+    et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
+    ret = FALSE;
+    for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
+    	/* languages are just ids... I hopem */
+	ret = lpfun(hmod,name,type,et[i].u1.Id,lparam);
+	if (!ret)
+		break;
+    }
+    return ret;
+}
+
+/**********************************************************************
+ *	    PE_EnumResourceLanguages32W
+ */
+WIN_BOOL
+PE_EnumResourceLanguagesW(
+	HMODULE hmod,LPCWSTR name,LPCWSTR type,ENUMRESLANGPROCW lpfun,
+	LONG lparam
+) {
+    PE_MODREF	*pem = HMODULE32toPE_MODREF(hmod);
+    int		i;
+    PIMAGE_RESOURCE_DIRECTORY		resdir;
+    PIMAGE_RESOURCE_DIRECTORY_ENTRY	et;
+    WIN_BOOL	ret;
+
+    if (!pem || !pem->pe_resource)
+    	return FALSE;
+
+    resdir = (PIMAGE_RESOURCE_DIRECTORY)pem->pe_resource;
+    resdir = GetResDirEntryW(resdir,name,(DWORD)pem->pe_resource,FALSE);
+    if (!resdir)
+    	return FALSE;
+    resdir = GetResDirEntryW(resdir,type,(DWORD)pem->pe_resource,FALSE);
+    if (!resdir)
+    	return FALSE;
+    et =(PIMAGE_RESOURCE_DIRECTORY_ENTRY)((LPBYTE)resdir+sizeof(IMAGE_RESOURCE_DIRECTORY));
+    ret = FALSE;
+    for (i=0;i<resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries;i++) {
+	ret = lpfun(hmod,name,type,et[i].u1.Id,lparam);
+	if (!ret)
+		break;
+    }
+    return ret;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/registry.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,421 @@
+#include <config.h>
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <pwd.h>
+#include <sys/types.h>
+
+#include <wine/winbase.h>
+#include <wine/winreg.h>
+#include <wine/winnt.h>
+#include <wine/winerror.h>
+
+#include <registry.h>
+
+struct reg_value
+{
+	int type;
+	char* name;
+	int len;
+	char* value;
+};
+
+static int reg_size=0;
+
+static struct reg_value* regs=0;
+
+struct reg_handle_s;
+typedef struct reg_handle_s
+{
+	int handle;
+	char* name;
+	struct reg_handle_s* next;
+	struct reg_handle_s* prev;
+} reg_handle_t;
+		
+static reg_handle_t* head=0;
+
+#define DIR -25
+
+static void create_registry();
+static void open_registry();
+static void save_registry();
+
+
+
+
+static void create_registry(){
+    if(regs)
+    {
+	printf("Logic error: create_registry() called with existing registry\n");
+	save_registry();
+	return;
+    }	
+    regs=(struct reg_value*)malloc(3*sizeof(struct reg_value));
+    regs[0].type=regs[1].type=DIR;
+    regs[0].name=(char*)malloc(5);
+    strcpy(regs[0].name, "HKLM");
+    regs[1].name=(char*)malloc(5);
+    strcpy(regs[1].name, "HKCU");
+    regs[0].value=regs[1].value=NULL;
+    regs[0].len=regs[1].len=0;
+    reg_size=2;
+    save_registry();
+}
+static void open_registry()
+{
+	int fd;
+	int i;
+	int len;
+         struct passwd* pwent;
+         char* pathname;
+	if(regs)
+	{
+		printf("Multiple open_registry(>\n");
+		return;
+	}
+        pwent=getpwuid(getuid());
+        pathname=(char*)malloc(strlen(pwent->pw_dir)+20);
+	strcpy(pathname, pwent->pw_dir);
+        strcat(pathname, "/.registry");
+	fd=open(pathname, O_RDONLY);
+        free(pathname);
+	if(fd==-1)
+	{
+	    printf("Creating new registry\n");
+	    create_registry();
+	    return;
+	}    
+	read(fd, &reg_size, 4);
+	regs=(struct reg_value*)malloc(reg_size*sizeof(struct reg_value));
+	for(i=0; i<reg_size; i++)
+	{
+		read(fd,&regs[i].type,4);
+		read(fd,&len,4);
+		regs[i].name=(char*)malloc(len+1);
+		if(regs[i].name==0)
+		{
+			reg_size=i+1;
+			goto error;
+		}
+		read(fd, regs[i].name, len);
+		regs[i].name[len]=0;
+		read(fd,&regs[i].len,4);
+		regs[i].value=(char*)malloc(regs[i].len+1);
+		if(regs[i].value==0)
+		{
+			free(regs[i].name);
+			reg_size=i+1;
+			goto error;
+		}
+		read(fd, regs[i].value, regs[i].len);
+		regs[i].value[regs[i].len]=0;
+	}
+error:
+	close(fd);
+	return;
+}
+
+static void save_registry()
+{
+	int fd, i, len;
+         struct passwd* pwent;
+         char* pathname;
+        pwent=getpwuid(getuid());
+        pathname=(char*)malloc(strlen(pwent->pw_dir)+20);
+	strcpy(pathname, pwent->pw_dir);
+        strcat(pathname, "/.registry");
+	fd=open(pathname, O_WRONLY | O_CREAT, 00777);
+        free(pathname);
+	if(fd==-1)
+	{
+		printf("Failed to open registry file for writing.\n");
+		return;
+	}
+	write(fd, &reg_size, 4);
+	for(i=0; i<reg_size; i++)
+	{
+		write(fd, &regs[i].type, 4);
+		len=strlen(regs[i].name);
+		write(fd, &len, 4);
+		write(fd, regs[i].name, len);
+		write(fd, &regs[i].len, 4);
+		write(fd, regs[i].value, regs[i].len);
+	}
+	close(fd);
+}
+static reg_handle_t* find_handle_by_name(const char* name)
+{
+	reg_handle_t* t;
+//        printf("REGISTRY: find_handle_by_name(%s)\n",name);
+	for(t=head; t; t=t->prev)
+	{
+		if(!strcmp(t->name, name))
+		{
+			return t;
+		}
+	}
+	return 0;
+}
+static struct reg_value* find_value_by_name(const char* name)
+{
+	int i;
+//        printf("REGISTRY: find_value_by_name(%s)\n",name);
+	for(i=0; i<reg_size; i++)
+		if(!strcmp(regs[i].name, name))
+			return regs+i;
+	return 0;
+}
+static reg_handle_t* find_handle(int handle)
+{
+	reg_handle_t* t;
+//        printf("REGISTRY: find_handle(%d)\n",handle);
+	for(t=head; t; t=t->prev)
+	{
+		if(t->handle==handle)
+		{
+			return t;
+		}
+	}
+	return 0;
+}	
+static int generate_handle()
+{
+	static int zz=249;
+	zz++;
+	while((zz==HKEY_LOCAL_MACHINE) || (zz==HKEY_CURRENT_USER))
+		zz++;
+	return zz;
+}
+
+static reg_handle_t* insert_handle(long handle, const char* name)
+{
+	reg_handle_t* t;
+	t=(reg_handle_t*)malloc(sizeof(reg_handle_t));
+	if(head==0)
+	{
+		t->prev=0;
+	}
+	else
+	{
+		head->next=t;
+		t->prev=head;
+	}
+	t->next=0;
+	t->name=(char*)malloc(strlen(name)+1);
+	strcpy(t->name, name);
+	t->handle=handle;
+	head=t;
+	return t;
+}
+static char* build_keyname(long key, const char* subkey)
+{
+	char* full_name;
+	reg_handle_t* t;
+ 	if((t=find_handle(key))==0)
+	{
+		TRACE("Invalid key\n");
+		return NULL;
+	}
+	if(subkey==NULL)
+		subkey="<default>";
+	full_name=(char*)malloc(strlen(t->name)+strlen(subkey)+10);
+	strcpy(full_name, t->name);
+	strcat(full_name, "\\");
+	strcat(full_name, subkey);
+	return full_name;
+}
+struct reg_value* insert_reg_value(int handle, const char* name, int type, const void* value, int len)
+{
+	reg_handle_t* t;
+	struct reg_value* v;
+	char* fullname;
+	if((fullname=build_keyname(handle, name))==NULL)
+	{
+		TRACE("Invalid handle\n");
+		return NULL;
+	}
+
+	if((v=find_value_by_name(fullname))==0)
+	//creating new value in registry
+	{
+		if(regs==0)
+		    create_registry();
+		regs=(struct reg_value*)realloc(regs, sizeof(struct reg_value)*(reg_size+1));
+		v=regs+reg_size;
+		reg_size++;
+	}
+	else
+	//replacing old one
+	{
+		free(v->value);
+		free(v->name);
+	}
+	v->type=type;
+	v->len=len;
+	v->value=(char*)malloc(len);
+	memcpy(v->value, value, len);
+	v->name=(char*)malloc(strlen(fullname)+1);
+	strcpy(v->name, fullname);
+	save_registry();
+	return v;
+}
+
+static void init_registry()
+{
+//	printf("Initializing registry\n");
+	open_registry();
+	insert_handle(HKEY_LOCAL_MACHINE, "HKLM");
+	insert_handle(HKEY_CURRENT_USER, "HKCU");
+}
+static reg_handle_t* find_handle_2(long key, const char* subkey)
+{
+	char* full_name;
+	reg_handle_t* t;
+ 	if((t=find_handle(key))==0)
+	{
+		TRACE("Invalid key\n");
+		return (reg_handle_t*)-1;
+	}
+	if(subkey==NULL)
+		return t;
+	full_name=(char*)malloc(strlen(t->name)+strlen(subkey)+10);
+	strcpy(full_name, t->name);
+	strcat(full_name, "\\");
+	strcat(full_name, subkey);
+	t=find_handle_by_name(full_name);
+	free(full_name);
+	return t;
+}
+
+long RegOpenKeyExA(long key, const char* subkey, long reserved, long access, int* newkey)
+{
+    char* full_name;
+    reg_handle_t* t;
+    struct reg_value* v;
+    TRACE("Opening key %s\n", subkey);
+    
+    if(!regs)
+        init_registry()
+;	
+/*	t=find_handle_2(key, subkey);
+	
+	if(t==0)
+		return -1;
+
+	if(t==(reg_handle_t*)-1)
+		return -1;
+
+*/    full_name=build_keyname(key, subkey);
+    if(!full_name)
+        return -1;
+    v=find_value_by_name(full_name);    
+
+    t=insert_handle(generate_handle(), full_name);
+    *newkey=t->handle;
+    free(full_name);
+    
+    return 0;
+}    
+long RegCloseKey(long key)
+{
+        reg_handle_t *handle;
+    if(key==HKEY_LOCAL_MACHINE)
+	return 0;
+    if(key==HKEY_CURRENT_USER)
+	return 0;
+    handle=find_handle(key);
+    if(handle==0)
+	return 0;
+    if(handle->prev)
+	handle->prev->next=handle->next;
+    if(handle->next)
+	handle->next->prev=handle->prev;
+    if(handle->name)
+	free(handle->name);
+    if(handle==head)
+	head=head->prev;
+    free(handle);
+    return 1;
+}         
+long RegQueryValueExA(long key, const char* value, int* reserved, int* type, int* data, int* count)
+{
+	struct reg_value* t;
+	char* c;
+	TRACE("Querying value %s\n", value);
+	if(!regs)
+	    init_registry()
+;	
+    	c=build_keyname(key, value);
+	if(c==NULL)
+		return 1;
+	if((t=find_value_by_name(c))==0)
+	{
+		free(c);
+		return 2;
+	}
+	free(c);
+	if(type)
+		*type=t->type;
+	if(data)
+	{
+		memcpy(data, t->value, (t->len<*count)?t->len:*count);
+		TRACE("returning %d bytes: %d\n", t->len, *(int*)data);
+	}	
+		if(*count<t->len)
+		{
+			*count=t->len;
+			return ERROR_MORE_DATA;
+    }
+    else
+    {
+        *count=t->len;
+	}
+    return 0;
+}  
+long RegCreateKeyExA(long key, const char* name, long reserved,
+							   void* classs, long options, long security,
+							   void* sec_attr, int* newkey, int* status) 
+{
+	reg_handle_t* t;
+	char* fullname;
+	struct reg_value* v;
+//        TRACE("Creating/Opening key %s\n", name);
+        TRACE("Creating/Opening key %s\n", name);
+	if(!regs)
+	    init_registry()
+;	
+	fullname=build_keyname(key, name);
+	if(fullname==NULL)
+		return 1;
+	v=find_value_by_name(fullname);
+	if(v==0)
+	{
+		int qw=45708;
+		v=insert_reg_value(key, name, DIR, &qw, 4);
+		*status=REG_CREATED_NEW_KEY;
+//		return 0;
+	}
+	else
+		*status=REG_OPENED_EXISTING_KEY;
+
+	t=insert_handle(generate_handle(), fullname);
+	*newkey=t->handle;
+	free(fullname);
+	return 0;
+}
+long RegSetValueExA(long key, const char* name, long v1, long v2, const void* data, long size)
+{
+    struct reg_value* t;
+    char* c;
+    TRACE("Request to set value %s\n", name);
+    if(!regs)
+        init_registry()
+;	
+    c=build_keyname(key, name);
+    if(c==NULL)
+	return 1;
+    insert_reg_value(key, name, v2, data, size);
+    free(c);
+    return 0;
+}        
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/registry.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,24 @@
+/********************************************************
+
+	Declaration of registry access functions
+	Copyright 2000 Eugene Smith (divx@euro.ru)
+
+*********************************************************/
+
+
+#ifndef REGISTRY_H
+#define REGISTRY_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+long RegOpenKeyExA(long key, const char* subkey, long reserved, long access, int* newkey);
+long RegCloseKey(long key);
+long RegQueryValueExA(long key, const char* value, int* reserved, int* type, int* data, int* count);
+long RegCreateKeyExA(long key, const char* name, long reserved,
+							   void* classs, long options, long security,
+							   void* sec_attr, int* newkey, int* status);
+long RegSetValueExA(long key, const char* name, long v1, long v2, const void* data, long size);
+#ifdef __cplusplus
+};
+#endif
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/resource.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,478 @@
+/*
+ * Resources
+ *
+ * Copyright 1993 Robert J. Amstadt
+ * Copyright 1995 Alexandre Julliard
+ */
+#include <config.h>
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <wine/winbase.h>
+#include <wine/windef.h>
+#include <wine/winuser.h>
+#include <wine/heap.h>
+#include <wine/module.h>
+#include <wine/debugtools.h>
+#include <wine/winerror.h>
+#define CP_ACP					0
+
+WORD WINE_LanguageId=0x409;//english
+
+#define HRSRC_MAP_BLOCKSIZE 16
+
+typedef struct _HRSRC_ELEM
+{
+    HANDLE hRsrc;
+    WORD     type;
+} HRSRC_ELEM;
+
+typedef struct _HRSRC_MAP
+{
+    int nAlloc;
+    int nUsed;
+    HRSRC_ELEM *elem;
+} HRSRC_MAP;
+
+static HRSRC RES_FindResource2( HMODULE hModule, LPCSTR type,
+				LPCSTR name, WORD lang, int unicode)
+{
+    HRSRC hRsrc = 0;
+    LPWSTR typeStr, nameStr;    
+    WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule );
+
+    if(!wm)
+	return 0;    
+    /* 32-bit PE module */
+
+    
+    if ( HIWORD( type ) && (!unicode))
+	typeStr = HEAP_strdupAtoW( GetProcessHeap(), 0, type );
+    else
+	typeStr = (LPWSTR)type;
+    if ( HIWORD( name ) && (!unicode))
+	nameStr = HEAP_strdupAtoW( GetProcessHeap(), 0, name );
+    else
+	nameStr = (LPWSTR)name;
+    
+    hRsrc = PE_FindResourceExW( wm, nameStr, typeStr, lang );
+    
+    if ( HIWORD( type ) && (!unicode)) 
+	HeapFree( GetProcessHeap(), 0, typeStr );
+    if ( HIWORD( name ) && (!unicode)) 
+	HeapFree( GetProcessHeap(), 0, nameStr );
+
+    return hRsrc;
+}
+
+/**********************************************************************
+ *          RES_FindResource
+ */
+
+static HRSRC RES_FindResource( HMODULE hModule, LPCSTR type,
+                               LPCSTR name, WORD lang, int unicode )
+{
+    HRSRC hRsrc;
+//    __TRY
+//    {
+	hRsrc = RES_FindResource2(hModule, type, name, lang, unicode);
+//    }
+//    __EXCEPT(page_fault)
+//    {
+//	WARN("page fault\n");
+//	SetLastError(ERROR_INVALID_PARAMETER);
+//	return 0;
+//    }
+//    __ENDTRY
+    return hRsrc;
+}
+
+/**********************************************************************
+ *          RES_SizeofResource
+ */
+static DWORD RES_SizeofResource( HMODULE hModule, HRSRC hRsrc)
+{
+    DWORD size = 0;
+    HRSRC hRsrc32;
+
+//    HMODULE16 hMod16   = MapHModuleLS( hModule );
+//    NE_MODULE *pModule = NE_GetPtr( hMod16 );
+//    WINE_MODREF *wm    = pModule && pModule->module32? 
+//                         MODULE32_LookupHMODULE( pModule->module32 ) : NULL;
+    WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule );
+
+    if ( !hModule || !hRsrc ) return 0;
+
+    /* 32-bit PE module */
+    /* If we got a 16-bit hRsrc, convert it */
+//    hRsrc32  = HIWORD(hRsrc)? hRsrc : MapHRsrc16To32( pModule, hRsrc );
+    if(!HIWORD(hRsrc))
+    {
+	printf("16-bit hRsrcs not supported\n");
+	return 0;
+    }	
+    size = PE_SizeofResource( hModule, hRsrc );
+    return size;
+}
+
+/**********************************************************************
+ *          RES_AccessResource
+ */
+static HFILE RES_AccessResource( HMODULE hModule, HRSRC hRsrc )
+{
+    HFILE hFile = HFILE_ERROR;
+
+    WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule );
+
+    if ( !hModule || !hRsrc ) return HFILE_ERROR;
+
+    /* 32-bit PE module */
+    FIXME("32-bit modules not yet supported.\n" );
+    hFile = HFILE_ERROR;
+
+    return hFile;
+}
+
+/**********************************************************************
+ *          RES_LoadResource
+ */
+static HGLOBAL RES_LoadResource( HMODULE hModule, HRSRC hRsrc)
+{
+    HGLOBAL hMem = 0;
+    HRSRC hRsrc32;
+    WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule );
+
+
+    if ( !hModule || !hRsrc ) return 0;
+
+    /* 32-bit PE module */
+
+    /* If we got a 16-bit hRsrc, convert it */
+//    hRsrc32 = HIWORD(hRsrc)? hRsrc : MapHRsrc16To32( pModule, hRsrc );
+    if(!HIWORD(hRsrc))
+    {
+	printf("16-bit hRsrcs not supported\n");
+	return 0;
+    }
+    hMem = PE_LoadResource( wm, hRsrc );
+
+    return hMem;
+}
+
+/**********************************************************************
+ *          RES_LockResource
+ */
+static LPVOID RES_LockResource( HGLOBAL handle )
+{
+    LPVOID bits = NULL;
+
+    TRACE("(%08x, %s)\n", handle, "PE" );
+
+    bits = (LPVOID)handle;
+
+    return bits;
+}
+
+/**********************************************************************
+ *          RES_FreeResource
+ */
+static WIN_BOOL RES_FreeResource( HGLOBAL handle )
+{
+    HGLOBAL retv = handle;
+    return (WIN_BOOL)retv;
+}
+
+/**********************************************************************
+ *	    FindResourceA    (KERNEL32.128)
+ */
+HANDLE WINAPI FindResourceA( HMODULE hModule, LPCSTR name, LPCSTR type )
+{
+    return RES_FindResource( hModule, type, name, 
+                             WINE_LanguageId, 0);
+}
+HANDLE WINAPI FindResourceW( HMODULE hModule, LPCWSTR name, LPCWSTR type )
+{
+    return RES_FindResource( hModule, (LPCSTR)type, (LPCSTR)name, 
+                             WINE_LanguageId, 1);
+}
+
+/**********************************************************************
+ *	    FindResourceExA  (KERNEL32.129)
+ */
+HANDLE WINAPI FindResourceExA( HMODULE hModule, 
+                               LPCSTR type, LPCSTR name, WORD lang )
+{
+    return RES_FindResource( hModule, type, name, 
+                             lang, 0 );
+}
+
+HANDLE WINAPI FindResourceExW( HMODULE hModule, 
+                               LPCWSTR type, LPCWSTR name, WORD lang )
+{
+    return RES_FindResource( hModule, (LPCSTR)type, (LPCSTR)name, 
+                             lang, 1 );
+}
+
+
+
+/**********************************************************************
+ *	    LockResource     (KERNEL32.384)
+ */
+LPVOID WINAPI LockResource( HGLOBAL handle )
+{
+    return RES_LockResource( handle );
+}
+
+
+/**********************************************************************
+ *	    FreeResource     (KERNEL32.145)
+ */
+WIN_BOOL WINAPI FreeResource( HGLOBAL handle )
+{
+    return RES_FreeResource( handle );
+}
+
+
+/**********************************************************************
+ *	    AccessResource   (KERNEL32.64)
+ */
+INT WINAPI AccessResource( HMODULE hModule, HRSRC hRsrc )
+{
+    return RES_AccessResource( hModule, hRsrc );
+}
+/**********************************************************************
+ *	    SizeofResource   (KERNEL32.522)
+ */
+DWORD WINAPI SizeofResource( HINSTANCE hModule, HRSRC hRsrc )
+{
+    return RES_SizeofResource( hModule, hRsrc );
+}
+
+
+INT WINAPI LoadStringW( HINSTANCE instance, UINT resource_id,
+                            LPWSTR buffer, INT buflen );
+
+/**********************************************************************
+ *	LoadStringA	(USER32.375)
+ */
+INT WINAPI LoadStringA( HINSTANCE instance, UINT resource_id,
+                            LPSTR buffer, INT buflen )
+{
+    INT    retval;
+    INT    wbuflen;
+    INT    abuflen;
+    LPWSTR wbuf = NULL;
+    LPSTR  abuf = NULL;
+
+    if ( buffer != NULL && buflen > 0 )
+	*buffer = 0;
+
+    wbuflen = LoadStringW(instance,resource_id,NULL,0);
+    if ( !wbuflen )
+	return 0;
+    wbuflen ++;
+
+    retval = 0;
+    wbuf = HeapAlloc( GetProcessHeap(), 0, wbuflen * sizeof(WCHAR) );
+    wbuflen = LoadStringW(instance,resource_id,wbuf,wbuflen);
+    if ( wbuflen > 0 )
+    {
+	abuflen = WideCharToMultiByte(CP_ACP,0,wbuf,wbuflen,NULL,0,NULL,NULL);
+	if ( abuflen > 0 )
+	{
+	    if ( buffer == NULL || buflen == 0 )
+		retval = abuflen;
+	    else
+	    {
+		abuf = HeapAlloc( GetProcessHeap(), 0, abuflen * sizeof(CHAR) );
+		abuflen = WideCharToMultiByte(CP_ACP,0,wbuf,wbuflen,abuf,abuflen,NULL,NULL);
+		if ( abuflen > 0 )
+		{
+		    abuflen = min(abuflen,buflen - 1);
+		    memcpy( buffer, abuf, abuflen );
+		    buffer[abuflen] = 0;
+		    retval = abuflen;
+		}
+		HeapFree( GetProcessHeap(), 0, abuf );
+	    }
+	}
+    }
+    HeapFree( GetProcessHeap(), 0, wbuf );
+
+    return retval;
+}
+
+/**********************************************************************
+ *	LoadStringW		(USER32.376)
+ */
+INT WINAPI LoadStringW( HINSTANCE instance, UINT resource_id,
+                            LPWSTR buffer, INT buflen )
+{
+    HGLOBAL hmem;
+    HRSRC hrsrc;
+    WCHAR *p;
+    int string_num;
+    int i;
+
+    if (HIWORD(resource_id)==0xFFFF) /* netscape 3 passes this */
+	resource_id = (UINT)(-((INT)resource_id));
+    TRACE("instance = %04x, id = %04x, buffer = %08x, "
+          "length = %d\n", instance, (int)resource_id, (int) buffer, buflen);
+
+    /* Use bits 4 - 19 (incremented by 1) as resourceid, mask out 
+     * 20 - 31. */
+    hrsrc = FindResourceW( instance, (LPCWSTR)(((resource_id>>4)&0xffff)+1),
+                             RT_STRINGW );
+    if (!hrsrc) return 0;
+    hmem = LoadResource( instance, hrsrc );
+    if (!hmem) return 0;
+    
+    p = LockResource(hmem);
+    string_num = resource_id & 0x000f;
+    for (i = 0; i < string_num; i++)
+	p += *p + 1;
+    
+    TRACE("strlen = %d\n", (int)*p );
+    
+    if (buffer == NULL) return *p;
+    i = min(buflen - 1, *p);
+    if (i > 0) {
+	memcpy(buffer, p + 1, i * sizeof (WCHAR));
+	buffer[i] = (WCHAR) 0;
+    } else {
+	if (buflen > 1) {
+	    buffer[0] = (WCHAR) 0;
+	    return 0;
+	}
+#if 0
+	WARN("Dont know why caller give buflen=%d *p=%d trying to obtain string '%s'\n", buflen, *p, p + 1);
+#endif
+    }
+
+    TRACE("String loaded !\n");
+    return i;
+}
+
+/* Messages...used by FormatMessage32* (KERNEL32.something)
+ * 
+ * They can be specified either directly or using a message ID and
+ * loading them from the resource.
+ * 
+ * The resourcedata has following format:
+ * start:
+ * 0: DWORD nrofentries
+ * nrofentries * subentry:
+ *	0: DWORD firstentry
+ *	4: DWORD lastentry
+ *      8: DWORD offset from start to the stringentries
+ *
+ * (lastentry-firstentry) * stringentry:
+ * 0: WORD len (0 marks end)
+ * 2: WORD flags
+ * 4: CHAR[len-4]
+ * 	(stringentry i of a subentry refers to the ID 'firstentry+i')
+ *
+ * Yes, ANSI strings in win32 resources. Go figure.
+ */
+
+/**********************************************************************
+ *	LoadMessageA		(internal)
+ */
+INT WINAPI LoadMessageA( HMODULE instance, UINT id, WORD lang,
+                      LPSTR buffer, INT buflen )
+{
+    HGLOBAL	hmem;
+    HRSRC	hrsrc;
+    PMESSAGE_RESOURCE_DATA	mrd;
+    PMESSAGE_RESOURCE_BLOCK	mrb;
+    PMESSAGE_RESOURCE_ENTRY	mre;
+    int		i,slen;
+
+    TRACE("instance = %08lx, id = %08lx, buffer = %p, length = %ld\n", (DWORD)instance, (DWORD)id, buffer, (DWORD)buflen);
+
+    /*FIXME: I am not sure about the '1' ... But I've only seen those entries*/
+    hrsrc = FindResourceExW(instance,RT_MESSAGELISTW,(LPWSTR)1,lang);
+    if (!hrsrc) return 0;
+    hmem = LoadResource( instance, hrsrc );
+    if (!hmem) return 0;
+    
+    mrd = (PMESSAGE_RESOURCE_DATA)LockResource(hmem);
+    mre = NULL;
+    mrb = &(mrd->Blocks[0]);
+    for (i=mrd->NumberOfBlocks;i--;) {
+    	if ((id>=mrb->LowId) && (id<=mrb->HighId)) {
+	    mre = (PMESSAGE_RESOURCE_ENTRY)(((char*)mrd)+mrb->OffsetToEntries);
+	    id	-= mrb->LowId;
+	    break;
+	}
+	mrb++;
+    }
+    if (!mre)
+    	return 0;
+    for (i=id;i--;) {
+    	if (!mre->Length)
+		return 0;
+    	mre = (PMESSAGE_RESOURCE_ENTRY)(((char*)mre)+(mre->Length));
+    }
+    slen=mre->Length;
+    TRACE("	- strlen=%d\n",slen);
+    i = min(buflen - 1, slen);
+    if (buffer == NULL)
+	return slen;
+    if (i>0) {
+	lstrcpynA(buffer,(char*)mre->Text,i);
+	buffer[i]=0;
+    } else {
+	if (buflen>1) {
+	    buffer[0]=0;
+	    return 0;
+	}
+    }
+    if (buffer)
+	    TRACE("'%s' copied !\n", buffer);
+    return i;
+}
+
+
+
+/**********************************************************************
+ *	EnumResourceTypesA	(KERNEL32.90)
+ */
+WIN_BOOL WINAPI EnumResourceTypesA( HMODULE hmodule,ENUMRESTYPEPROCA lpfun,
+                                    LONG lParam)
+{
+	/* FIXME: move WINE_MODREF stuff here */
+    return PE_EnumResourceTypesA(hmodule,lpfun,lParam);
+}
+
+/**********************************************************************
+ *	EnumResourceNamesA	(KERNEL32.88)
+ */
+WIN_BOOL WINAPI EnumResourceNamesA( HMODULE hmodule, LPCSTR type,
+                                    ENUMRESNAMEPROCA lpfun, LONG lParam )
+{
+	/* FIXME: move WINE_MODREF stuff here */
+    return PE_EnumResourceNamesA(hmodule,type,lpfun,lParam);
+}
+/**********************************************************************
+ *	EnumResourceLanguagesA	(KERNEL32.86)
+ */
+WIN_BOOL WINAPI EnumResourceLanguagesA( HMODULE hmodule, LPCSTR type,
+                                        LPCSTR name, ENUMRESLANGPROCA lpfun,
+                                        LONG lParam)
+{
+	/* FIXME: move WINE_MODREF stuff here */
+    return PE_EnumResourceLanguagesA(hmodule,type,name,lpfun,lParam);
+}
+/**********************************************************************
+ *	    LoadResource     (KERNEL32.370)
+ */
+HGLOBAL WINAPI LoadResource( HINSTANCE hModule, HRSRC hRsrc )
+{
+    return RES_LoadResource( hModule, hRsrc);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/stubs.s	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,36 @@
+	.file	"stubs.c"
+	.version	"01.01"
+gcc2_compiled.:
+.section	.rodata
+.LC0:
+	.string	"Called unk_%s\n"
+.text
+	.align 4
+.globl unk_exp1
+	.type	 unk_exp1,@function
+unk_exp1:
+	pushl %ebp
+	movl %esp,%ebp
+	subl $4,%esp
+	movl $1,-4(%ebp)
+	movl -4(%ebp),%eax
+	movl %eax,%ecx
+	movl %ecx,%edx
+	sall $4,%edx
+	subl %eax,%edx
+	leal 0(,%edx,2),%eax
+	movl %eax,%edx
+	addl $export_names,%edx
+	pushl %edx
+	pushl $.LC0
+	call printf
+	addl $8,%esp
+	xorl %eax,%eax
+	jmp .L1
+	.align 4
+.L1:
+	leave
+	ret
+.Lfe1:
+	.size	 unk_exp1,.Lfe1-unk_exp1
+	.ident	"GCC: (GNU) egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/vfl.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,330 @@
+/*
+ * Copyright 1998 Marcus Meissner
+ */
+#include <config.h>
+
+#include <stdio.h>
+#include <string.h>
+
+#include "wine/winbase.h"
+#include "wine/windef.h"
+#include "wine/winuser.h"
+#include "wine/vfw.h"
+#include "wine/winestring.h"
+#include "wine/driver.h"
+#include "wine/avifmt.h"
+
+#define FIXME_(X) printf
+#define FIXME printf
+
+long VFWAPI VideoForWindowsVersion(void);
+
+extern void* my_mreq(int size, int to_zero);
+extern      void DrvClose(HDRVR hdrvr);
+extern int my_release(char* memory);
+
+long VFWAPIV ICDecompress(HIC hic,long dwFlags,LPBITMAPINFOHEADER lpbiFormat,void* lpData,LPBITMAPINFOHEADER lpbi,void* lpBits);
+
+WIN_BOOL VFWAPI	ICInfo(long fccType, long fccHandler, ICINFO * lpicinfo);
+LRESULT	VFWAPI	ICGetInfo(HIC hic,ICINFO *picinfo, long cb);
+HIC	VFWAPI	ICOpen(long fccType, long fccHandler, UINT wMode);
+HIC	VFWAPI	ICOpenFunction(long fccType, long fccHandler, unsigned int wMode, void* lpfnHandler);
+
+LRESULT VFWAPI ICClose(HIC hic);
+LRESULT	VFWAPI ICSendMessage(HIC hic, unsigned int msg, long dw1, long dw2);
+HIC	VFWAPI ICLocate(long fccType, long fccHandler, LPBITMAPINFOHEADER lpbiIn, LPBITMAPINFOHEADER lpbiOut, short wFlags);
+
+#define OpenDriverA DrvOpen
+extern HDRVR VFWAPI DrvOpen(long);
+#define STORE_ALL \
+    __asm__ ( \
+    "push %%ebx\n\t" \
+    "push %%ecx\n\t" \
+    "push %%edx\n\t" \
+    "push %%esi\n\t" \
+    "push %%edi\n\t"::)
+
+#define REST_ALL \
+    __asm__ ( \
+    "pop %%edi\n\t" \
+    "pop %%esi\n\t" \
+    "pop %%edx\n\t" \
+    "pop %%ecx\n\t" \
+    "pop %%ebx\n\t"::)
+
+
+typedef struct {
+    unsigned int               uDriverSignature;
+    void*        hDriverModule;
+    DRIVERPROC        DriverProc;
+    long                dwDriverID;
+} DRVR;
+
+/***********************************************************************
+ *		VideoForWindowsVersion		[MSVFW.2][MSVIDEO.2]
+ * Returns the version in major.minor form.
+ * In Windows95 this returns 0x040003b6 (4.950)
+ */
+long VideoForWindowsVersion(void) {
+	return 0x040003B6; /* 4.950 */
+}
+
+/* system.ini: [drivers] */
+
+/***********************************************************************
+ *		ICInfo				[MSVFW.33]
+ * Get information about an installable compressor. Return TRUE if there
+ * is one.
+ */
+int VFWAPI
+ICInfo(
+	long fccType,		/* [in] type of compressor ('vidc') */
+	long fccHandler,	/* [in] <n>th compressor */
+	ICINFO *lpicinfo	/* [out] information about compressor */
+) {
+  char	type[5];
+
+	memcpy(type,&fccType,4);type[4]=0;
+	
+	/* does OpenDriver/CloseDriver */
+	lpicinfo->dwSize = sizeof(ICINFO);
+	lpicinfo->fccType = fccType;
+	lpicinfo->dwFlags = 0;
+/*
+	if (GetPrivateProfileStringA("drivers32",NULL,NULL,buf,2000,"system.ini")) {
+		char *s = buf;
+		while (*s) {
+			if (!lstrncmpiA(type,s,4)) {
+				if(!fccHandler--) {
+					lpicinfo->fccHandler = mmioStringToFOURCCA(s+5,0);
+					return TRUE;
+				}
+			}
+			s=s+lstrlenA(s)+1; 
+    		}
+	}
+*/
+	return TRUE;
+}
+
+/***********************************************************************
+ *		ICOpen				[MSVFW.37]
+ * Opens an installable compressor. Return special handle.
+ */
+HIC VFWAPI
+ICOpen(long fccType,long fccHandler,unsigned int wMode) {
+	char		type[5],handler[5],codecname[20];
+	ICOPEN		icopen;
+	HDRVR		hdrv;
+	WINE_HIC	*whic;
+
+	memcpy(type,&fccType,4);type[4]=0;
+	memcpy(handler,&fccHandler,4);handler[4]=0;
+	
+	sprintf(codecname,"%s.%s",type,handler);
+
+	/* Well, lParam2 is in fact a LPVIDEO_OPEN_PARMS, but it has the 
+	 * same layout as ICOPEN
+	 */
+	icopen.fccType		= fccType;
+	icopen.fccHandler	= fccHandler;
+	icopen.dwSize		= sizeof(ICOPEN);
+	icopen.dwFlags		= wMode;
+	/* FIXME: do we need to fill out the rest too? */
+//	hdrv=OpenDriverA(codecname,"drivers32",(long)&icopen);
+	hdrv=OpenDriverA((long)&icopen);
+/*
+	if (!hdrv) {
+	    if (!strcasecmp(type,"vids")) {
+		sprintf(codecname,"vidc.%s",handler);
+		fccType = mmioFOURCC('v','i','d','c');
+	    }
+//	    hdrv=OpenDriverA(codecname,"drivers32",(long)&icopen);
+	    hdrv=OpenDriverA((long)&icopen);
+*/
+	if (!hdrv)
+	    return 0;
+//	}
+	whic = (WINE_HIC*)my_mreq(sizeof(WINE_HIC), 0);
+	whic->hdrv	= hdrv;
+	whic->driverproc= ((DRVR*)hdrv)->DriverProc;
+//	whic->private	= ICSendMessage((HIC)whic,DRV_OPEN,0,(long)&icopen);
+	whic->private	= ((DRVR*)hdrv)->dwDriverID;
+	return (HIC)whic;
+}
+
+/***********************************************************************
+ *		ICOpenFunction			[MSVFW.38]
+ */
+HIC VFWAPI ICOpenFunction(long fccType, long fccHandler, unsigned int wMode,
+void* lpfnHandler) {
+	char		type[5],handler[5];
+	HIC		hic;
+	WINE_HIC	*whic;
+
+	memcpy(type,&fccType,4);type[4]=0;
+	memcpy(handler,&fccHandler,4);handler[4]=0;
+	FIXME("(%s,%s,%d,%p), stub!\n",type,handler,wMode,lpfnHandler);
+	hic = ICOpen(fccType,fccHandler,wMode);
+	if (!hic)
+		return hic;
+	whic = (WINE_HIC*)hic;
+	whic->driverproc = (DRIVERPROC)lpfnHandler;
+	return hic;
+}
+
+
+/***********************************************************************
+ *		ICGetInfo			[MSVFW.30]
+ */
+LRESULT VFWAPI
+ICGetInfo(HIC hic,ICINFO *picinfo,long cb) {
+	LRESULT		ret;
+
+	ret = ICSendMessage(hic,ICM_GETINFO,(long)picinfo,cb);
+	
+	return ret;
+}
+
+/***********************************************************************
+ *		ICLocate			[MSVFW.35]
+ */
+HIC  VFWAPI
+ICLocate(
+	long fccType, long fccHandler, LPBITMAPINFOHEADER lpbiIn,
+	LPBITMAPINFOHEADER lpbiOut, short wMode
+) {
+	char	type[5],handler[5];
+	HIC	hic;
+	long	querymsg;
+
+	switch (wMode) {
+	case ICMODE_FASTCOMPRESS:
+	case ICMODE_COMPRESS: 
+		querymsg = ICM_COMPRESS_QUERY;
+		break;
+	case ICMODE_DECOMPRESS:
+	case ICMODE_FASTDECOMPRESS:
+		querymsg = ICM_DECOMPRESS_QUERY;
+		break;
+	case ICMODE_DRAW:
+		querymsg = ICM_DRAW_QUERY;
+		break;
+	default:
+		FIXME("Unknown mode (%d)\n",wMode);
+		return 0;
+	}
+
+	/* Easy case: handler/type match, we just fire a query and return */
+	hic = ICOpen(fccType,fccHandler,wMode);
+	if (hic) {
+		if (!ICSendMessage(hic,querymsg,(long)lpbiIn,(long)lpbiOut))
+			return hic;
+		ICClose(hic);
+	}
+	type[4]='\0';memcpy(type,&fccType,4);
+	handler[4]='\0';memcpy(handler,&fccHandler,4);
+	if (fccType==streamtypeVIDEO) {
+		hic = ICLocate(ICTYPE_VIDEO,fccHandler,lpbiIn,lpbiOut,wMode);
+		if (hic)
+			return hic;
+	}
+	FIXME("(%s,%s,%p,%p,0x%04x),unhandled!\n",type,handler,lpbiIn,lpbiOut,wMode);
+	return 0;
+}
+
+/***********************************************************************
+ *		ICCompress			[MSVFW.23]
+ */
+long VFWAPIV
+ICCompress(
+	HIC hic,long dwFlags,LPBITMAPINFOHEADER lpbiOutput,void* lpData,
+	LPBITMAPINFOHEADER lpbiInput,void* lpBits,long* lpckid,
+	long* lpdwFlags,long lFrameNum,long dwFrameSize,long dwQuality,
+	LPBITMAPINFOHEADER lpbiPrev,void* lpPrev
+) {
+	ICCOMPRESS	iccmp;
+
+	iccmp.dwFlags		= dwFlags;
+
+	iccmp.lpbiOutput	= lpbiOutput;
+	iccmp.lpOutput		= lpData;
+	iccmp.lpbiInput		= lpbiInput;
+	iccmp.lpInput		= lpBits;
+
+	iccmp.lpckid		= lpckid;
+	iccmp.lpdwFlags		= lpdwFlags;
+	iccmp.lFrameNum		= lFrameNum;
+	iccmp.dwFrameSize	= dwFrameSize;
+	iccmp.dwQuality		= dwQuality;
+	iccmp.lpbiPrev		= lpbiPrev;
+	iccmp.lpPrev		= lpPrev;
+	return ICSendMessage(hic,ICM_COMPRESS,(long)&iccmp,sizeof(iccmp));
+}
+
+/***********************************************************************
+ *		ICDecompress			[MSVFW.26]
+ */
+long VFWAPIV 
+ICDecompress(HIC hic,long dwFlags,LPBITMAPINFOHEADER lpbiFormat,void* lpData,LPBITMAPINFOHEADER  lpbi,void* lpBits) {
+	ICDECOMPRESS	icd;
+	int result;
+	icd.dwFlags	= dwFlags;
+	icd.lpbiInput	= lpbiFormat;
+	icd.lpInput	= lpData;
+
+	icd.lpbiOutput	= lpbi;
+	icd.lpOutput	= lpBits;
+	icd.ckid	= 0;
+	STORE_ALL;
+	result=ICSendMessage(hic,ICM_DECOMPRESS,(long)&icd,sizeof(icd));
+	REST_ALL;
+	return result;
+}
+
+/***********************************************************************
+ *		ICSendMessage			[MSVFW.40]
+ */
+LRESULT VFWAPI
+ICSendMessage(HIC hic,unsigned int msg,long lParam1,long lParam2) {
+	LRESULT		ret;
+	WINE_HIC	*whic = (WINE_HIC*)hic;
+	char qw[200];
+
+    __asm__ __volatile__ ("fsave (%0)\n\t": :"r"(&qw));    
+    STORE_ALL;	
+        /*__asm__
+	(
+	    "pushl %eax\n\t"
+    	    "movl $0xf,%eax\n\t"
+	    "movw %ax, %fs\n\t"
+	    "popl %eax\n\t"
+        );*/
+    	ret = whic->driverproc(whic->private,1,msg,lParam1,lParam2);
+    REST_ALL;	
+    __asm__ __volatile__ ("frstor (%0)\n\t": :"r"(&qw));    
+//	} else
+
+//		ret = SendDriverMessage(whic->hdrv,msg,lParam1,lParam2);
+//	TRACE("	-> 0x%08lx\n",ret);
+	return ret;
+}
+
+
+/***********************************************************************
+ *		ICClose			[MSVFW.22]
+ */
+LRESULT VFWAPI ICClose(HIC hic) {
+	WINE_HIC	*whic = (WINE_HIC*)hic;
+	/* FIXME: correct? */
+//	CloseDriver(whic->hdrv,0,0);
+        DrvClose(whic->hdrv);
+//#warning FIXME: DrvClose
+	my_release(whic);
+	return 0;
+}
+int VFWAPI ICDoSomething()
+{
+  return 0;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/win32.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,1706 @@
+/***********************************************************
+
+	Win32 emulation code. Functions that emulate
+	responses from corresponding Win32 API calls.
+         Since we are not going to be able to load 
+       virtually any DLL, we can only implement this
+      much, adding needed functions with each new codec.
+
+************************************************************/
+
+#include <config.h>
+
+#include "win32.h"
+#include <stdio.h>
+#include <pthread.h>
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#else
+#include <stdlib.h>
+#endif
+#include <time.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/timeb.h>
+
+#include <wine/winbase.h>
+#include <wine/winreg.h>
+#include <wine/winnt.h>
+#include <wine/winerror.h>
+#include <wine/debugtools.h>
+#include <wine/module.h>
+
+#include <registry.h>
+#include <loader.h>
+#ifdef USE_TSC
+static unsigned int localcount()
+{
+    int a;
+    __asm__ __volatile__("rdtsc\n\t"
+    :"=a"(a)
+    :
+    :"edx");
+    return a;
+}
+static void longcount(long long* z)
+{
+    __asm__ __volatile__(
+    "pushl %%ebx\n\t"
+    "movl %%eax, %%ebx\n\t"
+    "rdtsc\n\t"
+    "movl %%eax, 0(%%ebx)\n\t"
+    "movl %%edx, 4(%%ebx)\n\t"
+    "popl %%ebx\n\t"
+    ::"a"(z));
+}    
+#else
+#include <sys/time.h>
+#include <unistd.h>
+static unsigned int localcount()
+{
+    struct timeval tv;
+    unsigned limit=~0;
+    limit/=1000000;
+    gettimeofday(&tv, 0);
+    return limit*tv.tv_usec;
+}
+static void longcount(long long* z)
+{
+    struct timeval tv;
+    unsigned long long result;
+    unsigned limit=~0;
+    if(!z)return;
+    limit/=1000000;
+    gettimeofday(&tv, 0);
+    result=tv.tv_sec;
+    result<<=32;
+    result+=limit*tv.tv_usec;
+    *z=result;
+}
+#endif
+
+void dbgprintf(char* fmt, ...)
+{
+#ifdef DETAILED_OUT
+#if 1
+    va_list va;
+    va_start(va, fmt);
+    vprintf(fmt, va);
+    va_end(va);
+#else
+    va_list va;
+    FILE* f;
+    va_start(va, fmt);
+    f=fopen("./log", "a");
+    if(f==0)return;
+    vfprintf(f, fmt, va);
+    fsync(f);
+    fclose(f);
+#endif
+#endif
+}    
+char export_names[500][30]={
+"name1",
+//"name2",
+//"name3"
+};
+//#define min(x,y) ((x)<(y)?(x):(y))
+
+static unsigned char* heap=NULL; 
+static int heap_counter=0;
+void test_heap()
+{
+    int offset=0;	
+    if(heap==0)
+	return;
+    while(offset<heap_counter)
+    {
+	if(*(int*)(heap+offset)!=0x433476)
+	{
+	    printf("Heap corruption at address %d\n", offset);
+	    return;
+	}
+	offset+=8+*(int*)(heap+offset+4);
+    }
+    for(;offset<min(offset+1000, 20000000); offset++)
+	if(heap[offset]!=0xCC)
+	    {
+		printf("Free heap corruption at address %d\n", offset);
+	}	    
+}
+#undef MEMORY_DEBUG
+
+#ifdef MEMORY_DEBUG
+
+void* my_mreq(int size, int to_zero)
+{
+    static int test=0;
+    test++;
+    if(test%10==0)printf("Memory: %d bytes allocated\n", heap_counter);
+//    test_heap();
+    if(heap==NULL)
+    {
+	heap=malloc(20000000);
+	memset(heap, 0xCC,20000000);
+    }
+    if(heap==0)
+    {
+	printf("No enough memory\n");
+	return 0;
+    }	
+    if(heap_counter+size>20000000)
+    {
+	printf("No enough memory\n");
+	return 0;
+    }	
+    *(int*)(heap+heap_counter)=0x433476;
+    heap_counter+=4;
+    *(int*)(heap+heap_counter)=size;
+    heap_counter+=4;
+    printf("Allocated %d bytes of memory: sys %d, user %d-%d\n", size, heap_counter-8, heap_counter, heap_counter+size);
+    if(to_zero)
+    	memset(heap+heap_counter, 0, size);	    
+    heap_counter+=size;
+    return heap+heap_counter-size;	
+}
+int my_release(char* memory)
+{
+//    test_heap();
+    if(memory==NULL)
+    {
+	printf("ERROR: free(0)\n");
+	return 0;
+    }	
+    if(*(int*)(memory-8)!=0x433476)
+    {
+	printf("MEMORY CORRUPTION !!!!!!!!!!!!!!!!!!!\n");
+	return 0;
+    }
+    printf("Freed %d bytes of memory\n", *(int*)(memory-4));
+//    memset(memory-8, *(int*)(memory-4), 0xCC);
+    return 0;
+}    	     
+
+#else
+void* my_mreq(int size, int to_zero)
+{
+    void* answer; 
+    if(to_zero)
+	answer=calloc(size+4, 1);
+    else
+	answer=malloc(size+4);
+    *(int*)answer=size;
+    return (int*)answer+1;
+}	
+int my_release(char* memory)
+{
+    if(memory==0)return 0;
+    free(memory-4);
+    return 0;
+}
+#endif
+int my_size(char* memory)
+{
+    return *(int*)(memory-4);
+}    
+
+extern int unk_exp1;
+char extcode[20000];// place for 200 unresolved exports
+int pos=0;
+
+int WINAPI ext_unknown()
+{
+    printf("Unknown func called\n");
+    return 0;
+}    
+int WINAPI expIsBadWritePtr(void* ptr, unsigned int count)
+{
+    dbgprintf("IsBadWritePtr(%x, %x)\n", ptr, count);
+    if(count==0)
+	return 0;
+    if(ptr==0)
+        return 1;
+    return 0;
+}
+int WINAPI expIsBadReadPtr(void* ptr, unsigned int count)
+{
+    dbgprintf("IsBadReadPtr(%x, %x)\n", ptr, count);
+    if(count==0)
+	return 0;
+    if(ptr==0)
+        return 1;
+    return 0;
+}
+void* CDECL expmalloc(int size)
+{
+//printf("malloc");
+//    return malloc(size);
+    void* result=my_mreq(size,0);
+    dbgprintf("malloc(%x)\n", size);
+    if(result==0)
+    {
+	dbgprintf("returns 0\n");
+	printf("WARNING: malloc() failed\n");
+    }	
+    return result;
+}
+void CDECL expfree(void* mem)
+{
+//    return free(mem);
+    dbgprintf("free(%x)\n", mem);
+    my_release(mem);
+}
+void* CDECL expnew(int size)
+{
+//    printf("NEW:: Call from address %08x\n STACK DUMP:\n", *(-1+(int*)&size));
+//    printf("%08x %08x %08x %08x\n",
+//    size, *(1+(int*)&size),
+//    *(2+(int*)&size),*(3+(int*)&size));
+    void* result=expmalloc(size);
+    dbgprintf("new(%x)\n", size);
+    if(result==0)
+    {
+	dbgprintf("returns 0\n");
+	printf("WARNING: malloc() failed\n");
+    }	
+    return result;
+
+}    
+int CDECL expdelete(void* memory)
+{
+    dbgprintf("delete(%x)\n", memory);
+    expfree(memory);
+    return 0;
+}
+int WINAPI expDisableThreadLibraryCalls(int module)
+{
+    dbgprintf("DisableThreadLibraryCalls(%x)\n", module);
+    return 0;
+}    
+int CDECL exp_initterm(int v1, int v2)
+{
+    return 0;
+}    
+
+typedef struct {
+    unsigned int     	uDriverSignature;
+    void*        	hDriverModule;
+    void*    		DriverProc;
+    unsigned int        dwDriverID;
+} DRVR;
+
+void* WINAPI expGetDriverModuleHandle(DRVR* pdrv)
+{
+    dbgprintf("GetDriverModuleHandle(%x)\n", pdrv);
+    return pdrv->hDriverModule;
+}
+
+void* WINAPI expGetModuleHandleA(const char* name)
+{
+	WINE_MODREF* wm;
+        dbgprintf("GetModuleHandleA(%s)\n", name);
+	if(!name)return 0;
+        wm=MODULE_FindModule(name);
+        if(wm==0)return 0;
+        return (void*)(wm->module);
+}
+struct th_list_t;
+typedef struct th_list_t{
+int id;
+void* thread;
+struct th_list_t* next;
+struct th_list_t* prev;
+}th_list;
+
+static th_list* list=NULL;
+
+
+
+void* WINAPI expCreateThread(void* pSecAttr, long dwStackSize, void* lpStartAddress,
+	void* lpParameter, long dwFlags, long* dwThreadId)
+{
+    pthread_t *pth;
+//    printf("CreateThread:");
+    pth=my_mreq(sizeof(pthread_t), 0);
+    dbgprintf("pthread_create\n");
+    pthread_create(pth, NULL, (void*(*)(void*))lpStartAddress, lpParameter);
+    if(dwFlags)
+	dbgprintf( "WARNING: CreateThread flags not supported\n");
+    if(dwThreadId)
+	*dwThreadId=(long)pth;
+    dbgprintf( "Created thread %08X\n", pth);
+    if(list==NULL)
+    {
+	list=my_mreq(sizeof(th_list), 1);
+	list->next=list->prev=NULL;
+    }
+    else
+    {
+	list->next=my_mreq(sizeof(th_list), 0);
+	list->next->prev=list;
+	list->next->next=NULL;
+	list=list->next;
+    }		
+    list->thread=pth;
+    return pth;
+}
+
+struct mutex_list_t;
+
+struct mutex_list_t
+{
+    pthread_mutex_t *pm;
+    char name[64];
+    struct mutex_list_t* next;
+    struct mutex_list_t* prev;
+};
+typedef struct mutex_list_t mutex_list;
+static mutex_list* mlist=NULL; 
+void* WINAPI expCreateEventA(void* pSecAttr, char bManualReset, 
+    char bInitialState, const char* name)
+{
+#warning ManualReset
+    pthread_mutex_t *pm;
+    dbgprintf("CreateEvent\n");
+    if(mlist!=NULL)
+    {
+	mutex_list* pp=mlist;
+	if(name!=NULL)
+	do
+	{
+	    if(strcmp(pp->name, name)==0)
+		return pp->pm;
+	}while(pp=pp->prev);
+    }	
+    pm=my_mreq(sizeof(pthread_mutex_t), 0);
+    pthread_mutex_init(pm, NULL);
+    if(mlist==NULL)
+    {
+	mlist=my_mreq(sizeof(mutex_list), 00);
+	mlist->next=mlist->prev=NULL;
+    }
+    else
+    {
+	mlist->next=my_mreq(sizeof(mutex_list), 00);
+	mlist->next->prev=mlist->next;
+	mlist->next->next=NULL;
+	mlist=mlist->next;
+    }
+    mlist->pm=pm;
+    if(name!=NULL)
+        strncpy(mlist->name, name, 64);
+	else
+	mlist->name[0]=0;
+    if(pm==NULL)
+	dbgprintf("ERROR::: CreateEventA failure\n");
+    if(bInitialState)
+        pthread_mutex_lock(pm);
+    return pm;
+}    
+
+void* WINAPI expSetEvent(void* event)
+{
+    dbgprintf("Trying to lock %X\n", event);
+    pthread_mutex_lock(event);
+}
+void* WINAPI expResetEvent(void* event)
+{
+    dbgprintf("Unlocking %X\n", event);
+    pthread_mutex_unlock(event);    
+}
+
+void* WINAPI expWaitForSingleObject(void* object, int duration)
+{
+#warning not sure
+    dbgprintf("WaitForSingleObject: duration %d\n", duration);
+    pthread_mutex_lock(object);
+    pthread_mutex_unlock(object);
+}    
+
+static BYTE PF[64] = {0,};
+
+void WINAPI expGetSystemInfo(SYSTEM_INFO* si)
+{
+    	/* FIXME: better values for the two entries below... */
+	static int cache = 0;
+	static SYSTEM_INFO cachedsi;
+	HKEY	xhkey=0,hkey;
+        dbgprintf("GetSystemInfo()\n");
+
+	if (cache) {
+		memcpy(si,&cachedsi,sizeof(*si));
+		return;
+	}
+	memset(PF,0,sizeof(PF));
+
+	cachedsi.u.s.wProcessorArchitecture     = PROCESSOR_ARCHITECTURE_INTEL;
+	cachedsi.dwPageSize 			= getpagesize();
+
+	/* FIXME: better values for the two entries below... */
+	cachedsi.lpMinimumApplicationAddress	= (void *)0x40000000;
+	cachedsi.lpMaximumApplicationAddress	= (void *)0x7FFFFFFF;
+	cachedsi.dwActiveProcessorMask		= 1;
+	cachedsi.dwNumberOfProcessors		= 1;
+	cachedsi.dwProcessorType		= PROCESSOR_INTEL_386;
+	cachedsi.dwAllocationGranularity	= 0x10000;
+	cachedsi.wProcessorLevel		= 3; /* pentium */
+	cachedsi.wProcessorRevision		= 0;
+	
+#ifdef __FreeBSD__
+        cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
+        cachedsi.wProcessorLevel= 5;
+	PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
+#ifdef MMX
+        PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
+#endif
+        cachedsi.dwNumberOfProcessors=1;
+#else
+	{
+	char buf[20];
+	char line[200];
+	FILE *f = fopen ("/proc/cpuinfo", "r");
+
+	if (!f)
+		return;
+        xhkey = 0;
+	while (fgets(line,200,f)!=NULL) {
+		char	*s,*value;
+
+		/* NOTE: the ':' is the only character we can rely on */
+		if (!(value = strchr(line,':')))
+			continue;
+		/* terminate the valuename */
+		*value++ = '\0';
+		/* skip any leading spaces */
+		while (*value==' ') value++;
+		if ((s=strchr(value,'\n')))
+			*s='\0';
+
+		/* 2.1 method */
+		if (!lstrncmpiA(line, "cpu family",strlen("cpu family"))) {
+			if (isdigit (value[0])) {
+				switch (value[0] - '0') {
+				case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
+					cachedsi.wProcessorLevel= 3;
+					break;
+				case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
+					cachedsi.wProcessorLevel= 4;
+					break;
+				case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
+					cachedsi.wProcessorLevel= 5;
+					break;
+				case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
+					cachedsi.wProcessorLevel= 5;
+					break;
+				default:cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
+					cachedsi.wProcessorLevel= 5;
+					break;
+				}
+			}
+			/* set the CPU type of the current processor */
+			sprintf(buf,"CPU %ld",cachedsi.dwProcessorType);
+			continue;
+		}
+		/* old 2.0 method */
+		if (!lstrncmpiA(line, "cpu",strlen("cpu"))) {
+			if (	isdigit (value[0]) && value[1] == '8' && 
+				value[2] == '6' && value[3] == 0
+			) {
+				switch (value[0] - '0') {
+				case 3: cachedsi.dwProcessorType = PROCESSOR_INTEL_386;
+					cachedsi.wProcessorLevel= 3;
+					break;
+				case 4: cachedsi.dwProcessorType = PROCESSOR_INTEL_486;
+					cachedsi.wProcessorLevel= 4;
+					break;
+				case 5: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
+					cachedsi.wProcessorLevel= 5;
+					break;
+				case 6: cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
+					cachedsi.wProcessorLevel= 5;
+					break;
+				default:cachedsi.dwProcessorType = PROCESSOR_INTEL_PENTIUM;
+					cachedsi.wProcessorLevel= 5;
+					break;
+				}
+			}
+			/* set the CPU type of the current processor */
+			sprintf(buf,"CPU %ld",cachedsi.dwProcessorType);
+			continue;
+		}
+		if (!lstrncmpiA(line,"fdiv_bug",strlen("fdiv_bug"))) {
+			if (!lstrncmpiA(value,"yes",3))
+				PF[PF_FLOATING_POINT_PRECISION_ERRATA] = TRUE;
+
+			continue;
+		}
+		if (!lstrncmpiA(line,"fpu",strlen("fpu"))) {
+			if (!lstrncmpiA(value,"no",2))
+				PF[PF_FLOATING_POINT_EMULATED] = TRUE;
+
+			continue;
+		}
+		if (!lstrncmpiA(line,"processor",strlen("processor"))) {
+			/* processor number counts up...*/
+			int	x;
+
+			if (sscanf(value,"%d",&x))
+				if (x+1>cachedsi.dwNumberOfProcessors)
+					cachedsi.dwNumberOfProcessors=x+1;
+
+			/* Create a new processor subkey on a multiprocessor
+			 * system
+			 */
+			sprintf(buf,"%d",x);
+		}
+		if (!lstrncmpiA(line,"stepping",strlen("stepping"))) {
+			int	x;
+
+			if (sscanf(value,"%d",&x))
+				cachedsi.wProcessorRevision = x;
+		}
+		if ( (!lstrncmpiA(line,"flags",strlen("flags"))) ||
+                     (!lstrncmpiA(line,"features",strlen("features"))) ) {
+			if (strstr(value,"cx8"))
+				PF[PF_COMPARE_EXCHANGE_DOUBLE] = TRUE;
+			if (strstr(value,"mmx"))
+				PF[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
+
+		}
+	}
+	fclose (f);
+	}
+#endif /* __FreeBSD__ */
+	memcpy(si,&cachedsi,sizeof(*si));
+}
+
+long WINAPI expGetVersion()
+{
+    return 0xC0000A04;//Windows 98
+}    
+
+HANDLE WINAPI expHeapCreate(long flags, long init_size, long max_size)
+{
+//    printf("HeapCreate:");
+    dbgprintf("HeapCreate(%X, %X, %X)\n", flags, init_size, max_size); 
+    if(init_size==0)
+    	return (HANDLE)my_mreq(0x110000, 0);
+    else
+	return (HANDLE)my_mreq(init_size, 0);
+}		
+void* WINAPI expHeapAlloc(HANDLE heap, int flags, int size)
+{
+    void* z;
+    dbgprintf("HeapAlloc(%X, %X, %X)\n", heap, flags, size); 
+//    printf("HeapAlloc:");
+    z=my_mreq(size, flags&8);    
+//    z=HeapAlloc(heap,flags,size);
+    if(z==0)
+	printf("HeapAlloc failure\n");
+    return z;
+}
+long WINAPI expHeapDestroy(void* heap)
+{
+    dbgprintf("HeapDestroy(%X)\n", heap); 
+    my_release(heap);
+    return 1;
+}
+
+long WINAPI expHeapFree(int arg1, int arg2, void* ptr)
+{
+    dbgprintf("HeapFree(%X, %X, %X)\n", arg1, arg2, ptr);
+    my_release(ptr);
+    return 1;
+}    	
+long WINAPI expHeapSize(int heap, int flags, void* pointer)
+{
+    return my_size(pointer);
+} 
+long WINAPI expGetProcessHeap(void)
+{
+    return 1;
+}    
+void* WINAPI expVirtualAlloc(void* v1, long v2, long v3, long v4)
+{
+    void* z;
+    dbgprintf("VirtualAlloc(%d %d %d %d) \n",v1,v2,v3,v4);
+    z=VirtualAlloc(v1, v2, v3, v4);
+    if(z==0)
+	printf("VirtualAlloc failure\n");
+    return z;
+}
+int WINAPI expVirtualFree(void* v1, int v2, int v3)
+{
+    dbgprintf("VirtualFree(%X %X %X) \n",v1,v2,v3);
+    return VirtualFree(v1,v2,v3);
+}    
+struct CRITSECT 
+{
+    pthread_t id;
+    pthread_mutex_t mutex;
+    int locked;
+};
+void WINAPI expInitializeCriticalSection(CRITICAL_SECTION* c)
+{
+    struct CRITSECT cs;
+    dbgprintf("InitCriticalSection(%X) \n", c);
+/*    if(sizeof(pthread_mutex_t)>sizeof(CRITICAL_SECTION))
+    {
+	printf(" ERROR:::: sizeof(pthread_mutex_t) is %d, expected <=%d!\n",
+	     sizeof(pthread_mutex_t), sizeof(CRITICAL_SECTION));
+	return;
+    }*/
+/*    pthread_mutex_init((pthread_mutex_t*)c, NULL);   */
+    pthread_mutex_init(&cs.mutex, NULL);   
+    cs.locked=0;
+    *(void**)c=malloc(sizeof cs);
+    memcpy(*(void**)c, &cs, sizeof cs);
+    return;
+}          
+void WINAPI expEnterCriticalSection(CRITICAL_SECTION* c)
+{
+    struct CRITSECT* cs=(struct CRITSECT*)c;
+    dbgprintf("EnterCriticalSection(%X) \n",c);
+//    cs.id=pthread_self();
+    if(cs->locked)
+	if(cs->id==pthread_self())
+	    return;
+    pthread_mutex_lock(&(cs->mutex));
+    cs->locked=1;
+    cs->id=pthread_self();
+    return;
+}          
+void WINAPI expLeaveCriticalSection(CRITICAL_SECTION* c)
+{
+    struct CRITSECT* cs=(struct CRITSECT*)c;
+    dbgprintf("LeaveCriticalSection(%X) \n",c);
+    cs->locked=0;
+    pthread_mutex_unlock(&(cs->mutex));
+    return;
+}
+void WINAPI expDeleteCriticalSection(CRITICAL_SECTION *c)
+{
+    dbgprintf("DeleteCriticalSection(%X) \n",c);
+    pthread_mutex_destroy((pthread_mutex_t*)c);
+    return;
+}
+int WINAPI expGetCurrentThreadId()
+{
+    dbgprintf("GetCurrentThreadId() \n");
+    return getpid();
+}                  
+struct tls_s;
+typedef struct tls_s
+{
+    void* value;
+    int used;
+    struct tls_s* prev;
+    struct tls_s* next;
+}tls_t;
+
+tls_t* g_tls=NULL;    
+    
+void* WINAPI expTlsAlloc()
+{
+    dbgprintf("TlsAlloc \n");
+    if(g_tls==NULL)
+    {
+	g_tls=my_mreq(sizeof(tls_t), 0);
+	g_tls->next=g_tls->prev=NULL;
+    }
+    else
+    {
+	g_tls->next=my_mreq(sizeof(tls_t), 0);
+	g_tls->next->prev=g_tls;
+	g_tls->next->next=NULL;
+	g_tls=g_tls->next;
+    }
+    return g_tls;
+}
+
+int WINAPI expTlsSetValue(tls_t* index, void* value)
+{
+    dbgprintf("TlsSetVal(%X %X) \n", index, value );
+    if(index==0)
+	return 0;
+    index->value=value;
+    return 1;
+}
+void* WINAPI expTlsGetValue(tls_t* index)
+{
+    dbgprintf("TlsGetVal(%X) \n", index );
+    if(index==0)
+	return 0;
+    return index->value;	
+}
+int WINAPI expTlsFree(tls_t* index)
+{
+    dbgprintf("TlsFree(%X) \n", index);
+    if(index==0)
+	return 0;
+    if(index->next)
+	index->next->prev=index->prev;
+    if(index->prev)
+        index->prev->next=index->next;
+    my_release((void*)index);
+    return 1;
+}     
+
+void* WINAPI expLocalAlloc(int flags, int size)
+{
+    void* z;
+    dbgprintf("LocalAlloc(%d, flags %X)\n", size, flags);
+    if(flags&GMEM_ZEROINIT)
+	z=my_mreq(size, 1);
+    else
+	z=my_mreq(size, 0);
+    if(z==0)
+	printf("LocalAlloc() failed\n");
+    return z;
+}	
+void* WINAPI expLocalLock(void* z)
+{
+   dbgprintf("LocalLock\n");
+    return z;
+}    
+void* WINAPI expGlobalAlloc(int flags, int size)
+{
+    void* z;
+     dbgprintf("GlobalAlloc(%d, flags 0x%X)\n", size, flags);
+    if(flags&GMEM_ZEROINIT)
+	z=my_mreq(size, 1);
+	else
+	z=my_mreq(size, 0);
+    if(z==0)
+	printf("LocalAlloc() failed\n");
+    return z;
+}	
+void* WINAPI expGlobalLock(void* z)
+{
+     dbgprintf("GlobalLock\n");
+    return z;
+}    
+
+int WINAPI expLoadStringA(long instance, long  id, void* buf, long size)
+{
+    dbgprintf("LoadStringA\n");
+    return LoadStringA(instance, id, buf, size);
+}    	    	
+
+long WINAPI expMultiByteToWideChar(long v1, long v2, char* s1, long siz1, char* s2, int siz2)
+{
+#warning FIXME
+    dbgprintf("MB2WCh\n");
+    dbgprintf("WARNING: Unsupported call: MBToWCh %s\n", s1);       
+    if(s2==0)
+	return 1;
+    s2[0]=s2[1]=0;
+    return 1;
+}
+long WINAPI expWideCharToMultiByte(long v1, long v2, short* s1, long siz1, char* s2, int siz2, char* c3, int* siz3)
+{
+    int result;
+    dbgprintf("WCh2MB\n");
+    result=WideCharToMultiByte(v1, v2, s1, siz1, s2, siz2, c3, siz3);
+    dbgprintf("=> %d\n", result);
+    return result;
+}
+long WINAPI expGetVersionExA(OSVERSIONINFOA* c)
+{
+    dbgprintf("GetVersionExA\n");
+    c->dwMajorVersion=4;
+    c->dwMinorVersion=10;
+    c->dwBuildNumber=0x40a07ce;
+    c->dwPlatformId=VER_PLATFORM_WIN32_WINDOWS;
+    strcpy(c->szCSDVersion, "Win98");
+    return 1;
+}        
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
+HANDLE WINAPI expCreateSemaphoreA(char* v1, long init_count, long max_count, char* name)
+{
+#warning FIXME
+/*    struct sembuf buf[1];
+    int sem=semget(IPC_PRIVATE,1,IPC_CREAT);
+    if(sem==-1)
+    {
+	printf("semget() failed\n");
+	return (HANDLE)-1;
+    }	
+    buf[0].sem_num=0;
+    printf("%s\n", name);
+    printf("Init count %d, max count %d\n", init_count, max_count);
+    buf[0].sem_op=-max_count+init_count;
+    buf[0].sem_flg=0;
+    if(semop(sem, &buf, 1)<0)
+    {
+	printf("semop() failed\n");
+    }
+    return sem;	
+*/    
+    void* z;
+    dbgprintf("CreateSemaphoreA\n");
+    z=my_mreq(24, 0);
+    pthread_mutex_init(z, NULL);
+    return (HANDLE)z;
+}
+        
+long WINAPI expReleaseSemaphore(long hsem, long increment, long* prev_count)
+{
+// The state of a semaphore object is signaled when its count 
+// is greater than zero and nonsignaled when its count is equal to zero
+// Each time a waiting thread is released because of the semaphore's signaled
+// state, the count of the semaphore is decreased by one. 
+    struct sembuf buf[1];
+    dbgprintf("ReleaseSemaphore\n");
+    dbgprintf("WARNING: Unsupported call: ReleaseSemaphoreA\n");       
+/*    if(hsem==-1)return 0;
+    buf[0].sem_num=0;
+    buf[0].sem_op=-1;
+    buf[0].sem_flg=0;
+    if(semop(hsem, &buf, 1)<0)
+    {
+	printf("ReleaseSemaphore: semop() failed\n");
+    }*/
+
+    return 1;//zero on error
+}
+
+
+long WINAPI expRegOpenKeyExA(long key, const char* subkey, long reserved, long access, int* newkey)
+{
+    dbgprintf("RegOpenKeyExA(%d,%s)\n", key, subkey);
+    return RegOpenKeyExA(key, subkey, reserved, access, newkey);
+}    
+long WINAPI expRegCloseKey(long key)
+{
+    dbgprintf("RegCloseKey()\n");
+    return RegCloseKey(key);
+}         
+long WINAPI expRegQueryValueExA(long key, const char* value, int* reserved, int* type, int* data, int* count)
+{
+    dbgprintf("RegQueryValueExA()\n");
+    return RegQueryValueExA(key, value, reserved, type, data, count);
+}  
+long WINAPI expRegCreateKeyExA(long key, const char* name, long reserved,
+							   void* classs, long options, long security,
+							   void* sec_attr, int* newkey, int* status) 
+{
+    dbgprintf("RegCreateKeyExA()\n");
+    return RegCreateKeyExA(key, name, reserved, classs, options, security, sec_attr, newkey, status);
+}
+long WINAPI expRegSetValueExA(long key, const char* name, long v1, long v2, void* data, long size)
+{
+    dbgprintf("RegSetValueExA()\n");
+    return RegSetValueExA(key, name, v1, v2, data, size);
+}        
+
+long WINAPI expRegOpenKeyA (
+long hKey,
+ LPCSTR lpSubKey,
+ int* phkResult
+){
+    return  RegOpenKeyExA(hKey, lpSubKey, 0, 0, phkResult);
+}
+
+long WINAPI expQueryPerformanceCounter(long long* z)
+{
+    dbgprintf("QueryPerformanceCounter()\n");
+    longcount(z);
+    return 1; 
+}
+
+static double old_freq()
+{
+    int i=time(NULL);
+    int x,y;
+    while(i==time(NULL));
+    x=localcount();
+    i++;
+    while(i==time(NULL));
+    y=localcount();
+    return (double)(y-x)/1000.;
+}
+static double CPU_Freq()
+{
+#ifdef USE_TSC
+	FILE *f = fopen ("/proc/cpuinfo", "r");
+	char line[200];
+	char model[200]="unknown";
+	char flags[500]="";
+	char	*s,*value;
+	double freq=-1;
+	
+	if (!f)
+	{
+	    printf("Can't open /proc/cpuinfo for reading\n");
+	    return old_freq();
+	}    
+	while (fgets(line,200,f)!=NULL) 
+	{
+		/* NOTE: the ':' is the only character we can rely on */
+		if (!(value = strchr(line,':')))
+			continue;
+		/* terminate the valuename */
+		*value++ = '\0';
+		/* skip any leading spaces */
+		while (*value==' ') value++;
+		if ((s=strchr(value,'\n')))
+			*s='\0';
+
+		if (!strncasecmp(line, "cpu MHz",strlen("cpu MHz"))) 
+		{
+		    sscanf(value, "%lf", &freq);
+		    freq*=1000;
+		    break;
+		}
+		continue;
+		
+	}
+	fclose(f);
+	if(freq<0)return old_freq();
+	return freq;
+#else
+	return old_freq();
+#endif    	
+}
+
+long WINAPI expQueryPerformanceFrequency(long long* z)
+{
+    dbgprintf("QueryPerformanceFrequency()\n");
+    *z=(long long)CPU_Freq();
+    return 1; 
+}
+long WINAPI exptimeGetTime()
+{
+    struct timeval t;
+    dbgprintf("timeGetTime()\n");
+    gettimeofday(&t, 0);
+    return 1000*t.tv_sec+t.tv_usec/1000;
+}
+void* WINAPI expLocalHandle(void* v)
+{
+    dbgprintf("LocalHandle\n");
+    return v;
+}        
+void* WINAPI expGlobalHandle(void* v)
+{
+    dbgprintf("GlobalHandle\n");
+    return v;
+}        
+int WINAPI expGlobalUnlock(void* v)
+{
+    dbgprintf("GlobalUnlock\n");
+    return 1;
+}
+//
+void* WINAPI expGlobalFree(void* v)
+{
+    dbgprintf("GlobalFree(%X)\n", v);
+    my_release(v);
+    return 0;
+}        
+
+int WINAPI expLocalUnlock(void* v)
+{
+    dbgprintf("LocalUnlock\n");
+    return 1;
+}
+//
+void* WINAPI expLocalFree(void* v)
+{
+    dbgprintf("LocalFree(%X)\n", v);
+    my_release(v);
+    return 0;
+}        
+
+HRSRC WINAPI expFindResourceA(HMODULE module, char* name, char* type)
+{
+    dbgprintf("FindResourceA\n");
+    return FindResourceA(module, name, type);
+}
+HGLOBAL WINAPI expLoadResource(HMODULE module, HRSRC res)
+{
+    dbgprintf("LoadResource\n");
+    return LoadResource(module, res);;    
+}
+void* WINAPI expLockResource(long res)
+{
+    dbgprintf("LockResource\n");
+    return LockResource(res);
+}    
+int WINAPI expFreeResource(long res)
+{
+    dbgprintf("FreeResource\n");
+    return FreeResource(res);
+}    
+//bool fun(HANDLE)
+//!0 on success
+int WINAPI expCloseHandle(long v1)
+{
+    dbgprintf("CloseHandle\n");
+    return 1;
+}    
+
+const char* WINAPI expGetCommandLineA()
+{
+    dbgprintf("GetCommandLine\n");
+    return "c:\\aviplay.exe";
+}
+LPWSTR WINAPI expGetEnvironmentStringsW()
+{
+    static wchar_t envs[]={'p', 'a', 't', 'h', ' ', 'c', ':', '\\', 0, 0};
+    dbgprintf("GetEnvStringsW\n");
+    return (LPWSTR)envs;
+}
+
+int WINAPI expFreeEnvironmentStringsW(short* strings)
+{
+    dbgprintf("FreeEnvStringsW\n");
+    return 1;
+}
+LPCSTR WINAPI expGetEnvironmentStrings()
+{
+    dbgprintf("GetEnvStrings\n");
+    return "\0\0";
+}
+
+int WINAPI expGetStartupInfoA(STARTUPINFOA *s)
+{
+    int i;    
+    dbgprintf("GetStartupInfoA\n");
+/*    
+    for(i=0; i<sizeof(STARTUPINFOA)/4; i++)
+     ((int*)s)[i]=i+0x200;
+*/
+    memset(s, 0, sizeof(*s));
+    s->cb=sizeof(*s);
+    s->lpReserved="qwe";
+    s->lpDesktop="rty";
+    s->lpTitle="uio";
+    s->dwX=s->dwY=0;
+    s->dwXSize=s->dwYSize=200;
+    s->dwFlags=s->wShowWindow=0;
+    return 1;
+}    
+
+int WINAPI expGetStdHandle(int z)
+{
+    dbgprintf("GetStdHandle\n");
+    dbgprintf("WARNING: Unsupported call: GetStdHandle\n");       
+    return 1234;
+}
+int WINAPI expGetFileType(int handle)
+{
+    dbgprintf("GetFileType\n");
+    dbgprintf("WARNING: Unsupported call: GetFileType\n");       
+    return 5678;
+}
+int WINAPI expSetHandleCount(int count)
+{
+    dbgprintf("SetHandleCount\n");
+    return 1;        
+}
+int WINAPI expGetACP()
+{
+    dbgprintf("GetACP\n");
+    dbgprintf("WARNING: Unsupported call: GetACP\n");       
+    return 0; 
+}
+extern WINE_MODREF *MODULE32_LookupHMODULE(HMODULE m);
+int WINAPI expGetModuleFileNameA(int module, char* s, int len)
+{
+    WINE_MODREF *mr;
+    dbgprintf("GetModuleFileNameA\n");
+//    printf("File name of module %X requested\n", module);
+    if(s==0)
+    return 0;
+    if(len<35)
+    return 0;
+    strcpy(s, "c:\\windows\\system\\");
+    mr=MODULE32_LookupHMODULE(module);
+    if(mr==0)//oops
+    {
+        strcat(s, "aviplay.dll");
+	return 1;
+    }	
+    if(strrchr(mr->filename, '/')==NULL)
+	strcat(s, mr->filename);
+    else
+	strcat(s, strrchr(mr->filename, '/')+1);
+    return 1;
+}    
+    
+int WINAPI expSetUnhandledExceptionFilter(void* filter)
+{
+    dbgprintf("SetUnhandledExcFilter\n");
+    return 1;//unsupported and probably won't ever be supported
+}    
+extern char* def_path;
+
+int WINAPI expLoadLibraryA(char* name)
+{
+    char qq[256];
+    dbgprintf("LoadLibraryA\n");
+    printf("They want library %s\n", name);
+    strcpy(qq, def_path);
+    strcat(qq, "/");
+    strcat(qq, name);
+    return LoadLibraryA(qq);
+}      
+int WINAPI expFreeLibrary(int module)
+{
+    dbgprintf("FreeLibrary\n");
+    return FreeLibrary(module);
+}   
+void* WINAPI expGetProcAddress(HMODULE mod, char* name)
+{
+    dbgprintf("GetProcAddress\n");
+    return GetProcAddress(mod, name);
+}    
+
+long WINAPI expCreateFileMappingA(int hFile, void* lpAttr,
+    long flProtect, long dwMaxHigh, long dwMaxLow, const char* name)
+{
+    dbgprintf("CreateFileMappingA\n");
+    return CreateFileMappingA(hFile, lpAttr, flProtect, dwMaxHigh, dwMaxLow, name);
+}    
+
+long WINAPI expOpenFileMappingA(long hFile, long hz, const char* name)
+{
+    dbgprintf("OpenFileMappingA\n");
+    return OpenFileMappingA(hFile, hz, name);
+}
+
+void* WINAPI expMapViewOfFile(HANDLE file, DWORD mode, DWORD offHigh, DWORD offLow, DWORD size)
+{
+    dbgprintf("MapViewOfFile(%d, %x, %x, %x, %x)\n",
+	file,mode,offHigh,offLow,size);
+    return (char*)file+offLow;
+}
+
+void* WINAPI expUnmapViewOfFile(void* view)
+{
+    dbgprintf("UnmapViewOfFile()\n");
+    return 0;
+}
+
+void* WINAPI expSleep(int time)
+{
+    dbgprintf("Sleep(%d)\n", time);
+    usleep(time);
+    return 0;
+}
+ // why does IV32 codec want to call this? I don't know ...
+void* WINAPI expCreateCompatibleDC(int hdc)
+{
+        dbgprintf("CreateCompatibleDC(%d)\n", hdc);
+        return (void*)129;
+}
+
+int WINAPI expGetDeviceCaps(int hdc, int unk)
+{
+        dbgprintf("GetDeviceCaps(%d, %d)\n", hdc, unk);
+        return 0;
+}
+
+WIN_BOOL WINAPI expDeleteDC(int hdc)
+{
+        dbgprintf("DeleteDC(%d)\n", hdc);
+        return 0;
+}
+
+int expwsprintfA(char* string, char* format, ...)
+{
+    va_list va;
+    va_start(va, format);
+    dbgprintf("wsprintfA\n");
+    return vsprintf(string, format, va);
+}
+
+int WINAPI expGetPrivateProfileIntA(const char* appname, const char* keyname, int default_value, const char* filename)
+{
+    int size=255;
+    char buffer[256];
+    char* fullname;
+    int result;
+    
+    buffer[255]=0;
+    dbgprintf("GetPrivateProfileIntA(%s, %s, %s)\n", appname, keyname, filename );
+    if(!(appname && keyname && filename) ) return default_value;
+    fullname=(char*)malloc(50+strlen(appname)+strlen(keyname)+strlen(filename));
+    strcpy(fullname, "Software\\IniFileMapping\\");
+    strcat(fullname, appname);
+    strcat(fullname, "\\");
+    strcat(fullname, keyname);
+    strcat(fullname, "\\");
+    strcat(fullname, filename);
+    result=RegQueryValueExA(HKEY_LOCAL_MACHINE, fullname, NULL, NULL, (int*)buffer, &size);
+    if((size>=0)&&(size<256))
+	buffer[size]=0;
+//    printf("GetPrivateProfileIntA(%s, %s, %s) -> %s\n", appname, keyname, filename, buffer);
+    free(fullname); 
+    if(result)
+    return default_value;
+    else
+	return atoi(buffer);    	
+}
+int WINAPI expGetPrivateProfileStringA(const char* appname, const char* keyname,
+	const char* def_val, char* dest, unsigned int len, const char* filename)
+{
+    int result;
+    int size;
+    char* fullname;
+    dbgprintf("GetPrivateProfileStringA(%s, %s, %s, %X, %X, %s)\n", appname, keyname, def_val, dest, len, filename );
+    if(!(appname && keyname && filename) ) return 0;
+    fullname=(char*)malloc(50+strlen(appname)+strlen(keyname)+strlen(filename));
+    strcpy(fullname, "Software\\IniFileMapping\\");
+    strcat(fullname, appname);
+    strcat(fullname, "\\");
+    strcat(fullname, keyname);
+    strcat(fullname, "\\");
+    strcat(fullname, filename);
+    size=len;
+    result=RegQueryValueExA(HKEY_LOCAL_MACHINE, fullname, NULL, NULL, (int*)dest, &size);
+//    printf("GetPrivateProfileStringA(%s, %s, %s, %X, %X, %s)\n", appname, keyname, def_val, dest, len, filename );
+    free(fullname); 
+    if(!result)
+	return size;
+    strncpy(dest, def_val, size);
+    return size;
+}
+int WINAPI expWritePrivateProfileStringA(const char* appname, const char* keyname,
+	const char* string, const char* filename)
+{
+    int size=256;
+    char* fullname;
+    dbgprintf("WritePrivateProfileStringA(%s, %s, %s, %s)\n", appname, keyname, string, filename );
+    if(!(appname && keyname && filename) ) return -1;
+    fullname=(char*)malloc(50+strlen(appname)+strlen(keyname)+strlen(filename));
+    strcpy(fullname, "Software\\IniFileMapping\\");
+    strcat(fullname, appname);
+    strcat(fullname, "\\");
+    strcat(fullname, keyname);
+    strcat(fullname, "\\");
+    strcat(fullname, filename);
+    RegSetValueExA(HKEY_LOCAL_MACHINE, fullname, 0, REG_SZ, (int*)string, strlen(string));
+//    printf("RegSetValueExA(%s,%d)\n", string, strlen(string));
+//    printf("WritePrivateProfileStringA(%s, %s, %s, %s)\n", appname, keyname, string, filename );
+    free(fullname); 
+    return 0;
+}
+
+unsigned int _GetPrivateProfileIntA(const char* appname, const char* keyname, INT default_value, const char* filename)
+{
+    return expGetPrivateProfileIntA(appname, keyname, default_value, filename);
+}
+int _GetPrivateProfileStringA(const char* appname, const char* keyname,
+	const char* def_val, char* dest, unsigned int len, const char* filename)
+{
+    return expGetPrivateProfileStringA(appname, keyname, def_val, dest, len, filename);
+}
+int _WritePrivateProfileStringA(const char* appname, const char* keyname,
+	const char* string, const char* filename)
+{
+    return expWritePrivateProfileStringA(appname, keyname, string, filename);
+}
+
+
+int WINAPI expDefDriverProc(int _private, int id, int msg, int arg1, int arg2)
+{
+    printf("Called DefDriverProc(%X)\n", msg);
+    return 0;
+}    
+
+int WINAPI expSizeofResource(int v1, int v2)
+{
+    dbgprintf("SizeofResource()\n");
+    return SizeofResource(v1, v2);
+}    
+
+int WINAPI expGetLastError()
+{
+    dbgprintf("GetLastError()\n");
+    return GetLastError();
+}
+
+void WINAPI expSetLastError(int error)
+{
+    dbgprintf("SetLastError()\n");
+    SetLastError(error);
+}        
+
+char* expstrrchr(char* string, int value)
+{
+    return strrchr(string, value);
+}    
+
+char* expstrchr(char* string, int value)
+{
+    return strchr(string, value);
+}    
+
+int WINAPI expGetFileVersionInfoSizeA(const char* name, int* lpHandle)
+{
+    printf("GetFileVersionInfoSizeA(%s,0x%X)\n", name, lpHandle);
+    return 0;
+}    
+
+int WINAPI expIsBadStringPtrW(const short* string, int nchars)
+{
+    if(string==0)return 1;
+    return 0;
+}    
+extern long WINAPI InterlockedExchangeAdd( long* dest, long incr )
+{
+    long ret;
+    __asm__ __volatile__( "lock; xaddl %0,(%1)"
+                          : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
+    return ret;
+}
+
+extern long WINAPI expInterlockedIncrement( long* dest )
+{
+    return InterlockedExchangeAdd( dest, 1 ) + 1;
+}
+extern long WINAPI expInterlockedDecrement( long* dest )
+{
+    return InterlockedExchangeAdd( dest, -1 ) - 1;
+}
+
+extern void WINAPI expOutputDebugStringA( const char* string )
+{
+    fprintf(stderr, "DEBUG: %s\n", string);
+}    
+
+int WINAPI expGetDC(int hwnd)
+{
+    return 0;
+}
+
+int WINAPI expGetDesktopWindow()
+{
+    return 0;
+}
+     
+int WINAPI expReleaseDC(int hwnd, int hdc)
+{
+    return 0;
+}    
+
+int WINAPI expGetSystemPaletteEntries(int hdc, int iStartIndex, int nEntries, void* lppe)
+{
+    return 0;
+}    
+/*
+typedef struct _TIME_ZONE_INFORMATION {
+    long Bias;
+    char StandardName[32];
+    SYSTEMTIME StandardDate;
+    long StandardBias;
+    char DaylightName[32];
+    SYSTEMTIME DaylightDate;
+    long DaylightBias;
+} TIME_ZONE_INFORMATION, *LPTIME_ZONE_INFORMATION;    
+*/
+
+int WINAPI expGetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation)
+{
+    memset(lpTimeZoneInformation, 0, sizeof(TIME_ZONE_INFORMATION));
+    return 0;
+}    
+
+void WINAPI expGetLocalTime(SYSTEMTIME* systime)
+{
+    time_t local_time;
+    struct tm *local_tm;
+    struct timeval tv;
+    
+    gettimeofday(&tv, NULL);
+    local_time=tv.tv_sec;
+    local_tm=localtime(&local_time);
+    
+    systime->wYear = local_tm->tm_year + 1900;
+    systime->wMonth = local_tm->tm_mon + 1;
+    systime->wDayOfWeek = local_tm->tm_wday;
+    systime->wDay = local_tm->tm_mday;
+    systime->wHour = local_tm->tm_hour;
+    systime->wMinute = local_tm->tm_min;
+    systime->wSecond = local_tm->tm_sec;
+    systime->wMilliseconds = (tv.tv_usec / 1000) % 1000;
+}
+
+int WINAPI expGetSystemTime(SYSTEMTIME* systime)
+{
+    time_t local_time;
+    struct tm *local_tm;
+    struct timeval tv;
+    
+    gettimeofday(&tv, NULL);
+    local_time=tv.tv_sec;
+    local_tm=gmtime(&local_time);
+    
+    systime->wYear = local_tm->tm_year + 1900;
+    systime->wMonth = local_tm->tm_mon + 1;
+    systime->wDayOfWeek = local_tm->tm_wday;
+    systime->wDay = local_tm->tm_mday;
+    systime->wHour = local_tm->tm_hour;
+    systime->wMinute = local_tm->tm_min;
+    systime->wSecond = local_tm->tm_sec;
+    systime->wMilliseconds = (tv.tv_usec / 1000) % 1000;
+    
+}
+
+int WINAPI expGetEnvironmentVariableA(const char* name, char* field, int size)
+{
+    dbgprintf("GetEnvironmentVariableA\n");
+    printf("%s %x %x\n", name, field, size);
+    if(field)field[0]=0;
+    return 0;
+}
+
+
+//HDRVR WINAPI expOpenDriverA(LPCSTR szDriverName, LPCSTR szSectionName, LPARAM lParam2);
+//HDRVR WINAPI expOpenDriverW(LPCWSTR szDriverName, LPCWSTR szSectionName, LPARAM lParam2);
+HDRVR WINAPI expOpenDriver(LPCSTR szDriverName, LPCSTR szSectionName, LPARAM lParam2){
+  printf("winmm32::OpenDriver() called\n");
+  return NULL;
+}
+
+
+struct exports
+{
+    char name[64];
+    int id;
+    void* func;
+};
+struct libs 
+{
+    char name[64];
+    int length;
+    struct exports* exps;
+};
+
+#define FF(X,Y) \
+{#X, Y, (void*)exp##X},
+
+struct exports exp_kernel32[]={
+FF(IsBadWritePtr, 357)
+FF(IsBadReadPtr, 354)
+FF(IsBadStringPtrW, -1)
+FF(DisableThreadLibraryCalls, -1)
+FF(CreateThread, -1)
+FF(CreateEventA, -1)
+FF(SetEvent, -1)
+FF(ResetEvent, -1)
+FF(WaitForSingleObject, -1)
+FF(GetSystemInfo, -1)
+FF(GetVersion, 332)
+FF(HeapCreate, 461)
+FF(HeapAlloc, -1)
+FF(HeapDestroy, -1)
+FF(HeapFree, -1)
+FF(HeapSize, -1)
+FF(GetProcessHeap, -1)
+FF(VirtualAlloc, -1)
+FF(VirtualFree, -1)
+FF(InitializeCriticalSection, -1) 
+FF(EnterCriticalSection, -1)
+FF(LeaveCriticalSection, -1) 
+FF(DeleteCriticalSection, -1)
+FF(TlsAlloc, -1)
+FF(TlsFree, -1)
+FF(TlsGetValue, -1)
+FF(TlsSetValue, -1)
+FF(GetCurrentThreadId, -1)
+FF(LocalAlloc, -1) 
+FF(LocalLock, -1)
+FF(GlobalAlloc, -1)
+FF(GlobalLock, -1)
+FF(MultiByteToWideChar, 427)
+FF(WideCharToMultiByte, -1)
+FF(GetVersionExA, -1)
+FF(CreateSemaphoreA, -1)
+FF(QueryPerformanceCounter, -1)
+FF(QueryPerformanceFrequency, -1)
+FF(LocalHandle, -1)
+FF(LocalUnlock, -1)
+FF(LocalFree, -1)
+FF(GlobalHandle, -1)
+FF(GlobalUnlock, -1)
+FF(GlobalFree, -1)
+FF(LoadResource, -1)
+FF(ReleaseSemaphore, -1) 
+FF(FindResourceA, -1)
+FF(LockResource, -1)
+FF(FreeResource, -1)
+FF(SizeofResource, -1)
+FF(CloseHandle, -1)
+FF(GetCommandLineA, -1)
+FF(GetEnvironmentStringsW, -1)
+FF(FreeEnvironmentStringsW, -1)
+FF(GetEnvironmentStrings, -1)  
+FF(GetStartupInfoA, -1)
+FF(GetStdHandle, -1)
+FF(GetFileType, -1)
+FF(SetHandleCount, -1)
+FF(GetACP, -1)
+FF(GetModuleFileNameA, -1)
+FF(SetUnhandledExceptionFilter, -1)
+FF(LoadLibraryA, -1)
+FF(GetProcAddress, -1)
+FF(FreeLibrary, -1)
+FF(CreateFileMappingA, -1)
+FF(OpenFileMappingA, -1)
+FF(MapViewOfFile, -1)
+FF(UnmapViewOfFile, -1)
+FF(Sleep, -1)
+FF(GetModuleHandleA, -1)
+FF(GetPrivateProfileIntA, -1)
+FF(GetPrivateProfileStringA, -1)
+FF(WritePrivateProfileStringA, -1)
+FF(GetLastError, -1)
+FF(SetLastError, -1)
+FF(InterlockedIncrement, -1)
+FF(InterlockedDecrement, -1)
+FF(GetTimeZoneInformation, -1)
+FF(OutputDebugStringA, -1)
+FF(GetLocalTime, -1)
+FF(GetSystemTime, -1)
+FF(GetEnvironmentVariableA, -1)
+};
+
+struct exports exp_msvcrt[]={
+FF(malloc, -1)
+FF(_initterm, -1)
+FF(free, -1)
+{"??3@YAXPAX@Z", -1, expdelete},
+{"??2@YAPAXI@Z", -1, expnew},
+FF(strrchr, -1)
+FF(strchr, -1)
+};
+struct exports exp_winmm[]={
+FF(GetDriverModuleHandle, -1)
+FF(timeGetTime, -1)
+FF(DefDriverProc, -1)
+FF(OpenDriver, -1)
+};
+struct exports exp_user32[]={
+FF(LoadStringA, -1)
+FF(wsprintfA, -1)
+FF(GetDC, -1)
+FF(GetDesktopWindow, -1)
+FF(ReleaseDC, -1)
+};
+struct exports exp_advapi32[]={
+FF(RegOpenKeyA, -1)
+FF(RegOpenKeyExA, -1)
+FF(RegCreateKeyExA, -1)
+FF(RegQueryValueExA, -1)
+FF(RegSetValueExA, -1)
+FF(RegCloseKey, -1)
+};
+struct exports exp_gdi32[]={
+FF(CreateCompatibleDC, -1)
+FF(GetDeviceCaps, -1)
+FF(DeleteDC, -1)
+FF(GetSystemPaletteEntries, -1)
+};
+struct exports exp_version[]={
+FF(GetFileVersionInfoSizeA, -1)
+};
+#define LL(X) \
+{#X".dll", sizeof(exp_##X)/sizeof(struct exports), exp_##X},
+
+struct libs libraries[]={
+LL(kernel32)
+LL(msvcrt)
+LL(winmm)
+LL(user32)
+LL(advapi32)
+LL(gdi32)
+LL(version)
+};
+
+void* LookupExternal(const char* library, int ordinal)
+{
+    char* answ;
+    int i,j;
+    if(library==0)
+    {
+	printf("ERROR: library=0\n");
+	return (void*)ext_unknown;
+    }
+    printf("External func %s:%d\n", library, ordinal);
+//    printf("%x %x\n", &unk_exp1, &unk_exp2);
+
+    for(i=0; i<sizeof(libraries)/sizeof(struct libs); i++)
+    {
+	if(strcasecmp(library, libraries[i].name))
+	    continue;
+	for(j=0; j<libraries[i].length; j++)
+	{
+	    if(ordinal!=libraries[i].exps[j].id)
+		continue;
+	    printf("Hit: 0x%08X\n", libraries[i].exps[j].func);
+	    return libraries[i].exps[j].func;
+	}
+    }
+    if(pos>150)return 0;
+    answ=(char*)extcode+pos*0x64;
+    memcpy(answ, &unk_exp1, 0x64);
+    *(int*)(answ+9)=pos;
+    *(int*)(answ+47)-=((int)answ-(int)&unk_exp1);
+    sprintf(export_names[pos], "%s:%d", library, ordinal);
+    pos++;    
+    return (void*)answ;
+}    
+
+void* LookupExternalByName(const char* library, const char* name)
+{
+    char* answ;
+    int i,j;
+//   return (void*)ext_unknown;
+    if(library==0)
+    {
+	printf("ERROR: library=0\n");
+	return (void*)ext_unknown;
+    }
+    if(name==0)
+    {
+	printf("ERROR: name=0\n");
+	return (void*)ext_unknown;
+    }
+//    printf("External func %s:%s\n", library, name);
+    for(i=0; i<sizeof(libraries)/sizeof(struct libs); i++)
+    {
+	if(strcasecmp(library, libraries[i].name))
+	    continue;
+	for(j=0; j<libraries[i].length; j++)
+	{
+	    if(strcmp(name, libraries[i].exps[j].name))
+		continue;
+//	    printf("Hit: 0x%08X\n", libraries[i].exps[j].func);
+	    return libraries[i].exps[j].func;
+	}
+    }//    printf("%x %x\n", &unk_exp1, &unk_exp2);
+    //printf("Missing (%d) External func %s:%s\n", pos, library, name);
+    if(pos>150){
+//      printf("Warning! Too many missing externals!\n");
+      return 0;
+    }
+    strcpy(export_names[pos], name);
+    answ=(char*)extcode+pos*0x64;
+    memcpy(answ, &unk_exp1, 0x64);
+    *(int*)(answ+9)=pos;
+    *(int*)(answ+47)-=((int)answ-(int)&unk_exp1);
+    pos++;
+    return (void*)answ;
+//    memcpy(extcode, &unk_exp1, 0x64);
+//    *(int*)(extcode+52)-=((int)extcode-(int)&unk_exp1);
+//    return (void*)extcode;
+//    printf("Unknown func %s:%s\n", library, name);
+//    return (void*)ext_unknown;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/win32.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,1 @@
+int ext_unknown();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/avifmt.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,246 @@
+/****************************************************************************
+ *
+ *  AVIFMT - AVI file format definitions
+ *
+ ****************************************************************************/
+#ifndef AVIFMT
+ 
+#define AVIFMT
+
+#ifndef NOAVIFMT
+ 
+
+#ifndef  __WINE_WINDEF_H
+#include <wine/windef.h>
+#endif
+
+#ifndef __WINE_MMSYSTEM_H
+#ifndef __WINE_MSACM_H
+typedef DWORD FOURCC;
+#endif
+#endif
+
+
+#ifdef _MSC_VER
+#pragma warning(disable:4200)
+#endif
+    
+/* The following is a short description of the AVI file format.  Please
+ * see the accompanying documentation for a full explanation.
+ *
+ * An AVI file is the following RIFF form:
+ *
+ *	RIFF('AVI' 
+ *	      LIST('hdrl'
+ *		    avih(<MainAVIHeader>)
+ *                  LIST ('strl'
+ *                      strh(<Stream header>)
+ *                      strf(<Stream format>)
+ *                      ... additional header data
+ *            LIST('movi'	 
+ *      	  { LIST('rec' 
+ *      		      SubChunk...
+ *      		   )
+ *      	      | SubChunk } ....	    
+ *            )
+ *            [ <AVIIndex> ]
+ *      )
+ *
+ *	The main file header specifies how many streams are present.  For
+ *	each one, there must be a stream header chunk and a stream format
+ *	chunk, enlosed in a 'strl' LIST chunk.  The 'strf' chunk contains
+ *	type-specific format information; for a video stream, this should
+ *	be a BITMAPINFO structure, including palette.  For an audio stream,
+ *	this should be a WAVEFORMAT (or PCMWAVEFORMAT) structure.
+ *
+ *	The actual data is contained in subchunks within the 'movi' LIST 
+ *	chunk.  The first two characters of each data chunk are the
+ *	stream number with which that data is associated.
+ *
+ *	Some defined chunk types:
+ *           Video Streams:
+ *                  ##db:	RGB DIB bits
+ *                  ##dc:	RLE8 compressed DIB bits
+ *                  ##pc:	Palette Change
+ *
+ *           Audio Streams:
+ *                  ##wb:	waveform audio bytes
+ *
+ * The grouping into LIST 'rec' chunks implies only that the contents of
+ *   the chunk should be read into memory at the same time.  This
+ *   grouping is used for files specifically intended to be played from 
+ *   CD-ROM.
+ *
+ * The index chunk at the end of the file should contain one entry for 
+ *   each data chunk in the file.
+ *       
+ * Limitations for the current software:
+ *	Only one video stream and one audio stream are allowed.
+ *	The streams must start at the beginning of the file.
+ *
+ * 
+ * To register codec types please obtain a copy of the Multimedia
+ * Developer Registration Kit from:
+ *
+ *  Microsoft Corporation
+ *  Multimedia Systems Group
+ *  Product Marketing
+ *  One Microsoft Way
+ *  Redmond, WA 98052-6399
+ *
+ */
+
+#ifndef mmioFOURCC
+#define mmioFOURCC( ch0, ch1, ch2, ch3 )				\
+		( (DWORD)(BYTE)(ch0) | ( (DWORD)(BYTE)(ch1) << 8 ) |	\
+		( (DWORD)(BYTE)(ch2) << 16 ) | ( (DWORD)(BYTE)(ch3) << 24 ) )
+#endif
+
+/* Macro to make a TWOCC out of two characters */
+#ifndef aviTWOCC
+#define aviTWOCC(ch0, ch1) ((WORD)(BYTE)(ch0) | ((WORD)(BYTE)(ch1) << 8))
+#endif
+
+typedef WORD TWOCC;
+
+/* form types, list types, and chunk types */
+#define formtypeAVI             mmioFOURCC('A', 'V', 'I', ' ')
+#define listtypeAVIHEADER       mmioFOURCC('h', 'd', 'r', 'l')
+#define ckidAVIMAINHDR          mmioFOURCC('a', 'v', 'i', 'h')
+#define listtypeSTREAMHEADER    mmioFOURCC('s', 't', 'r', 'l')
+#define ckidSTREAMHEADER        mmioFOURCC('s', 't', 'r', 'h')
+#define ckidSTREAMFORMAT        mmioFOURCC('s', 't', 'r', 'f')
+#define ckidSTREAMHANDLERDATA   mmioFOURCC('s', 't', 'r', 'd')
+#define ckidSTREAMNAME		mmioFOURCC('s', 't', 'r', 'n')
+
+#define listtypeAVIMOVIE        mmioFOURCC('m', 'o', 'v', 'i')
+#define listtypeAVIRECORD       mmioFOURCC('r', 'e', 'c', ' ')
+
+#define ckidAVINEWINDEX         mmioFOURCC('i', 'd', 'x', '1')
+
+/*
+** Stream types for the <fccType> field of the stream header.
+*/
+#define streamtypeVIDEO         mmioFOURCC('v', 'i', 'd', 's')
+#define streamtypeAUDIO         mmioFOURCC('a', 'u', 'd', 's')
+#define streamtypeMIDI		mmioFOURCC('m', 'i', 'd', 's')
+#define streamtypeTEXT          mmioFOURCC('t', 'x', 't', 's')
+
+/* Basic chunk types */
+#define cktypeDIBbits           aviTWOCC('d', 'b')
+#define cktypeDIBcompressed     aviTWOCC('d', 'c')
+#define cktypePALchange         aviTWOCC('p', 'c')
+#define cktypeWAVEbytes         aviTWOCC('w', 'b')
+
+/* Chunk id to use for extra chunks for padding. */
+#define ckidAVIPADDING          mmioFOURCC('J', 'U', 'N', 'K')
+
+/*
+** Useful macros
+**
+** Warning: These are nasty macro, and MS C 6.0 compiles some of them
+** incorrectly if optimizations are on.  Ack.
+*/
+
+/* Macro to get stream number out of a FOURCC ckid */
+#define FromHex(n)	(((n) >= 'A') ? ((n) + 10 - 'A') : ((n) - '0'))
+#define StreamFromFOURCC(fcc) ((WORD) ((FromHex(LOBYTE(LOWORD(fcc))) << 4) + \
+                                             (FromHex(HIBYTE(LOWORD(fcc))))))
+
+/* Macro to get TWOCC chunk type out of a FOURCC ckid */
+#define TWOCCFromFOURCC(fcc)    HIWORD(fcc)
+
+/* Macro to make a ckid for a chunk out of a TWOCC and a stream number
+** from 0-255.
+*/
+#define ToHex(n)	((BYTE) (((n) > 9) ? ((n) - 10 + 'A') : ((n) + '0')))
+#define MAKEAVICKID(tcc, stream) \
+        MAKELONG((ToHex((stream) & 0x0f) << 8) | \
+			    (ToHex(((stream) & 0xf0) >> 4)), tcc)
+
+/*
+** Main AVI File Header 
+*/	     
+		     
+/* flags for use in <dwFlags> in AVIFileHdr */
+#define AVIF_HASINDEX		0x00000010	// Index at end of file?
+#define AVIF_MUSTUSEINDEX	0x00000020
+#define AVIF_ISINTERLEAVED	0x00000100
+#define AVIF_TRUSTCKTYPE	0x00000800	// Use CKType to find key frames?
+#define AVIF_WASCAPTUREFILE	0x00010000
+#define AVIF_COPYRIGHTED	0x00020000
+
+/* The AVI File Header LIST chunk should be padded to this size */
+#define AVI_HEADERSIZE  2048                    // size of AVI header list
+
+typedef struct
+{
+    DWORD		dwMicroSecPerFrame;	// frame display rate (or 0L)
+    DWORD		dwMaxBytesPerSec;	// max. transfer rate
+    DWORD		dwPaddingGranularity;	// pad to multiples of this
+                                                // size; normally 2K.
+    DWORD		dwFlags;		// the ever-present flags
+    DWORD		dwTotalFrames;		// # frames in file
+    DWORD		dwInitialFrames;
+    DWORD		dwStreams;
+    DWORD		dwSuggestedBufferSize;
+    
+    DWORD		dwWidth;
+    DWORD		dwHeight;
+    
+    DWORD		dwReserved[4];
+} MainAVIHeader;
+
+/*
+** Stream header
+*/
+
+#define AVISF_DISABLED			0x00000001
+
+#define AVISF_VIDEO_PALCHANGES		0x00010000
+
+  
+typedef struct {
+    FOURCC		fccType;
+    FOURCC		fccHandler;
+    DWORD		dwFlags;	/* Contains AVITF_* flags */
+    WORD		wPriority;
+    WORD		wLanguage;
+    DWORD		dwInitialFrames;
+    DWORD		dwScale;	
+    DWORD		dwRate;	/* dwRate / dwScale == samples/second */
+    DWORD		dwStart;
+    DWORD		dwLength; /* In units above... */
+    DWORD		dwSuggestedBufferSize;
+    DWORD		dwQuality;
+    DWORD		dwSampleSize;
+    RECT		rcFrame;
+} AVIStreamHeader;
+
+/* Flags for index */
+#define AVIIF_LIST          0x00000001L // chunk is a 'LIST'
+#define AVIIF_KEYFRAME      0x00000010L // this frame is a key frame.
+
+#define AVIIF_NOTIME	    0x00000100L // this frame doesn't take any time
+#define AVIIF_COMPUSE       0x0FFF0000L // these bits are for compressor use
+
+#define FOURCC_RIFF     mmioFOURCC('R', 'I', 'F', 'F')
+#define FOURCC_LIST     mmioFOURCC('L', 'I', 'S', 'T')
+
+typedef struct
+{
+    DWORD		ckid;
+    DWORD		dwFlags;
+    DWORD		dwChunkOffset;		// Position of chunk
+    DWORD		dwChunkLength;		// Length of chunk
+} AVIINDEXENTRY;
+
+#define AVISTREAMREAD_CONVENIENT	(-1L)
+
+/*
+** Palette change chunk
+**
+** Used in video streams.
+*/
+#endif /* NOAVIFMT */
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/basetsd.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,145 @@
+/*
+ * Compilers that uses ILP32, LP64 or P64 type models
+ * for both Win32 and Win64 are supported by this file.
+ */
+
+#ifndef __WINE_BASETSD_H
+#define __WINE_BASETSD_H
+
+#ifdef __WINE__
+#include "config.h"
+#endif /* defined(__WINE__) */
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* defined(__cplusplus) */
+
+/*
+ * Win32 was easy to implement under Unix since most (all?) 32-bit
+ * Unices uses the same type model (ILP32) as Win32, where int, long
+ * and pointer are 32-bit.
+ *
+ * Win64, however, will cause some problems when implemented under Unix.
+ * Linux/{Alpha, Sparc64} and most (all?) other 64-bit Unices uses
+ * the LP64 type model where int is 32-bit and long and pointer are
+ * 64-bit. Win64 on the other hand uses the P64 (sometimes called LLP64)
+ * type model where int and long are 32 bit and pointer is 64-bit.
+ */
+
+/* Type model indepent typedefs */
+
+typedef char          __int8;
+typedef unsigned char __uint8;
+
+typedef short          __int16;
+typedef unsigned short __uint16;
+
+typedef int          __int32;
+typedef unsigned int __uint32;
+
+typedef long long          __int64;
+typedef unsigned long long __uint64;
+
+#if defined(_WIN64)
+
+typedef __uint32 __ptr32;
+typedef void    *__ptr64;
+
+#else /* FIXME: defined(_WIN32) */
+
+typedef void    *__ptr32;
+typedef __uint64 __ptr64;
+
+#endif
+
+/* Always signed and 32 bit wide */
+
+typedef __int32 LONG32;
+//typedef __int32 INT32;
+
+typedef LONG32 *PLONG32;
+//typedef INT32  *PINT32;
+
+/* Always unsigned and 32 bit wide */
+
+typedef __uint32 ULONG32;
+typedef __uint32 DWORD32;
+typedef __uint32 UINT32;
+
+typedef ULONG32 *PULONG32;
+typedef DWORD32 *PDWORD32;
+typedef UINT32  *PUINT32;
+
+/* Always signed and 64 bit wide */
+
+typedef __int64 LONG64;
+typedef __int64 INT64;
+
+typedef LONG64 *PLONG64;
+typedef INT64  *PINT64;
+
+/* Always unsigned and 64 bit wide */
+
+typedef __uint64 ULONG64;
+typedef __uint64 DWORD64;
+typedef __uint64 UINT64;
+
+typedef ULONG64 *PULONG64;
+typedef DWORD64 *PDWORD64;
+typedef UINT64  *PUINT64;
+
+/* Win32 or Win64 dependent typedef/defines. */
+
+#ifdef _WIN64
+
+typedef __int64 INT_PTR, *PINT_PTR;
+typedef __uint64 UINT_PTR, *PUINT_PTR;
+
+#define MAXINT_PTR 0x7fffffffffffffff
+#define MININT_PTR 0x8000000000000000
+#define MAXUINT_PTR 0xffffffffffffffff
+
+typedef __int32 HALF_PTR, *PHALF_PTR;
+typedef __int32 UHALF_PTR, *PUHALF_PTR;
+
+#define MAXHALF_PTR 0x7fffffff
+#define MINHALF_PTR 0x80000000
+#define MAXUHALF_PTR 0xffffffff
+
+typedef __int64 LONG_PTR, *PLONG_PTR;
+typedef __uint64 ULONG_PTR, *PULONG_PTR;
+typedef __uint64 DWORD_PTR, *PDWORD_PTR;
+
+#else /* FIXME: defined(_WIN32) */
+
+typedef __int32 INT_PTR, *PINT_PTR;
+typedef __uint32 UINT_PTR, *PUINT_PTR;
+
+#define MAXINT_PTR 0x7fffffff
+#define MININT_PTR 0x80000000
+#define MAXUINT_PTR 0xffffffff
+
+typedef __int16 HALF_PTR, *PHALF_PTR;
+typedef __uint16 UHALF_PTR, *PUHALF_PTR;
+
+#define MAXUHALF_PTR 0xffff
+#define MAXHALF_PTR 0x7fff
+#define MINHALF_PTR 0x8000
+
+typedef __int32 LONG_PTR, *PLONG_PTR;
+typedef __uint32 ULONG_PTR, *PULONG_PTR;
+typedef __uint32 DWORD_PTR, *PDWORD_PTR;
+
+#endif /* defined(_WIN64) || defined(_WIN32) */
+
+typedef INT_PTR SSIZE_T, *PSSIZE_T;
+typedef UINT_PTR SIZE_T, *PSIZE_T;
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif /* defined(__cplusplus) */
+
+#endif /* !defined(__WINE_BASETSD_H) */
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/config.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,442 @@
+/* include/config.h.  Generated automatically by configure.  */
+/* include/config.h.in.  Generated automatically from configure.in by autoheader.  */
+
+/* Define if using alloca.c.  */
+/* #undef C_ALLOCA */
+
+/* Define to empty if the keyword does not work.  */
+/* #undef const */
+
+/* Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems.
+   This function is required for alloca.c support on those systems.  */
+/* #undef CRAY_STACKSEG_END */
+
+/* Define if you have alloca, as a function or macro.  */
+#define HAVE_ALLOCA 1
+
+/* Define if you have <alloca.h> and it should be used (not on Ultrix).  */
+#define HAVE_ALLOCA_H 1
+
+/* Define as __inline if that's what the C compiler calls it.  */
+/* #undef inline */
+
+/* Define to `unsigned' if <sys/types.h> doesn't define.  */
+/* #undef size_t */
+
+/* If using the C implementation of alloca, define if you know the
+   direction of stack growth for your system; otherwise it will be
+   automatically deduced at run-time.
+ STACK_DIRECTION > 0 => grows toward higher addresses
+ STACK_DIRECTION < 0 => grows toward lower addresses
+ STACK_DIRECTION = 0 => direction of growth unknown
+ */
+/* #undef STACK_DIRECTION */
+
+/* Define if the `S_IS*' macros in <sys/stat.h> do not work properly.  */
+/* #undef STAT_MACROS_BROKEN */
+
+/* Define if you have the ANSI C header files.  */
+#define STDC_HEADERS 1
+
+/* Define if your processor stores words with the most significant
+   byte first (like Motorola and SPARC, unlike Intel and VAX).  */
+/* #undef WORDS_BIGENDIAN */
+
+/* Define if the X Window System is missing or not being used.  */
+/* #undef X_DISPLAY_MISSING */
+
+/* Define if symbols declared in assembly code need an underscore prefix */
+/* #undef NEED_UNDERSCORE_PREFIX */
+
+/* Define to use .string instead of .ascii */
+#define HAVE_ASM_STRING 1
+
+/* Define if struct msghdr contains msg_accrights */
+/* #undef HAVE_MSGHDR_ACCRIGHTS */
+
+/* Define if struct sockaddr_un contains sun_len */
+/* #undef HAVE_SOCKADDR_SUN_LEN */
+
+/* Define if you have the Xxf86dga library (-lXxf86dga).  */
+#define HAVE_LIBXXF86DGA 1
+
+/* Define if you have the Xxf86dga library version 2.0 (-lXxf86dga).  */
+/* #undef HAVE_LIBXXF86DGA2 */
+
+/* Define if you have the X Shm extension */
+#define HAVE_LIBXXSHM 1
+
+/* Define if you have the Xxf86vm library */
+#define HAVE_LIBXXF86VM 1
+
+/* Define if you have the Xpm library */
+#define HAVE_LIBXXPM 1
+
+/* Define if you have the Open Sound system.  */
+#define HAVE_OSS 1
+
+/* Define if you have the Open Sound system (MIDI interface).  */
+#define HAVE_OSS_MIDI 1
+
+/* Define if X libraries are not reentrant (compiled without -D_REENTRANT).  */
+/* #undef NO_REENTRANT_X11 */
+
+/* Define if libc is not reentrant  */
+/* #undef NO_REENTRANT_LIBC */
+
+/* Define if libc uses __errno_location for reentrant errno */
+#define HAVE__ERRNO_LOCATION 1
+
+/* Define if libc uses __error for reentrant errno */
+/* #undef HAVE__ERROR */
+
+/* Define if libc uses ___errno for reentrant errno */
+/* #undef HAVE___ERRNO */
+
+/* Define if libc uses __thr_errno for reentrant errno */
+/* #undef HAVE__THR_ERRNO */
+
+/* Define if all debug messages are to be compiled out */
+/* #undef NO_DEBUG_MSGS */
+
+/* Define if TRACE messages are to be compiled out */
+/* #undef NO_TRACE_MSGS */
+
+/* Define if the struct statfs has the member bavail */
+#define STATFS_HAS_BAVAIL 1
+
+/* Define if the struct statfs has the member bfree */
+#define STATFS_HAS_BFREE 1
+
+/* Define if the struct statfs is defined by <sys/vfs.h> */
+#define STATFS_DEFINED_BY_SYS_VFS 1
+
+/* Define if the struct statfs is defined by <sys/statfs.h> */
+#define STATFS_DEFINED_BY_SYS_STATFS 1
+
+/* Define if the struct statfs is defined by <sys/mount.h> */
+/* #undef STATFS_DEFINED_BY_SYS_MOUNT */
+
+/* Define if ncurses have the new resizeterm function */
+#define HAVE_RESIZETERM 1
+
+/* Define if ncurses have the new getbkgd function */
+#define HAVE_GETBKGD 1
+
+/* Define if IPX should use netipx/ipx.h from libc */
+#define HAVE_IPX_GNU 1
+
+/* Define if IPX includes are taken from Linux kernel */
+/* #undef HAVE_IPX_LINUX */
+
+/* Define if Mesa is present on the system or not */
+/* #undef HAVE_LIBMESAGL */
+
+/* Define if the system has dynamic link library support with the dl* API */
+#define HAVE_DL_API 1
+
+/* Define if <linux/joystick.h> defines the Linux 2.2 joystick API */
+#define HAVE_LINUX_22_JOYSTICK_API 1
+
+/* Define if the OpenGL implementation supports the GL_EXT_color_table extension */
+/* #undef HAVE_GL_COLOR_TABLE */
+
+/* Define if the OpenGL implementation supports the GL_EXT_paletted_texture extension */
+/* #undef HAVE_GL_PALETTED_TEXTURE */
+
+/* The number of bytes in a long long.  */
+#define SIZEOF_LONG_LONG 8
+
+/* Define if you have the __libc_fork function.  */
+/* #undef HAVE___LIBC_FORK */
+
+/* Define if you have the _lwp_create function.  */
+/* #undef HAVE__LWP_CREATE */
+
+/* Define if you have the clone function.  */
+#define HAVE_CLONE 1
+
+/* Define if you have the connect function.  */
+#define HAVE_CONNECT 1
+
+/* Define if you have the dlopen function.  */
+/* #undef HAVE_DLOPEN */
+
+/* Define if you have the gethostbyname function.  */
+#define HAVE_GETHOSTBYNAME 1
+
+/* Define if you have the getnetbyaddr function.  */
+#define HAVE_GETNETBYADDR 1
+
+/* Define if you have the getnetbyname function.  */
+#define HAVE_GETNETBYNAME 1
+
+/* Define if you have the getpagesize function.  */
+#define HAVE_GETPAGESIZE 1
+
+/* Define if you have the getprotobyname function.  */
+#define HAVE_GETPROTOBYNAME 1
+
+/* Define if you have the getprotobynumber function.  */
+#define HAVE_GETPROTOBYNUMBER 1
+
+/* Define if you have the getservbyport function.  */
+#define HAVE_GETSERVBYPORT 1
+
+/* Define if you have the getsockopt function.  */
+#define HAVE_GETSOCKOPT 1
+
+/* Define if you have the inet_network function.  */
+#define HAVE_INET_NETWORK 1
+
+/* Define if you have the memmove function.  */
+#define HAVE_MEMMOVE 1
+
+/* Define if you have the openpty function.  */
+#define HAVE_OPENPTY 1
+
+/* Define if you have the rfork function.  */
+/* #undef HAVE_RFORK */
+
+/* Define if you have the select function.  */
+#define HAVE_SELECT 1
+
+/* Define if you have the sendmsg function.  */
+#define HAVE_SENDMSG 1
+
+/* Define if you have the settimeofday function.  */
+#define HAVE_SETTIMEOFDAY 1
+
+/* Define if you have the sigaltstack function.  */
+#define HAVE_SIGALTSTACK 1
+
+/* Define if you have the statfs function.  */
+#define HAVE_STATFS 1
+
+/* Define if you have the strcasecmp function.  */
+#define HAVE_STRCASECMP 1
+
+/* Define if you have the strerror function.  */
+#define HAVE_STRERROR 1
+
+/* Define if you have the strncasecmp function.  */
+#define HAVE_STRNCASECMP 1
+
+/* Define if you have the tcgetattr function.  */
+#define HAVE_TCGETATTR 1
+
+/* Define if you have the timegm function.  */
+#define HAVE_TIMEGM 1
+
+/* Define if you have the usleep function.  */
+#define HAVE_USLEEP 1
+
+/* Define if you have the vfscanf function.  */
+#define HAVE_VFSCANF 1
+
+/* Define if you have the wait4 function.  */
+#define HAVE_WAIT4 1
+
+/* Define if you have the waitpid function.  */
+#define HAVE_WAITPID 1
+
+/* Define if you have the <GL/gl.h> header file.  */
+/* #undef HAVE_GL_GL_H */
+
+/* Define if you have the <GL/glx.h> header file.  */
+/* #undef HAVE_GL_GLX_H */
+
+/* Define if you have the <X11/Xlib.h> header file.  */
+#define HAVE_X11_XLIB_H 1
+
+/* Define if you have the <X11/extensions/XShm.h> header file.  */
+#define HAVE_X11_EXTENSIONS_XSHM_H 1
+
+/* Define if you have the <X11/extensions/xf86dga.h> header file.  */
+#define HAVE_X11_EXTENSIONS_XF86DGA_H 1
+
+/* Define if you have the <X11/extensions/xf86vmode.h> header file.  */
+#define HAVE_X11_EXTENSIONS_XF86VMODE_H 1
+
+/* Define if you have the <X11/xpm.h> header file.  */
+#define HAVE_X11_XPM_H 1
+
+/* Define if you have the <a.out.h> header file.  */
+#define HAVE_A_OUT_H 1
+
+/* Define if you have the <a_out.h> header file.  */
+#define HAVE_A_OUT_H 1
+
+/* Define if you have the <arpa/inet.h> header file.  */
+#define HAVE_ARPA_INET_H 1
+
+/* Define if you have the <arpa/nameser.h> header file.  */
+#define HAVE_ARPA_NAMESER_H 1
+
+/* Define if you have the <curses.h> header file.  */
+/* #undef HAVE_CURSES_H */
+
+/* Define if you have the <dlfcn.h> header file.  */
+#define HAVE_DLFCN_H 1
+
+/* Define if you have the <elf.h> header file.  */
+#define HAVE_ELF_H 1
+
+/* Define if you have the <float.h> header file.  */
+#define HAVE_FLOAT_H 1
+
+/* Define if you have the <libio.h> header file.  */
+#define HAVE_LIBIO_H 1
+
+/* Define if you have the <link.h> header file.  */
+#define HAVE_LINK_H 1
+
+/* Define if you have the <linux/cdrom.h> header file.  */
+#define HAVE_LINUX_CDROM_H 1
+
+/* Define if you have the <linux/joystick.h> header file.  */
+#define HAVE_LINUX_JOYSTICK_H 1
+
+/* Define if you have the <linux/ucdrom.h> header file.  */
+/* #undef HAVE_LINUX_UCDROM_H */
+
+/* Define if you have the <machine/soundcard.h> header file.  */
+/* #undef HAVE_MACHINE_SOUNDCARD_H */
+
+/* Define if you have the <ncurses.h> header file.  */
+#define HAVE_NCURSES_H 1
+
+/* Define if you have the <net/if.h> header file.  */
+#define HAVE_NET_IF_H 1
+
+/* Define if you have the <netinet/in.h> header file.  */
+#define HAVE_NETINET_IN_H 1
+
+/* Define if you have the <netinet/tcp.h> header file.  */
+#define HAVE_NETINET_TCP_H 1
+
+/* Define if you have the <pty.h> header file.  */
+#define HAVE_PTY_H 1
+
+/* Define if you have the <resolv.h> header file.  */
+#define HAVE_RESOLV_H 1
+
+/* Define if you have the <sched.h> header file.  */
+#define HAVE_SCHED_H 1
+
+/* Define if you have the <socket.h> header file.  */
+/* #undef HAVE_SOCKET_H */
+
+/* Define if you have the <soundcard.h> header file.  */
+/* #undef HAVE_SOUNDCARD_H */
+
+/* Define if you have the <strings.h> header file.  */
+#define HAVE_STRINGS_H 1
+
+/* Define if you have the <sys/cdio.h> header file.  */
+/* #undef HAVE_SYS_CDIO_H */
+
+/* Define if you have the <sys/errno.h> header file.  */
+#define HAVE_SYS_ERRNO_H 1
+
+/* Define if you have the <sys/file.h> header file.  */
+#define HAVE_SYS_FILE_H 1
+
+/* Define if you have the <sys/filio.h> header file.  */
+/* #undef HAVE_SYS_FILIO_H */
+
+/* Define if you have the <sys/ipc.h> header file.  */
+#define HAVE_SYS_IPC_H 1
+
+/* Define if you have the <sys/lwp.h> header file.  */
+/* #undef HAVE_SYS_LWP_H */
+
+/* Define if you have the <sys/mman.h> header file.  */
+#define HAVE_SYS_MMAN_H 1
+
+/* Define if you have the <sys/modem.h> header file.  */
+/* #undef HAVE_SYS_MODEM_H */
+
+/* Define if you have the <sys/mount.h> header file.  */
+#define HAVE_SYS_MOUNT_H 1
+
+/* Define if you have the <sys/msg.h> header file.  */
+#define HAVE_SYS_MSG_H 1
+
+/* Define if you have the <sys/param.h> header file.  */
+#define HAVE_SYS_PARAM_H 1
+
+/* Define if you have the <sys/reg.h> header file.  */
+#define HAVE_SYS_REG_H 1
+
+/* Define if you have the <sys/shm.h> header file.  */
+#define HAVE_SYS_SHM_H 1
+
+/* Define if you have the <sys/signal.h> header file.  */
+#define HAVE_SYS_SIGNAL_H 1
+
+/* Define if you have the <sys/socket.h> header file.  */
+#define HAVE_SYS_SOCKET_H 1
+
+/* Define if you have the <sys/sockio.h> header file.  */
+/* #undef HAVE_SYS_SOCKIO_H */
+
+/* Define if you have the <sys/soundcard.h> header file.  */
+#define HAVE_SYS_SOUNDCARD_H 1
+
+/* Define if you have the <sys/statfs.h> header file.  */
+#define HAVE_SYS_STATFS_H 1
+
+/* Define if you have the <sys/strtio.h> header file.  */
+/* #undef HAVE_SYS_STRTIO_H */
+
+/* Define if you have the <sys/syscall.h> header file.  */
+#define HAVE_SYS_SYSCALL_H 1
+
+/* Define if you have the <sys/v86.h> header file.  */
+/* #undef HAVE_SYS_V86_H */
+
+/* Define if you have the <sys/v86intr.h> header file.  */
+/* #undef HAVE_SYS_V86INTR_H */
+
+/* Define if you have the <sys/vfs.h> header file.  */
+#define HAVE_SYS_VFS_H 1
+
+/* Define if you have the <sys/vm86.h> header file.  */
+#define HAVE_SYS_VM86_H 1
+
+/* Define if you have the <sys/wait.h> header file.  */
+#define HAVE_SYS_WAIT_H 1
+
+/* Define if you have the <syscall.h> header file.  */
+#define HAVE_SYSCALL_H 1
+
+/* Define if you have the <ucontext.h> header file.  */
+#define HAVE_UCONTEXT_H 1
+
+/* Define if you have the <wctype.h> header file.  */
+#define HAVE_WCTYPE_H 1
+
+/* Define if you have the curses library (-lcurses).  */
+/* #undef HAVE_LIBCURSES */
+
+/* Define if you have the i386 library (-li386).  */
+/* #undef HAVE_LIBI386 */
+
+/* Define if you have the m library (-lm).  */
+#define HAVE_LIBM 1
+
+/* Define if you have the mmap library (-lmmap).  */
+/* #undef HAVE_LIBMMAP */
+
+/* Define if you have the ncurses library (-lncurses).  */
+#define HAVE_LIBNCURSES 1
+
+/* Define if you have the ossaudio library (-lossaudio).  */
+/* #undef HAVE_LIBOSSAUDIO */
+
+/* Define if you have the w library (-lw).  */
+/* #undef HAVE_LIBW */
+
+/* Define if you have the xpg4 library (-lxpg4).  */
+/* #undef HAVE_LIBXPG4 */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/debugtools.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,93 @@
+
+#ifndef __WINE_DEBUGTOOLS_H
+#define __WINE_DEBUGTOOLS_H
+
+#ifdef __WINE__  /* Debugging interface is internal to Wine */
+
+#include <stdarg.h>
+#include "config.h"
+#include "windef.h"
+
+struct _GUID;
+
+/* Internal definitions (do not use these directly) */
+
+enum __DEBUG_CLASS { __DBCL_FIXME, __DBCL_ERR, __DBCL_WARN, __DBCL_TRACE, __DBCL_COUNT };
+
+#ifndef NO_TRACE_MSGS
+# define __GET_DEBUGGING_trace(dbch) ((dbch)[0] & (1 << __DBCL_TRACE))
+#else
+# define __GET_DEBUGGING_trace(dbch) 0
+#endif
+
+#ifndef NO_DEBUG_MSGS
+# define __GET_DEBUGGING_warn(dbch)  ((dbch)[0] & (1 << __DBCL_WARN))
+# define __GET_DEBUGGING_fixme(dbch) ((dbch)[0] & (1 << __DBCL_FIXME))
+#else
+# define __GET_DEBUGGING_warn(dbch)  0
+# define __GET_DEBUGGING_fixme(dbch) 0
+#endif
+
+/* define error macro regardless of what is configured */
+#define __GET_DEBUGGING_err(dbch)  ((dbch)[0] & (1 << __DBCL_ERR))
+
+#define __GET_DEBUGGING(dbcl,dbch)  __GET_DEBUGGING_##dbcl(dbch)
+#define __SET_DEBUGGING(dbcl,dbch,on) \
+    ((on) ? ((dbch)[0] |= 1 << (dbcl)) : ((dbch)[0] &= ~(1 << (dbcl))))
+
+#ifndef __GNUC__
+#define __FUNCTION__ ""
+#endif
+
+#define __DPRINTF(dbcl,dbch) \
+  (!__GET_DEBUGGING(dbcl,(dbch)) || (dbg_header_##dbcl((dbch),__FUNCTION__),0)) ? \
+     (void)0 : (void)dbg_printf
+
+/* Exported definitions and macros */
+
+/* These function return a printable version of a string, including
+   quotes.  The string will be valid for some time, but not indefinitely
+   as strings are re-used.  */
+extern LPCSTR debugstr_an (LPCSTR s, int n);
+extern LPCSTR debugstr_wn (LPCWSTR s, int n);
+extern LPCSTR debugres_a (LPCSTR res);
+extern LPCSTR debugres_w (LPCWSTR res);
+extern LPCSTR debugstr_guid( const struct _GUID *id );
+extern LPCSTR debugstr_hex_dump (const void *ptr, int len);
+extern int dbg_header_err( const char *dbg_channel, const char *func );
+extern int dbg_header_warn( const char *dbg_channel, const char *func );
+extern int dbg_header_fixme( const char *dbg_channel, const char *func );
+extern int dbg_header_trace( const char *dbg_channel, const char *func );
+extern int dbg_vprintf( const char *format, va_list args );
+
+static inline LPCSTR debugstr_a( LPCSTR s )  { return debugstr_an( s, 80 ); }
+static inline LPCSTR debugstr_w( LPCWSTR s ) { return debugstr_wn( s, 80 ); }
+
+#ifdef __GNUC__
+extern int dbg_printf(const char *format, ...) __attribute__((format (printf,1,2)));
+#else
+extern int dbg_printf(const char *format, ...);
+#endif
+
+#define TRACE_(X) TRACE
+#define WARN_(X) TRACE
+#define WARN TRACE
+#define ERR_(X) printf
+#define ERR printf
+#define FIXME_(X) TRACE
+#define FIXME TRACE
+
+#define TRACE_ON(X) 1
+#define ERR_ON(X) 1
+
+#define DECLARE_DEBUG_CHANNEL(ch) \
+    extern char dbch_##ch[];
+#define DEFAULT_DEBUG_CHANNEL(ch) \
+    extern char dbch_##ch[]; static char * const __dbch_default = dbch_##ch;
+
+#define DPRINTF dbg_printf
+#define MESSAGE dbg_printf
+
+#endif  /* __WINE__ */
+
+#endif  /* __WINE_DEBUGTOOLS_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/driver.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,112 @@
+/*
+ * Drivers definitions
+ */
+
+#ifndef __WINE_DRIVER_H
+#define __WINE_DRIVER_H
+
+#include "windef.h"
+
+#define MMSYSERR_BASE          0
+
+#define MMSYSERR_NOERROR      	0                    /* no error */
+#define MMSYSERR_ERROR        	(MMSYSERR_BASE + 1)  /* unspecified error */
+#define MMSYSERR_BADDEVICEID  	(MMSYSERR_BASE + 2)  /* device ID out of range */
+#define MMSYSERR_NOTENABLED   	(MMSYSERR_BASE + 3)  /* driver failed enable */
+#define MMSYSERR_ALLOCATED    	(MMSYSERR_BASE + 4)  /* device already allocated */
+#define MMSYSERR_INVALHANDLE  	(MMSYSERR_BASE + 5)  /* device handle is invalid */
+#define MMSYSERR_NODRIVER     	(MMSYSERR_BASE + 6)  /* no device driver present */
+#define MMSYSERR_NOMEM        	(MMSYSERR_BASE + 7)  /* memory allocation error */
+#define MMSYSERR_NOTSUPPORTED 	(MMSYSERR_BASE + 8)  /* function isn't supported */
+#define MMSYSERR_BADERRNUM    	(MMSYSERR_BASE + 9)  /* error value out of range */
+#define MMSYSERR_INVALFLAG    	(MMSYSERR_BASE + 10) /* invalid flag passed */
+#define MMSYSERR_INVALPARAM   	(MMSYSERR_BASE + 11) /* invalid parameter passed */
+#define MMSYSERR_LASTERROR    	(MMSYSERR_BASE + 11) /* last error in range */
+
+#define DRV_LOAD                0x0001
+#define DRV_ENABLE              0x0002
+#define DRV_OPEN                0x0003
+#define DRV_CLOSE               0x0004
+#define DRV_DISABLE             0x0005
+#define DRV_FREE                0x0006
+#define DRV_CONFIGURE           0x0007
+#define DRV_QUERYCONFIGURE      0x0008
+#define DRV_INSTALL             0x0009
+#define DRV_REMOVE              0x000A
+#define DRV_EXITSESSION         0x000B
+#define DRV_EXITAPPLICATION     0x000C
+#define DRV_POWER               0x000F
+
+#define DRV_RESERVED            0x0800
+#define DRV_USER                0x4000
+
+#define DRVCNF_CANCEL           0x0000
+#define DRVCNF_OK               0x0001
+#define DRVCNF_RESTART 		0x0002
+
+#define DRVEA_NORMALEXIT  	0x0001
+#define DRVEA_ABNORMALEXIT 	0x0002
+
+#define DRV_SUCCESS		0x0001
+#define DRV_FAILURE		0x0000
+
+#define GND_FIRSTINSTANCEONLY 	0x00000001
+
+#define GND_FORWARD  		0x00000000
+#define GND_REVERSE    		0x00000002
+
+typedef struct {
+    DWORD   			dwDCISize;
+    LPCSTR  			lpszDCISectionName;
+    LPCSTR  			lpszDCIAliasName;
+} DRVCONFIGINFO16, *LPDRVCONFIGINFO16;
+
+typedef struct {
+    DWORD   			dwDCISize;
+    LPCWSTR  			lpszDCISectionName;
+    LPCWSTR  			lpszDCIAliasName;
+} DRVCONFIGINFO, *LPDRVCONFIGINFO;
+
+
+/* GetDriverInfo16 references this structure, so this a struct defined
+ * in the Win16 API.
+ * GetDriverInfo has been deprecated in Win32.
+ */
+typedef struct
+{
+    UINT16       		length;
+    HDRVR16      		hDriver;
+    HINSTANCE16  		hModule;
+    CHAR         		szAliasName[128];
+} DRIVERINFOSTRUCT16, *LPDRIVERINFOSTRUCT16;
+
+LRESULT WINAPI DefDriverProc16(DWORD dwDevID, HDRVR16 hDriv, UINT16 wMsg, 
+                               LPARAM dwParam1, LPARAM dwParam2);
+LRESULT WINAPI DefDriverProc(DWORD dwDriverIdentifier, HDRVR hdrvr,
+                               UINT Msg, LPARAM lParam1, LPARAM lParam2);
+HDRVR16 WINAPI OpenDriver16(LPCSTR szDriverName, LPCSTR szSectionName,
+                            LPARAM lParam2);
+HDRVR WINAPI OpenDriverA(LPCSTR szDriverName, LPCSTR szSectionName,
+                             LPARAM lParam2);
+HDRVR WINAPI OpenDriverW(LPCWSTR szDriverName, LPCWSTR szSectionName,
+                             LPARAM lParam2);
+#define OpenDriver WINELIB_NAME_AW(OpenDriver)
+LRESULT WINAPI CloseDriver16(HDRVR16 hDriver, LPARAM lParam1, LPARAM lParam2);
+LRESULT WINAPI CloseDriver(HDRVR hDriver, LPARAM lParam1, LPARAM lParam2);
+LRESULT WINAPI SendDriverMessage16( HDRVR16 hDriver, UINT16 message,
+                                    LPARAM lParam1, LPARAM lParam2 );
+LRESULT WINAPI SendDriverMessage( HDRVR hDriver, UINT message,
+                                    LPARAM lParam1, LPARAM lParam2 );
+HMODULE16 WINAPI GetDriverModuleHandle16(HDRVR16 hDriver);
+HMODULE WINAPI GetDriverModuleHandle(HDRVR hDriver);
+
+DWORD WINAPI GetDriverFlags( HDRVR hDriver );
+#ifdef __WINE__
+/* this call (GetDriverFlags) is not documented, nor the flags returned.
+ * here are Wine only definitions
+ */
+#define WINE_GDF_EXIST	0x80000000
+#define WINE_GDF_16BIT	0x10000000
+#endif
+
+#endif  /* __WINE_DRIVER_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/elfdll.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,14 @@
+#ifndef __WINE_ELFDLL_H
+#define __WINE_ELFDLL_H
+
+#include "module.h"
+#include "windef.h"
+
+WINE_MODREF *ELFDLL_LoadLibraryExA(LPCSTR libname, DWORD flags);
+HINSTANCE16 ELFDLL_LoadModule16(LPCSTR libname);
+void ELFDLL_UnloadLibrary(WINE_MODREF *wm);
+
+void *ELFDLL_dlopen(const char *libname, int flags);
+extern char *extra_ld_library_path;
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/heap.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,56 @@
+/*
+ * Win32 heap definitions
+ *
+ * Copyright 1996 Alexandre Julliard
+ */
+
+#ifndef __WINE_HEAP_H
+#define __WINE_HEAP_H
+
+#include "config.h"
+
+#include "winbase.h"
+
+extern HANDLE SystemHeap;
+extern HANDLE SegptrHeap;
+
+extern int HEAP_IsInsideHeap( HANDLE heap, DWORD flags, LPCVOID ptr );
+extern SEGPTR HEAP_GetSegptr( HANDLE heap, DWORD flags, LPCVOID ptr );
+extern LPSTR HEAP_strdupA( HANDLE heap, DWORD flags, LPCSTR str );
+extern LPWSTR HEAP_strdupW( HANDLE heap, DWORD flags, LPCWSTR str );
+extern LPWSTR HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str );
+extern LPSTR HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str );
+
+/* SEGPTR helper macros */
+
+#define SEGPTR_ALLOC(size) \
+         (HeapAlloc( SegptrHeap, 0, (size) ))
+#define SEGPTR_NEW(type) \
+         ((type *)HeapAlloc( SegptrHeap, 0, sizeof(type) ))
+#define SEGPTR_STRDUP(str) \
+         (HIWORD(str) ? HEAP_strdupA( SegptrHeap, 0, (str) ) : (LPSTR)(str))
+#define SEGPTR_STRDUP_WtoA(str) \
+         (HIWORD(str) ? HEAP_strdupWtoA( SegptrHeap, 0, (str) ) : (LPSTR)(str))
+	/* define an inline function, a macro won't do */
+static inline SEGPTR WINE_UNUSED SEGPTR_Get(LPCVOID ptr) {
+         return (HIWORD(ptr) ? HEAP_GetSegptr( SegptrHeap, 0, ptr ) : (SEGPTR)ptr);
+}
+#define SEGPTR_GET(ptr) SEGPTR_Get(ptr)
+#define SEGPTR_FREE(ptr) \
+         (HIWORD(ptr) ? HeapFree( SegptrHeap, 0, (ptr) ) : 0)
+
+/* system heap private data */
+/* you must lock the system heap before using this structure */
+typedef struct
+{
+    void     *gdi;        /* GDI heap */
+    void     *user;       /* USER handle table */
+    void     *cursor;     /* cursor information */
+    void     *queue;      /* message queues descriptor */
+    void     *win;        /* windows descriptor */
+    void     *root;       /* X11 root window */
+} SYSTEM_HEAP_DESCR;
+
+extern SYSTEM_HEAP_DESCR *SystemHeapDescr;
+
+#endif  /* __WINE_HEAP_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/ldt.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,98 @@
+/*
+ * LDT copy
+ *
+ * Copyright 1995 Alexandre Julliard
+ */
+
+#ifndef __WINE_LDT_H
+#define __WINE_LDT_H
+
+#include "windef.h"
+enum seg_type
+{
+    SEGMENT_DATA  = 0,
+    SEGMENT_STACK = 1,
+    SEGMENT_CODE  = 2
+};
+
+  /* This structure represents a real LDT entry.        */
+  /* It is used by get_ldt_entry() and set_ldt_entry(). */
+typedef struct
+{
+    unsigned long base;            /* base address */
+    unsigned long limit;           /* segment limit (in pages or bytes) */
+    int           seg_32bit;       /* is segment 32-bit? */
+    int           read_only;       /* is segment read-only? */
+    int           limit_in_pages;  /* is the limit in pages or bytes? */
+    enum seg_type type;            /* segment type */
+} ldt_entry;
+#ifdef __cplusplus
+extern "C" 
+{
+#endif
+extern void LDT_BytesToEntry( const unsigned long *buffer, ldt_entry *content);
+extern void LDT_EntryToBytes( unsigned long *buffer, const ldt_entry *content);
+extern int LDT_GetEntry( int entry, ldt_entry *content );
+extern int LDT_SetEntry( int entry, const ldt_entry *content );
+extern void LDT_Print( int start, int length );
+
+
+  /* This structure is used to build the local copy of the LDT. */
+typedef struct
+{
+    unsigned long base;    /* base address or 0 if entry is free   */
+    unsigned long limit;   /* limit in bytes or 0 if entry is free */
+} ldt_copy_entry;
+
+#define LDT_SIZE  8192
+
+extern ldt_copy_entry ldt_copy[LDT_SIZE];
+
+#define __AHSHIFT  3  /* don't change! */
+#define __AHINCR   (1 << __AHSHIFT)
+
+#define SELECTOR_TO_ENTRY(sel)  (((int)(sel) & 0xffff) >> __AHSHIFT)
+#define ENTRY_TO_SELECTOR(i)    ((i) ? (((int)(i) << __AHSHIFT) | 7) : 0)
+#define IS_LDT_ENTRY_FREE(i)    (!(ldt_flags_copy[(i)] & LDT_FLAGS_ALLOCATED))
+#define IS_SELECTOR_FREE(sel)   (IS_LDT_ENTRY_FREE(SELECTOR_TO_ENTRY(sel)))
+#define GET_SEL_BASE(sel)       (ldt_copy[SELECTOR_TO_ENTRY(sel)].base)
+#define GET_SEL_LIMIT(sel)      (ldt_copy[SELECTOR_TO_ENTRY(sel)].limit)
+
+/* Convert a segmented ptr (16:16) to a linear (32) pointer */
+
+#define PTR_SEG_OFF_TO_LIN(seg,off) \
+   ((void*)(GET_SEL_BASE(seg) + (unsigned int)(off)))
+#define PTR_SEG_TO_LIN(ptr) \
+   PTR_SEG_OFF_TO_LIN(SELECTOROF(ptr),OFFSETOF(ptr))
+#define PTR_SEG_OFF_TO_SEGPTR(seg,off) \
+   ((SEGPTR)MAKELONG(off,seg))
+#define PTR_SEG_OFF_TO_HUGEPTR(seg,off) \
+   PTR_SEG_OFF_TO_SEGPTR( (seg) + (HIWORD(off) << __AHSHIFT), LOWORD(off) )
+
+#define W32S_APPLICATION() (PROCESS_Current()->flags & PDB32_WIN32S_PROC)
+#define W32S_OFFSET 0x10000
+#define W32S_APP2WINE(addr, offset) ((addr)? (DWORD)(addr) + (DWORD)(offset) : 0)
+#define W32S_WINE2APP(addr, offset) ((addr)? (DWORD)(addr) - (DWORD)(offset) : 0)
+
+extern unsigned char ldt_flags_copy[LDT_SIZE];
+
+#define LDT_FLAGS_TYPE      0x03  /* Mask for segment type */
+#define LDT_FLAGS_READONLY  0x04  /* Segment is read-only (data) */
+#define LDT_FLAGS_EXECONLY  0x04  /* Segment is execute-only (code) */
+#define LDT_FLAGS_32BIT     0x08  /* Segment is 32-bit (code or stack) */
+#define LDT_FLAGS_BIG       0x10  /* Segment is big (limit is in pages) */
+#define LDT_FLAGS_ALLOCATED 0x80  /* Segment is allocated (no longer free) */
+
+#define GET_SEL_FLAGS(sel)   (ldt_flags_copy[SELECTOR_TO_ENTRY(sel)])
+
+#define FIRST_LDT_ENTRY_TO_ALLOC  17
+
+/* Determine if sel is a system selector (i.e. not managed by Wine) */
+#define IS_SELECTOR_SYSTEM(sel) \
+   (!((sel) & 4) || (SELECTOR_TO_ENTRY(sel) < FIRST_LDT_ENTRY_TO_ALLOC))
+#define IS_SELECTOR_32BIT(sel) \
+   (IS_SELECTOR_SYSTEM(sel) || (GET_SEL_FLAGS(sel) & LDT_FLAGS_32BIT))
+#ifdef __cplusplus
+}
+#endif
+#endif  /* __WINE_LDT_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/mmreg.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,104 @@
+/*
+ *      mmreg.h   -       Declarations for ???
+ */
+
+#ifndef __WINE_MMREG_H
+#define __WINE_MMREG_H
+
+/***********************************************************************
+ * Defines/Enums
+ */
+
+#ifndef _ACM_WAVEFILTER
+#define _ACM_WAVEFILTER
+
+#include "windef.h"
+
+#define WAVE_FILTER_UNKNOWN     0x0000
+#define WAVE_FILTER_DEVELOPMENT 0xFFFF
+
+typedef struct _WAVEFILTER {
+  DWORD   cbStruct;
+  DWORD   dwFilterTag;
+  DWORD   fdwFilter;
+  DWORD   dwReserved[5];
+} WAVEFILTER, *PWAVEFILTER, *NPWAVEFILTER, *LPWAVEFILTER;
+#endif /* _ACM_WAVEFILTER */
+
+#ifndef WAVE_FILTER_VOLUME
+#define WAVE_FILTER_VOLUME      0x0001
+
+typedef struct _WAVEFILTER_VOLUME {
+   WAVEFILTER      wfltr;
+   DWORD           dwVolume;
+} VOLUMEWAVEFILTER, *PVOLUMEWAVEFILTER, *NPVOLUMEWAVEFILTER, *LPVOLUMEWAVEFILTER;
+#endif  /* WAVE_FILTER_VOLUME */
+
+#ifndef WAVE_FILTER_ECHO
+#define WAVE_FILTER_ECHO        0x0002
+
+typedef struct WAVEFILTER_ECHO {
+   WAVEFILTER      wfltr;
+   DWORD           dwVolume;
+   DWORD           dwDelay;
+} ECHOWAVEFILTER, *PECHOWAVEFILTER, *NPECHOWAVEFILTER, *LPECHOWAVEFILTER;
+#endif  /* WAVEFILTER_ECHO */
+    
+#ifndef _WAVEFORMATEX_
+#define _WAVEFORMATEX_
+typedef struct _WAVEFORMATEX {
+  WORD   wFormatTag;
+  WORD   nChannels;
+  DWORD  nSamplesPerSec;
+  DWORD  nAvgBytesPerSec;
+  WORD   nBlockAlign;
+  WORD   wBitsPerSample;
+  WORD   cbSize;
+} WAVEFORMATEX, *PWAVEFORMATEX, *NPWAVEFORMATEX, *LPWAVEFORMATEX;
+#endif /* _WAVEFORMATEX_ */
+
+/* WAVE form wFormatTag IDs */
+#define  WAVE_FORMAT_UNKNOWN			0x0000	/*  Microsoft Corporation  */
+#define  WAVE_FORMAT_ADPCM			0x0002	/*  Microsoft Corporation  */
+#define  WAVE_FORMAT_IBM_CVSD			0x0005	/*  IBM Corporation  */
+#define  WAVE_FORMAT_ALAW			0x0006	/*  Microsoft Corporation  */
+#define  WAVE_FORMAT_MULAW			0x0007	/*  Microsoft Corporation  */
+#define  WAVE_FORMAT_OKI_ADPCM			0x0010	/*  OKI  */
+#define  WAVE_FORMAT_DVI_ADPCM			0x0011	/*  Intel Corporation  */
+#define  WAVE_FORMAT_IMA_ADPCM			(WAVE_FORMAT_DVI_ADPCM)	/*  Intel Corporation  */
+#define  WAVE_FORMAT_MEDIASPACE_ADPCM		0x0012	/*  Videologic  */
+#define  WAVE_FORMAT_SIERRA_ADPCM		0x0013	/*  Sierra Semiconductor Corp  */
+#define  WAVE_FORMAT_G723_ADPCM			0x0014	/*  Antex Electronics Corporation  */
+#define  WAVE_FORMAT_DIGISTD			0x0015	/*  DSP Solutions, Inc.  */
+#define  WAVE_FORMAT_DIGIFIX			0x0016	/*  DSP Solutions, Inc.  */
+#define  WAVE_FORMAT_DIALOGIC_OKI_ADPCM		0x0017	/*  Dialogic Corporation  */
+#define  WAVE_FORMAT_YAMAHA_ADPCM		0x0020	/*  Yamaha Corporation of America  */
+#define  WAVE_FORMAT_SONARC			0x0021	/*  Speech Compression  */
+#define  WAVE_FORMAT_DSPGROUP_TRUESPEECH	0x0022	/*  DSP Group, Inc  */
+#define  WAVE_FORMAT_ECHOSC1			0x0023	/*  Echo Speech Corporation  */
+#define  WAVE_FORMAT_AUDIOFILE_AF36		0x0024	/*    */
+#define  WAVE_FORMAT_APTX			0x0025	/*  Audio Processing Technology  */
+#define  WAVE_FORMAT_AUDIOFILE_AF10		0x0026	/*    */
+#define  WAVE_FORMAT_DOLBY_AC2			0x0030	/*  Dolby Laboratories  */
+#define  WAVE_FORMAT_GSM610			0x0031	/*  Microsoft Corporation  */
+#define  WAVE_FORMAT_ANTEX_ADPCME		0x0033	/*  Antex Electronics Corporation  */
+#define  WAVE_FORMAT_CONTROL_RES_VQLPC		0x0034	/*  Control Resources Limited  */
+#define  WAVE_FORMAT_DIGIREAL			0x0035	/*  DSP Solutions, Inc.  */
+#define  WAVE_FORMAT_DIGIADPCM			0x0036	/*  DSP Solutions, Inc.  */
+#define  WAVE_FORMAT_CONTROL_RES_CR10		0x0037	/*  Control Resources Limited  */
+#define  WAVE_FORMAT_NMS_VBXADPCM		0x0038	/*  Natural MicroSystems  */
+#define  WAVE_FORMAT_G721_ADPCM			0x0040	/*  Antex Electronics Corporation  */
+#define  WAVE_FORMAT_MPEG			0x0050	/*  Microsoft Corporation  */
+#define  WAVE_FORMAT_CREATIVE_ADPCM		0x0200	/*  Creative Labs, Inc  */
+#define  WAVE_FORMAT_CREATIVE_FASTSPEECH8	0x0202	/*  Creative Labs, Inc  */
+#define  WAVE_FORMAT_CREATIVE_FASTSPEECH10	0x0203	/*  Creative Labs, Inc  */
+#define  WAVE_FORMAT_FM_TOWNS_SND		0x0300	/*  Fujitsu Corp.  */
+#define  WAVE_FORMAT_OLIGSM			0x1000	/*  Ing C. Olivetti & C., S.p.A.  */
+#define  WAVE_FORMAT_OLIADPCM			0x1001	/*  Ing C. Olivetti & C., S.p.A.  */
+#define  WAVE_FORMAT_OLICELP			0x1002	/*  Ing C. Olivetti & C., S.p.A.  */
+#define  WAVE_FORMAT_OLISBC			0x1003	/*  Ing C. Olivetti & C., S.p.A.  */
+#define  WAVE_FORMAT_OLIOPR			0x1004	/*  Ing C. Olivetti & C., S.p.A.  */
+
+#define WAVE_FORMAT_DEVELOPMENT         	(0xFFFF)
+
+#endif /* __WINE_MMREG_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/module.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,198 @@
+/*
+ * Module definitions
+ *
+ * Copyright 1995 Alexandre Julliard
+ */
+
+#ifndef __WINE_MODULE_H
+#define __WINE_MODULE_H
+
+#include "windef.h"
+//#include "dosexe.h"
+#include "pe_image.h"
+
+
+
+typedef struct {
+    BYTE type;
+    BYTE flags;
+    BYTE segnum;
+    WORD offs WINE_PACKED;
+} ET_ENTRY;
+
+typedef struct {
+    WORD first; /* ordinal */
+    WORD last; /* ordinal */
+    WORD next; /* bundle */
+} ET_BUNDLE;
+
+
+  /* In-memory segment table */
+typedef struct
+{
+    WORD      filepos;   /* Position in file, in sectors */
+    WORD      size;      /* Segment size on disk */
+    WORD      flags;     /* Segment flags */
+    WORD      minsize;   /* Min. size of segment in memory */
+    HANDLE16  hSeg;      /* Selector or handle (selector - 1) */
+                         /* of segment in memory */
+} SEGTABLEENTRY;
+
+
+  /* Self-loading modules contain this structure in their first segment */
+
+#include "pshpack1.h"
+
+typedef struct
+{
+    WORD      version;       /* Must be "A0" (0x3041) */
+    WORD      reserved;
+    FARPROC16 BootApp;       /* startup procedure */
+    FARPROC16 LoadAppSeg;    /* procedure to load a segment */
+    FARPROC16 reserved2;
+    FARPROC16 MyAlloc;       /* memory allocation procedure, 
+                              * wine must write this field */
+    FARPROC16 EntryAddrProc;
+    FARPROC16 ExitProc;      /* exit procedure */
+    WORD      reserved3[4];
+    FARPROC16 SetOwner;      /* Set Owner procedure, exported by wine */
+} SELFLOADHEADER;
+
+  /* Parameters for LoadModule() */
+typedef struct
+{
+    HGLOBAL16 hEnvironment;         /* Environment segment */
+    SEGPTR    cmdLine WINE_PACKED;  /* Command-line */
+    SEGPTR    showCmd WINE_PACKED;  /* Code for ShowWindow() */
+    SEGPTR    reserved WINE_PACKED;
+} LOADPARAMS16;
+
+typedef struct 
+{
+    LPSTR lpEnvAddress;
+    LPSTR lpCmdLine;
+    UINT16 *lpCmdShow;
+    DWORD dwReserved;
+} LOADPARAMS;
+
+#include "poppack.h"
+
+/* internal representation of 32bit modules. per process. */
+typedef enum {
+	MODULE32_PE = 1,
+	MODULE32_ELF,
+	MODULE32_ELFDLL
+} MODULE32_TYPE;
+
+typedef struct _wine_modref
+{
+	struct _wine_modref	*next;
+	struct _wine_modref	*prev;
+	MODULE32_TYPE		type;
+	union {
+		PE_MODREF	pe;
+		ELF_MODREF	elf;
+	} binfmt;
+
+	HMODULE			module;
+
+	int			nDeps;
+	struct _wine_modref	**deps;
+
+	int			flags;
+	int			refCount;
+
+	char			*filename;
+	char			*modname;
+	char			*short_filename;
+	char			*short_modname;
+} WINE_MODREF;
+
+#define WINE_MODREF_INTERNAL              0x00000001
+#define WINE_MODREF_NO_DLL_CALLS          0x00000002
+#define WINE_MODREF_PROCESS_ATTACHED      0x00000004
+#define WINE_MODREF_LOAD_AS_DATAFILE      0x00000010
+#define WINE_MODREF_DONT_RESOLVE_REFS     0x00000020
+#define WINE_MODREF_MARKER                0x80000000
+
+
+
+/* Resource types */
+typedef struct resource_typeinfo_s NE_TYPEINFO;
+typedef struct resource_nameinfo_s NE_NAMEINFO;
+
+#define NE_SEG_TABLE(pModule) \
+    ((SEGTABLEENTRY *)((char *)(pModule) + (pModule)->seg_table))
+
+#define NE_MODULE_TABLE(pModule) \
+    ((WORD *)((char *)(pModule) + (pModule)->modref_table))
+
+#define NE_MODULE_NAME(pModule) \
+    (((OFSTRUCT *)((char*)(pModule) + (pModule)->fileinfo))->szPathName)
+
+/* module.c */
+extern FARPROC MODULE_GetProcAddress( HMODULE hModule, LPCSTR function, WIN_BOOL snoop );
+extern WINE_MODREF *MODULE32_LookupHMODULE( HMODULE hModule );
+extern WIN_BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved );
+extern void MODULE_DllProcessDetach( WINE_MODREF *wm, WIN_BOOL bForceDetach, LPVOID lpReserved );
+extern void MODULE_DllThreadAttach( LPVOID lpReserved );
+extern void MODULE_DllThreadDetach( LPVOID lpReserved );
+extern WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags );
+extern WIN_BOOL MODULE_FreeLibrary( WINE_MODREF *wm );
+extern WINE_MODREF *MODULE_FindModule( LPCSTR path );
+extern HMODULE MODULE_CreateDummyModule( LPCSTR filename, HMODULE module32 );
+extern FARPROC16 WINAPI WIN32_GetProcAddress16( HMODULE hmodule, LPCSTR name );
+extern SEGPTR WINAPI HasGPHandler16( SEGPTR address );
+extern void MODULE_WalkModref( DWORD id );
+
+/* resource.c */
+extern INT       WINAPI AccessResource(HMODULE,HRSRC); 
+/*
+/ loader/ne/module.c 
+extern NE_MODULE *NE_GetPtr( HMODULE16 hModule );
+extern void NE_DumpModule( HMODULE16 hModule );
+extern void NE_WalkModules(void);
+extern void NE_RegisterModule( NE_MODULE *pModule );
+extern WORD NE_GetOrdinal( HMODULE16 hModule, const char *name );
+extern FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal );
+extern FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, WIN_BOOL16 snoop );
+extern WIN_BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset );
+extern int NE_OpenFile( NE_MODULE *pModule );
+extern WIN_BOOL NE_CreateProcess( HANDLE hFile, LPCSTR filename, LPCSTR cmd_line, LPCSTR env, 
+                              LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
+                              WIN_BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
+                              LPPROCESS_INFORMATION info );
+extern WIN_BOOL NE_InitProcess( NE_MODULE *pModule );
+
+
+/ loader/ne/resource.c 
+extern HGLOBAL16 WINAPI NE_DefResourceHandler(HGLOBAL16,HMODULE16,HRSRC16);
+extern WIN_BOOL NE_InitResourceHandler( HMODULE16 hModule );
+extern HRSRC16 NE_FindResource( NE_MODULE *pModule, LPCSTR name, LPCSTR type );
+extern INT16 NE_AccessResource( NE_MODULE *pModule, HRSRC16 hRsrc );
+extern DWORD NE_SizeofResource( NE_MODULE *pModule, HRSRC16 hRsrc );
+extern HGLOBAL16 NE_LoadResource( NE_MODULE *pModule, HRSRC16 hRsrc );
+extern WIN_BOOL16 NE_FreeResource( NE_MODULE *pModule, HGLOBAL16 handle );
+extern NE_TYPEINFO *NE_FindTypeSection( LPBYTE pResTab, NE_TYPEINFO *pTypeInfo, LPCSTR typeId );
+extern NE_NAMEINFO *NE_FindResourceFromType( LPBYTE pResTab, NE_TYPEINFO *pTypeInfo, LPCSTR resId );
+
+// loader/ne/segment.c
+extern WIN_BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum );
+extern WIN_BOOL NE_LoadAllSegments( NE_MODULE *pModule );
+extern WIN_BOOL NE_CreateSegment( NE_MODULE *pModule, int segnum );
+extern WIN_BOOL NE_CreateAllSegments( NE_MODULE *pModule );
+extern HINSTANCE16 NE_GetInstance( NE_MODULE *pModule );
+extern void NE_InitializeDLLs( HMODULE16 hModule );
+extern void NE_DllProcessAttach( HMODULE16 hModule );
+
+// loader/ne/convert.c 
+HGLOBAL16 NE_LoadPEResource( NE_MODULE *pModule, WORD type, LPVOID bits, DWORD size );
+*/
+/* relay32/builtin.c */
+extern WINE_MODREF *BUILTIN32_LoadLibraryExA(LPCSTR name, DWORD flags);
+extern HMODULE BUILTIN32_LoadExeModule( LPCSTR *filename );
+extern void BUILTIN32_UnloadLibrary(WINE_MODREF *wm);
+extern void *BUILTIN32_dlopen( const char *name );
+extern int BUILTIN32_dlclose( void *handle );
+
+#endif  /* __WINE_MODULE_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/msacm.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,942 @@
+/*
+ *      msacm.h   -       Declarations for MSACM
+ */
+
+#ifndef __WINE_MSACM_H
+#define __WINE_MSACM_H
+
+#include "windef.h"
+#include "driver.h"
+#include "mmreg.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* defined(__cplusplus) */
+
+//typedef WORD    VERSION;        /* major (high byte), minor (low byte) */
+
+typedef UINT16	MMVERSION16;
+typedef UINT	MMVERSION;
+typedef UINT16	MCIDEVICEID16;
+typedef UINT	MCIDEVICEID;
+typedef	UINT16	MMRESULT16;
+typedef	UINT	MMRESULT;
+typedef DWORD           FOURCC;         /* a four character code */
+
+
+
+#define WAVE_FORMAT_PCM     1
+
+/***********************************************************************
+ * Defines/Enums
+ */
+
+#define ACMERR_BASE        512
+#define ACMERR_NOTPOSSIBLE (ACMERR_BASE + 0)
+#define ACMERR_BUSY        (ACMERR_BASE + 1)
+#define ACMERR_UNPREPARED  (ACMERR_BASE + 2)
+#define ACMERR_CANCELED    (ACMERR_BASE + 3)
+
+#define MM_ACM_OPEN  MM_STREAM_OPEN
+#define MM_ACM_CLOSE MM_STREAM_CLOSE
+#define MM_ACM_DONE  MM_STREAM_DONE
+
+#define ACM_DRIVERADDF_FUNCTION   0x00000003L
+#define ACM_DRIVERADDF_NOTIFYHWND 0x00000004L
+#define ACM_DRIVERADDF_TYPEMASK   0x00000007L
+#define ACM_DRIVERADDF_LOCAL      0x00000000L
+#define ACM_DRIVERADDF_GLOBAL     0x00000008L
+
+#define ACMDRIVERDETAILS_SHORTNAME_CHARS  32
+#define ACMDRIVERDETAILS_LONGNAME_CHARS  128
+#define ACMDRIVERDETAILS_COPYRIGHT_CHARS  80
+#define ACMDRIVERDETAILS_LICENSING_CHARS 128
+#define ACMDRIVERDETAILS_FEATURES_CHARS  512
+
+#define ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC mmioFOURCC('a', 'u', 'd', 'c')
+#define ACMDRIVERDETAILS_FCCCOMP_UNDEFINED  mmioFOURCC('\0', '\0', '\0', '\0')
+
+#define ACMDRIVERDETAILS_SUPPORTF_CODEC     0x00000001L
+#define ACMDRIVERDETAILS_SUPPORTF_CONVERTER 0x00000002L
+#define ACMDRIVERDETAILS_SUPPORTF_FILTER    0x00000004L
+#define ACMDRIVERDETAILS_SUPPORTF_HARDWARE  0x00000008L
+#define ACMDRIVERDETAILS_SUPPORTF_ASYNC     0x00000010L
+#define ACMDRIVERDETAILS_SUPPORTF_LOCAL     0x40000000L
+#define ACMDRIVERDETAILS_SUPPORTF_DISABLED  0x80000000L
+
+#define ACM_DRIVERENUMF_NOLOCAL  0x40000000L
+#define ACM_DRIVERENUMF_DISABLED 0x80000000L
+
+#define ACM_DRIVERPRIORITYF_ENABLE    0x00000001L
+#define ACM_DRIVERPRIORITYF_DISABLE   0x00000002L
+#define ACM_DRIVERPRIORITYF_ABLEMASK  0x00000003L
+#define ACM_DRIVERPRIORITYF_BEGIN     0x00010000L
+#define ACM_DRIVERPRIORITYF_END       0x00020000L
+#define ACM_DRIVERPRIORITYF_DEFERMASK 0x00030000L
+
+#define MM_ACM_FILTERCHOOSE 0x8000
+
+#define FILTERCHOOSE_MESSAGE          0
+#define FILTERCHOOSE_FILTERTAG_VERIFY (FILTERCHOOSE_MESSAGE+0)
+#define FILTERCHOOSE_FILTER_VERIFY    (FILTERCHOOSE_MESSAGE+1)
+#define FILTERCHOOSE_CUSTOM_VERIFY    (FILTERCHOOSE_MESSAGE+2)
+
+#define ACMFILTERCHOOSE_STYLEF_SHOWHELP             0x00000004L
+#define ACMFILTERCHOOSE_STYLEF_ENABLEHOOK           0x00000008L
+#define ACMFILTERCHOOSE_STYLEF_ENABLETEMPLATE       0x00000010L
+#define ACMFILTERCHOOSE_STYLEF_ENABLETEMPLATEHANDLE 0x00000020L
+#define ACMFILTERCHOOSE_STYLEF_INITTOFILTERSTRUCT   0x00000040L
+#define ACMFILTERCHOOSE_STYLEF_CONTEXTHELP          0x00000080L
+
+#define ACMFILTERDETAILS_FILTER_CHARS 128
+
+#define ACM_FILTERDETAILSF_INDEX     0x00000000L
+#define ACM_FILTERDETAILSF_FILTER    0x00000001L
+#define ACM_FILTERDETAILSF_QUERYMASK 0x0000000FL
+
+#define ACMFILTERTAGDETAILS_FILTERTAG_CHARS 48
+
+#define ACM_FILTERTAGDETAILSF_INDEX       0x00000000L
+#define ACM_FILTERTAGDETAILSF_FILTERTAG   0x00000001L
+#define ACM_FILTERTAGDETAILSF_LARGESTSIZE 0x00000002L
+#define ACM_FILTERTAGDETAILSF_QUERYMASK   0x0000000FL
+
+#define ACM_FILTERENUMF_DWFILTERTAG 0x00010000L
+
+#define ACMHELPMSGSTRINGA       "acmchoose_help"
+#define ACMHELPMSGSTRINGW       L"acmchoose_help"
+#define ACMHELPMSGSTRING16       "acmchoose_help"
+
+#define ACMHELPMSGCONTEXTMENUA  "acmchoose_contextmenu"
+#define ACMHELPMSGCONTEXTMENUW  L"acmchoose_contextmenu"
+#define ACMHELPMSGCONTEXTMENU16   "acmchoose_contextmenu"
+
+#define ACMHELPMSGCONTEXTHELPA  "acmchoose_contexthelp"
+#define ACMHELPMSGCONTEXTHELPW  L"acmchoose_contexthelp"
+#define ACMHELPMSGCONTEXTHELP16   "acmchoose_contexthelp"
+
+#define MM_ACM_FORMATCHOOSE 0x8000
+
+#define FORMATCHOOSE_MESSAGE          0
+#define FORMATCHOOSE_FORMATTAG_VERIFY (FORMATCHOOSE_MESSAGE+0)
+#define FORMATCHOOSE_FORMAT_VERIFY    (FORMATCHOOSE_MESSAGE+1)
+#define FORMATCHOOSE_CUSTOM_VERIFY    (FORMATCHOOSE_MESSAGE+2)
+
+#define ACMFORMATCHOOSE_STYLEF_SHOWHELP             0x00000004L
+#define ACMFORMATCHOOSE_STYLEF_ENABLEHOOK           0x00000008L
+#define ACMFORMATCHOOSE_STYLEF_ENABLETEMPLATE       0x00000010L
+#define ACMFORMATCHOOSE_STYLEF_ENABLETEMPLATEHANDLE 0x00000020L
+#define ACMFORMATCHOOSE_STYLEF_INITTOWFXSTRUCT      0x00000040L
+#define ACMFORMATCHOOSE_STYLEF_CONTEXTHELP          0x00000080L
+
+#define ACMFORMATDETAILS_FORMAT_CHARS   128
+
+#define ACM_FORMATDETAILSF_INDEX     0x00000000L
+#define ACM_FORMATDETAILSF_FORMAT    0x00000001L
+#define ACM_FORMATDETAILSF_QUERYMASK 0x0000000FL
+
+#define ACM_FORMATENUMF_WFORMATTAG     0x00010000L
+#define ACM_FORMATENUMF_NCHANNELS      0x00020000L
+#define ACM_FORMATENUMF_NSAMPLESPERSEC 0x00040000L
+#define ACM_FORMATENUMF_WBITSPERSAMPLE 0x00080000L
+#define ACM_FORMATENUMF_CONVERT        0x00100000L
+#define ACM_FORMATENUMF_SUGGEST        0x00200000L
+#define ACM_FORMATENUMF_HARDWARE       0x00400000L
+#define ACM_FORMATENUMF_INPUT          0x00800000L
+#define ACM_FORMATENUMF_OUTPUT         0x01000000L
+
+#define ACM_FORMATSUGGESTF_WFORMATTAG     0x00010000L
+#define ACM_FORMATSUGGESTF_NCHANNELS      0x00020000L
+#define ACM_FORMATSUGGESTF_NSAMPLESPERSEC 0x00040000L
+#define ACM_FORMATSUGGESTF_WBITSPERSAMPLE 0x00080000L
+#define ACM_FORMATSUGGESTF_TYPEMASK       0x00FF0000L
+
+#define ACMFORMATTAGDETAILS_FORMATTAG_CHARS 48
+
+#define ACM_FORMATTAGDETAILSF_INDEX       0x00000000L
+#define ACM_FORMATTAGDETAILSF_FORMATTAG   0x00000001L
+#define ACM_FORMATTAGDETAILSF_LARGESTSIZE 0x00000002L
+#define ACM_FORMATTAGDETAILSF_QUERYMASK   0x0000000FL
+
+#define ACM_METRIC_COUNT_DRIVERS            1
+#define ACM_METRIC_COUNT_CODECS             2
+#define ACM_METRIC_COUNT_CONVERTERS         3
+#define ACM_METRIC_COUNT_FILTERS            4
+#define ACM_METRIC_COUNT_DISABLED           5
+#define ACM_METRIC_COUNT_HARDWARE           6
+#define ACM_METRIC_COUNT_LOCAL_DRIVERS     20
+#define ACM_METRIC_COUNT_LOCAL_CODECS      21
+#define ACM_METRIC_COUNT_LOCAL_CONVERTERS  22
+#define ACM_METRIC_COUNT_LOCAL_FILTERS     23
+#define ACM_METRIC_COUNT_LOCAL_DISABLED    24
+#define ACM_METRIC_HARDWARE_WAVE_INPUT     30
+#define ACM_METRIC_HARDWARE_WAVE_OUTPUT    31
+#define ACM_METRIC_MAX_SIZE_FORMAT         50
+#define ACM_METRIC_MAX_SIZE_FILTER         51
+#define ACM_METRIC_DRIVER_SUPPORT         100
+#define ACM_METRIC_DRIVER_PRIORITY        101
+
+#define ACM_STREAMCONVERTF_BLOCKALIGN 0x00000004
+#define ACM_STREAMCONVERTF_START      0x00000010
+#define ACM_STREAMCONVERTF_END        0x00000020
+
+#define ACMSTREAMHEADER_STATUSF_DONE     0x00010000L
+#define ACMSTREAMHEADER_STATUSF_PREPARED 0x00020000L
+#define ACMSTREAMHEADER_STATUSF_INQUEUE  0x00100000L
+
+#define ACM_STREAMOPENF_QUERY       0x00000001
+#define ACM_STREAMOPENF_ASYNC       0x00000002
+#define ACM_STREAMOPENF_NONREALTIME 0x00000004
+
+#define ACM_STREAMSIZEF_SOURCE      0x00000000L
+#define ACM_STREAMSIZEF_DESTINATION 0x00000001L
+#define ACM_STREAMSIZEF_QUERYMASK   0x0000000FL
+
+#define ACMDM_USER                  (DRV_USER + 0x0000)
+#define ACMDM_RESERVED_LOW          (DRV_USER + 0x2000)
+#define ACMDM_RESERVED_HIGH         (DRV_USER + 0x2FFF)
+
+#define ACMDM_BASE                  ACMDM_RESERVED_LOW
+
+#define ACMDM_DRIVER_ABOUT          (ACMDM_BASE + 11)
+
+/***********************************************************************
+ * Callbacks
+ */
+
+typedef WIN_BOOL CALLBACK ( *ACMDRIVERENUMCB)(
+  HACMDRIVERID hadid, DWORD dwInstance, DWORD fdwSupport
+);
+
+typedef WIN_BOOL16 CALLBACK ( *ACMDRIVERENUMCB16)(
+  HACMDRIVERID16 hadid, DWORD dwInstance, DWORD fdwSupport
+);
+
+typedef UINT CALLBACK ( *ACMFILTERCHOOSEHOOKPROCA)(
+  HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam
+);
+
+typedef UINT CALLBACK ( *ACMFILTERCHOOSEHOOKPROCW)(
+  HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam
+);
+
+typedef UINT CALLBACK ( *ACMFILTERCHOOSEHOOKPROC16)(
+  HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam
+);
+
+typedef UINT CALLBACK ( *ACMFORMATCHOOSEHOOKPROCA)(
+  HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam
+);
+
+typedef UINT CALLBACK ( *ACMFORMATCHOOSEHOOKPROCW)(
+  HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam
+);
+
+typedef UINT16 CALLBACK ( *ACMFORMATCHOOSEHOOKPROC16)(
+  HWND16 hwnd, UINT16 uMsg, WPARAM16 wParam, LPARAM lParam
+);
+
+/***********************************************************************
+ * Structures
+ */
+
+typedef struct _ACMDRIVERDETAILSA
+{
+  DWORD    cbStruct;
+
+  FOURCC   fccType;
+  FOURCC   fccComp;
+
+  WORD     wMid;
+  WORD     wPid;
+
+  DWORD    vdwACM;
+  DWORD    vdwDriver;
+
+  DWORD    fdwSupport;
+  DWORD    cFormatTags;
+  DWORD    cFilterTags;
+
+  HICON  hicon;
+
+  CHAR     szShortName[ACMDRIVERDETAILS_SHORTNAME_CHARS];
+  CHAR     szLongName[ACMDRIVERDETAILS_LONGNAME_CHARS];
+  CHAR     szCopyright[ACMDRIVERDETAILS_COPYRIGHT_CHARS];
+  CHAR     szLicensing[ACMDRIVERDETAILS_LICENSING_CHARS];
+  CHAR     szFeatures[ACMDRIVERDETAILS_FEATURES_CHARS];
+} ACMDRIVERDETAILSA, *PACMDRIVERDETAILSA;
+
+typedef struct _ACMDRIVERDETAILSW
+{
+  DWORD    cbStruct;
+
+  FOURCC   fccType;
+  FOURCC   fccComp;
+
+  WORD     wMid;
+  WORD     wPid;
+
+  DWORD    vdwACM;
+  DWORD    vdwDriver;
+
+  DWORD    fdwSupport;
+  DWORD    cFormatTags;
+  DWORD    cFilterTags;
+
+  HICON  hicon;
+
+  WCHAR    szShortName[ACMDRIVERDETAILS_SHORTNAME_CHARS];
+  WCHAR    szLongName[ACMDRIVERDETAILS_LONGNAME_CHARS];
+  WCHAR    szCopyright[ACMDRIVERDETAILS_COPYRIGHT_CHARS];
+  WCHAR    szLicensing[ACMDRIVERDETAILS_LICENSING_CHARS];
+  WCHAR    szFeatures[ACMDRIVERDETAILS_FEATURES_CHARS];
+} ACMDRIVERDETAILSW, *PACMDRIVERDETAILSW;
+
+typedef struct _ACMDRIVERDETAILS16
+{
+  DWORD   cbStruct;
+
+  FOURCC  fccType;
+  FOURCC  fccComp;
+
+  WORD    wMid;
+  WORD    wPid;
+
+  DWORD   vdwACM;
+  DWORD   vdwDriver;
+
+  DWORD   fdwSupport;
+  DWORD   cFormatTags;
+  DWORD   cFilterTags;
+
+  HICON16 hicon;
+
+  CHAR    szShortName[ACMDRIVERDETAILS_SHORTNAME_CHARS];
+  CHAR    szLongName[ACMDRIVERDETAILS_LONGNAME_CHARS];
+  CHAR    szCopyright[ACMDRIVERDETAILS_COPYRIGHT_CHARS];
+  CHAR    szLicensing[ACMDRIVERDETAILS_LICENSING_CHARS];
+  CHAR    szFeatures[ACMDRIVERDETAILS_FEATURES_CHARS];
+} ACMDRIVERDETAILS16, *NPACMDRIVERDETAILS16, *LPACMDRIVERDETAILS16;
+
+typedef struct _ACMFILTERCHOOSEA
+{
+  DWORD         cbStruct;
+  DWORD         fdwStyle;
+
+  HWND        hwndOwner;
+
+  PWAVEFILTER   pwfltr;
+  DWORD         cbwfltr;
+
+  LPCSTR        pszTitle;
+
+  CHAR          szFilterTag[ACMFILTERTAGDETAILS_FILTERTAG_CHARS];
+  CHAR          szFilter[ACMFILTERDETAILS_FILTER_CHARS];
+  LPSTR         pszName;
+  DWORD         cchName;
+
+  DWORD         fdwEnum;
+  PWAVEFILTER   pwfltrEnum;
+    
+  HINSTANCE   hInstance;
+  LPCSTR        pszTemplateName;
+  LPARAM        lCustData;
+  ACMFILTERCHOOSEHOOKPROCA pfnHook;
+} ACMFILTERCHOOSEA, *PACMFILTERCHOOSEA;
+
+typedef struct _ACMFILTERCHOOSEW
+{
+  DWORD         cbStruct;
+  DWORD         fdwStyle;
+
+  HWND        hwndOwner;
+
+  PWAVEFILTER   pwfltr;
+  DWORD         cbwfltr;
+
+  LPCWSTR       pszTitle;
+
+  WCHAR         szFilterTag[ACMFILTERTAGDETAILS_FILTERTAG_CHARS];
+  WCHAR         szFilter[ACMFILTERDETAILS_FILTER_CHARS];
+  LPWSTR        pszName;
+  DWORD         cchName;
+
+  DWORD         fdwEnum;
+  PWAVEFILTER   pwfltrEnum;
+    
+  HINSTANCE   hInstance;
+  LPCWSTR       pszTemplateName;
+  LPARAM        lCustData;
+  ACMFILTERCHOOSEHOOKPROCW pfnHook;
+} ACMFILTERCHOOSEW, *PACMFILTERCHOOSEW;
+
+typedef struct _ACMFILTERCHOOSE16
+{
+  DWORD          cbStruct;
+  DWORD          fdwStyle;
+
+  HWND16         hwndOwner;
+
+  LPWAVEFILTER   pwfltr;
+  DWORD          cbwfltr;
+
+  LPCSTR         pszTitle;
+
+  char           szFilterTag[ACMFILTERTAGDETAILS_FILTERTAG_CHARS];
+  char           szFilter[ACMFILTERDETAILS_FILTER_CHARS];
+  LPSTR          pszName;
+  DWORD          cchName;
+
+  DWORD          fdwEnum;
+  LPWAVEFILTER   pwfltrEnum;
+    
+  HINSTANCE16    hInstance;
+  LPCSTR         pszTemplateName;
+  LPARAM         lCustData;
+  ACMFILTERCHOOSEHOOKPROC16 pfnHook;
+} ACMFILTERCHOOSE16, *NPACMFILTERCHOOSE16, *LPACMFILTERCHOOSE16;
+
+typedef struct _ACMFILTERDETAILSA
+{
+  DWORD           cbStruct;
+  DWORD           dwFilterIndex;
+  DWORD           dwFilterTag;
+  DWORD           fdwSupport;
+  PWAVEFILTER     pwfltr;
+  DWORD           cbwfltr;
+  CHAR            szFilter[ACMFILTERDETAILS_FILTER_CHARS];
+} ACMFILTERDETAILSA, *PACMFILTERDETAILSA;
+
+typedef struct _ACMFILTERDETAILSW
+{
+  DWORD          cbStruct;
+  DWORD          dwFilterIndex;
+  DWORD          dwFilterTag;
+  DWORD          fdwSupport;
+  PWAVEFILTER    pwfltr;
+  DWORD          cbwfltr;
+  WCHAR          szFilter[ACMFILTERDETAILS_FILTER_CHARS];
+} ACMFILTERDETAILSW, *PACMFILTERDETAILSW;
+
+typedef struct _ACMFILTERDETAILS16
+{
+  DWORD          cbStruct;
+  DWORD          dwFilterIndex;
+  DWORD          dwFilterTag;
+  DWORD          fdwSupport;
+  LPWAVEFILTER   pwfltr;
+  DWORD          cbwfltr;
+  CHAR           szFilter[ACMFILTERDETAILS_FILTER_CHARS];
+} ACMFILTERDETAILS16, *NPACMFILTERDETAILS16, *LPACMFILTERDETAILS16;
+
+typedef struct _ACMFILTERTAGDETAILSA
+{
+  DWORD cbStruct;
+  DWORD dwFilterTagIndex;
+  DWORD dwFilterTag;
+  DWORD cbFilterSize;
+  DWORD fdwSupport;
+  DWORD cStandardFilters;
+  CHAR  szFilterTag[ACMFILTERTAGDETAILS_FILTERTAG_CHARS];
+} ACMFILTERTAGDETAILSA, *PACMFILTERTAGDETAILSA;
+
+typedef struct _ACMFILTERTAGDETAILSW
+{
+  DWORD cbStruct;
+  DWORD dwFilterTagIndex;
+  DWORD dwFilterTag;
+  DWORD cbFilterSize;
+  DWORD fdwSupport;
+  DWORD cStandardFilters;
+  WCHAR szFilterTag[ACMFILTERTAGDETAILS_FILTERTAG_CHARS];
+} ACMFILTERTAGDETAILSW, *PACMFILTERTAGDETAILSW;
+
+typedef struct _ACMFILTERTAGDETAILS16
+{
+  DWORD cbStruct;
+  DWORD dwFilterTagIndex;
+  DWORD dwFilterTag;
+  DWORD cbFilterSize;
+  DWORD fdwSupport;
+  DWORD cStandardFilters;
+  CHAR  szFilterTag[ACMFILTERTAGDETAILS_FILTERTAG_CHARS];
+} ACMFILTERTAGDETAILS16, *NPACMFILTERTAGDETAILS16, *LPACMFILTERTAGDETAILS16;
+
+typedef struct _ACMFORMATCHOOSEA
+{
+  DWORD           cbStruct;
+  DWORD           fdwStyle;
+ 
+  HWND          hwndOwner;
+
+  PWAVEFORMATEX   pwfx;
+  DWORD           cbwfx;
+  LPCSTR          pszTitle;
+    
+  CHAR            szFormatTag[ACMFORMATTAGDETAILS_FORMATTAG_CHARS];
+  CHAR            szFormat[ACMFORMATDETAILS_FORMAT_CHARS];    
+
+  LPSTR           pszName;
+  DWORD           cchName;
+
+  DWORD           fdwEnum;
+  PWAVEFORMATEX   pwfxEnum;
+    
+  HINSTANCE     hInstance;
+  LPCSTR          pszTemplateName;
+  LPARAM          lCustData;
+  ACMFORMATCHOOSEHOOKPROCA pfnHook;
+} ACMFORMATCHOOSEA, *PACMFORMATCHOOSEA;
+
+typedef struct _ACMFORMATCHOOSEW
+{
+  DWORD           cbStruct;
+  DWORD           fdwStyle;
+    
+  HWND          hwndOwner;
+
+  PWAVEFORMATEX   pwfx;
+  DWORD           cbwfx;
+  LPCWSTR         pszTitle;
+    
+  WCHAR           szFormatTag[ACMFORMATTAGDETAILS_FORMATTAG_CHARS];
+  WCHAR           szFormat[ACMFORMATDETAILS_FORMAT_CHARS];    
+
+  LPWSTR          pszName;
+  DWORD           cchName;
+
+  DWORD           fdwEnum;
+  LPWAVEFORMATEX  pwfxEnum;
+    
+  HINSTANCE     hInstance;
+  LPCWSTR         pszTemplateName;
+  LPARAM          lCustData;
+  ACMFORMATCHOOSEHOOKPROCW pfnHook;
+} ACMFORMATCHOOSEW, *PACMFORMATCHOOSEW;
+
+typedef struct _ACMFORMATCHOOSE16
+{
+  DWORD            cbStruct;
+  DWORD            fdwStyle;
+    
+  HWND16           hwndOwner;
+
+  LPWAVEFORMATEX   pwfx;
+  DWORD            cbwfx;
+  LPCSTR           pszTitle;
+    
+  CHAR             szFormatTag[ACMFORMATTAGDETAILS_FORMATTAG_CHARS];
+  CHAR             szFormat[ACMFORMATDETAILS_FORMAT_CHARS];    
+
+  LPSTR            pszName;
+  DWORD            cchName;
+
+  DWORD            fdwEnum;
+  LPWAVEFORMATEX   pwfxEnum;
+    
+  HINSTANCE16      hInstance;
+  LPCSTR           pszTemplateName;
+  LPARAM           lCustData;
+  ACMFORMATCHOOSEHOOKPROC16 pfnHook;
+} ACMFORMATCHOOSE16, *NPACMFORMATCHOOSE16, *LPACMFORMATCHOOSE16;
+
+typedef struct _ACMFORMATDETAILSA
+{
+  DWORD           cbStruct;
+  DWORD           dwFormatIndex;
+  DWORD           dwFormatTag;
+  DWORD           fdwSupport;
+  PWAVEFORMATEX   pwfx;
+  DWORD           cbwfx;
+  CHAR            szFormat[ACMFORMATDETAILS_FORMAT_CHARS];
+} ACMFORMATDETAILSA, *PACMFORMATDETAILSA;
+
+typedef struct _ACMFORMATDETAILSW
+{
+    DWORD           cbStruct;
+    DWORD           dwFormatIndex;
+    DWORD           dwFormatTag;
+    DWORD           fdwSupport;
+    PWAVEFORMATEX   pwfx;
+    DWORD           cbwfx;
+    WCHAR           szFormat[ACMFORMATDETAILS_FORMAT_CHARS];
+} ACMFORMATDETAILSW, *PACMFORMATDETAILSW;
+
+typedef struct _ACMFORMATDETAILS16
+{
+    DWORD            cbStruct;
+    DWORD            dwFormatIndex;
+    DWORD            dwFormatTag;
+    DWORD            fdwSupport;
+    LPWAVEFORMATEX   pwfx;
+    DWORD            cbwfx;
+    CHAR             szFormat[ACMFORMATDETAILS_FORMAT_CHARS];
+} ACMFORMATDETAILS16, *NPACMFORMATDETAILS16, *LPACMFORMATDETAILS16;
+
+typedef struct _ACMFORMATTAGDETAILSA
+{
+  DWORD cbStruct;
+  DWORD dwFormatTagIndex;
+  DWORD dwFormatTag;
+  DWORD cbFormatSize;
+  DWORD fdwSupport;
+  DWORD cStandardFormats;
+  CHAR  szFormatTag[ACMFORMATTAGDETAILS_FORMATTAG_CHARS];
+} ACMFORMATTAGDETAILSA, *PACMFORMATTAGDETAILSA;
+
+typedef struct _ACMFORMATTAGDETAILSW
+{
+  DWORD cbStruct;
+  DWORD dwFormatTagIndex;
+  DWORD dwFormatTag;
+  DWORD cbFormatSize;
+  DWORD fdwSupport;
+  DWORD cStandardFormats;
+  WCHAR szFormatTag[ACMFORMATTAGDETAILS_FORMATTAG_CHARS];
+} ACMFORMATTAGDETAILSW, *PACMFORMATTAGDETAILSW;
+
+typedef struct _ACMFORMATTAGDETAILS16
+{
+  DWORD cbStruct;
+  DWORD dwFormatTagIndex;
+  DWORD dwFormatTag;
+  DWORD cbFormatSize;
+  DWORD fdwSupport;
+  DWORD cStandardFormats;
+  CHAR  szFormatTag[ACMFORMATTAGDETAILS_FORMATTAG_CHARS];
+} ACMFORMATTAGDETAILS16, *NPACMFORMATTAGDETAILS16, *LPACMFORMATTAGDETAILS16;
+
+typedef struct _ACMSTREAMHEADER
+{
+  DWORD  cbStruct;
+  DWORD  fdwStatus;
+  DWORD  dwUser;
+  LPBYTE pbSrc;
+  DWORD  cbSrcLength;
+  DWORD  cbSrcLengthUsed;
+  DWORD  dwSrcUser;
+  LPBYTE pbDst;
+  DWORD  cbDstLength;
+  DWORD  cbDstLengthUsed;
+  DWORD  dwDstUser;
+  DWORD  dwReservedDriver[10];
+} ACMSTREAMHEADER16, *NPACMSTREAMHEADER16, *LPACMSTREAMHEADER16,
+  ACMSTREAMHEADER, *PACMSTREAMHEADER;
+
+/***********************************************************************
+ * Callbacks 2
+ */
+
+typedef WIN_BOOL CALLBACK ( *ACMFILTERENUMCBA)(
+  HACMDRIVERID hadid, PACMFILTERDETAILSA pafd,
+  DWORD dwInstance, DWORD fdwSupport
+);
+
+typedef WIN_BOOL CALLBACK ( *ACMFILTERENUMCBW)(
+  HACMDRIVERID hadid, PACMFILTERDETAILSW pafd,
+  DWORD dwInstance, DWORD fdwSupport
+);
+
+typedef WIN_BOOL16 CALLBACK ( *ACMFILTERENUMCB16)(
+ HACMDRIVERID16 hadid, LPACMFILTERDETAILS16 pafd,
+ DWORD dwInstance, DWORD fdwSupport
+);
+
+typedef WIN_BOOL CALLBACK ( *ACMFILTERTAGENUMCBA)(
+  HACMDRIVERID hadid, PACMFILTERTAGDETAILSA paftd,
+  DWORD dwInstance, DWORD fdwSupport
+);
+
+typedef WIN_BOOL CALLBACK ( *ACMFILTERTAGENUMCBW)(
+  HACMDRIVERID hadid, PACMFILTERTAGDETAILSW paftd,
+  DWORD dwInstance, DWORD fdwSupport
+);
+
+typedef WIN_BOOL16 CALLBACK ( *ACMFILTERTAGENUMCB16)(
+  HACMDRIVERID16 hadid, LPACMFILTERTAGDETAILS16 paftd,
+  DWORD dwInstance, DWORD fdwSupport
+);
+
+typedef WIN_BOOL CALLBACK ( *ACMFORMATENUMCBA)(
+  HACMDRIVERID hadid, PACMFORMATDETAILSA pafd,
+  DWORD dwInstance, DWORD fdwSupport
+);
+
+typedef WIN_BOOL CALLBACK ( *ACMFORMATENUMCBW)(
+  HACMDRIVERID hadid, PACMFORMATDETAILSW pafd,
+  DWORD dwInstance, DWORD fdwSupport
+);
+
+typedef WIN_BOOL16 CALLBACK ( *ACMFORMATENUMCB16)(
+  HACMDRIVERID16 hadid, LPACMFORMATDETAILS16 pafd,
+  DWORD dwInstance, DWORD fdwSupport
+);
+
+typedef WIN_BOOL CALLBACK ( *ACMFORMATTAGENUMCBA)(
+  HACMDRIVERID hadid, PACMFORMATTAGDETAILSA paftd,
+  DWORD dwInstance, DWORD fdwSupport
+);
+
+typedef WIN_BOOL CALLBACK ( *ACMFORMATTAGENUMCBW)(
+  HACMDRIVERID hadid, PACMFORMATTAGDETAILSW paftd,
+  DWORD dwInstance, DWORD fdwSupport
+);
+
+typedef WIN_BOOL16 CALLBACK ( *ACMFORMATTAGENUMCB16)(
+  HACMDRIVERID16 hadid, LPACMFORMATTAGDETAILS16 paftd,
+  DWORD dwInstance, DWORD fdwSupport
+);
+
+/***********************************************************************
+ * Functions - Win16
+ */
+
+DWORD WINAPI acmGetVersion16(
+);
+MMRESULT16 WINAPI acmMetrics16(
+  HACMOBJ16 hao, UINT16 uMetric, LPVOID pMetric
+);
+MMRESULT16 WINAPI acmDriverEnum16(
+  ACMDRIVERENUMCB16 fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT16 WINAPI acmDriverDetails16(
+  HACMDRIVERID16 hadid, LPACMDRIVERDETAILS16 padd, DWORD fdwDetails
+);
+MMRESULT16 WINAPI acmDriverAdd16(
+  LPHACMDRIVERID16 phadid, HINSTANCE16 hinstModule,
+  LPARAM lParam, DWORD dwPriority, DWORD fdwAdd
+);
+MMRESULT16 WINAPI acmDriverRemove16(
+  HACMDRIVERID16 hadid, DWORD fdwRemove
+);
+MMRESULT16 WINAPI acmDriverOpen16(
+  LPHACMDRIVER16 phad, HACMDRIVERID16 hadid, DWORD fdwOpen
+);
+MMRESULT16 WINAPI acmDriverClose16(
+  HACMDRIVER16 had, DWORD fdwClose
+);
+LRESULT WINAPI acmDriverMessage16(
+  HACMDRIVER16 had, UINT16 uMsg, LPARAM lParam1, LPARAM lParam2
+);
+MMRESULT16 WINAPI acmDriverID16(
+  HACMOBJ16 hao, LPHACMDRIVERID16 phadid, DWORD fdwDriverID
+);
+MMRESULT16 WINAPI acmDriverPriority16(
+ HACMDRIVERID16 hadid, DWORD dwPriority, DWORD fdwPriority
+);
+MMRESULT16 WINAPI acmFormatTagDetails16(
+  HACMDRIVER16 had, LPACMFORMATTAGDETAILS16 paftd, DWORD fdwDetails
+);
+MMRESULT16 WINAPI acmFormatTagEnum16(
+  HACMDRIVER16 had, LPACMFORMATTAGDETAILS16 paftd,
+  ACMFORMATTAGENUMCB16 fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT16 WINAPI acmFormatChoose16(
+  LPACMFORMATCHOOSE16 pafmtc
+);
+MMRESULT16 WINAPI acmFormatDetails16(
+  HACMDRIVER16 had, LPACMFORMATDETAILS16 pafd, DWORD fdwDetails
+);
+MMRESULT16 WINAPI acmFormatEnum16(
+  HACMDRIVER16 had, LPACMFORMATDETAILS16 pafd,
+  ACMFORMATENUMCB16 fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT16 WINAPI acmFormatSuggest16(
+  HACMDRIVER16 had, LPWAVEFORMATEX pwfxSrc, 
+  LPWAVEFORMATEX pwfxDst, DWORD cbwfxDst, DWORD fdwSuggest
+);
+MMRESULT16 WINAPI acmFilterTagDetails16(
+  HACMDRIVER16 had, LPACMFILTERTAGDETAILS16 paftd, DWORD fdwDetails
+);
+MMRESULT16 WINAPI acmFilterTagEnum16(
+  HACMDRIVER16 had, LPACMFILTERTAGDETAILS16 paftd,
+  ACMFILTERTAGENUMCB16 fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT16 WINAPI acmFilterChoose16(
+  LPACMFILTERCHOOSE16 pafltrc
+);
+MMRESULT16 WINAPI acmFilterDetails16(
+  HACMDRIVER16 had, LPACMFILTERDETAILS16 pafd, DWORD fdwDetails
+);
+MMRESULT16 WINAPI acmFilterEnum16(
+  HACMDRIVER16 had, LPACMFILTERDETAILS16 pafd,
+  ACMFILTERENUMCB16 fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT16 WINAPI acmStreamOpen16(
+  LPHACMSTREAM16 phas, HACMDRIVER16 had,
+  LPWAVEFORMATEX pwfxSrc, LPWAVEFORMATEX pwfxDst,
+  LPWAVEFILTER pwfltr, DWORD dwCallback,
+  DWORD dwInstance, DWORD fdwOpen
+);
+MMRESULT16 WINAPI acmStreamClose16(
+  HACMSTREAM16 has, DWORD fdwClose
+);
+MMRESULT16 WINAPI acmStreamSize16(
+  HACMSTREAM16 has, DWORD cbInput, 
+  LPDWORD pdwOutputBytes, DWORD fdwSize
+);
+MMRESULT16 WINAPI acmStreamConvert16(
+  HACMSTREAM16 has, LPACMSTREAMHEADER16 pash, DWORD fdwConvert
+);
+MMRESULT16 WINAPI acmStreamReset16(
+  HACMSTREAM16 has, DWORD fdwReset
+);
+MMRESULT16 WINAPI acmStreamPrepareHeader16(
+  HACMSTREAM16 has, LPACMSTREAMHEADER16 pash, DWORD fdwPrepare
+);
+MMRESULT16 WINAPI acmStreamUnprepareHeader16(
+  HACMSTREAM16 has, LPACMSTREAMHEADER16 pash, DWORD fdwUnprepare
+);
+
+/***********************************************************************
+ * Functions - Win32
+ */
+
+MMRESULT WINAPI acmDriverAddA(
+  PHACMDRIVERID phadid, HINSTANCE hinstModule,
+  LPARAM lParam, DWORD dwPriority, DWORD fdwAdd
+);
+MMRESULT WINAPI acmDriverAddW(
+  PHACMDRIVERID phadid, HINSTANCE hinstModule,
+  LPARAM lParam, DWORD dwPriority, DWORD fdwAdd
+);
+MMRESULT WINAPI acmDriverClose(
+  HACMDRIVER had, DWORD fdwClose
+);
+MMRESULT WINAPI acmDriverDetailsA(
+  HACMDRIVERID hadid, PACMDRIVERDETAILSA padd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmDriverDetailsW(
+  HACMDRIVERID hadid, PACMDRIVERDETAILSW padd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmDriverEnum(
+  ACMDRIVERENUMCB fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT WINAPI acmDriverID(
+  HACMOBJ hao, PHACMDRIVERID phadid, DWORD fdwDriverID
+);
+LRESULT WINAPI acmDriverMessage(
+  HACMDRIVER had, UINT uMsg, LPARAM lParam1, LPARAM lParam2
+);
+MMRESULT WINAPI acmDriverOpen(
+  PHACMDRIVER phad, HACMDRIVERID hadid, DWORD fdwOpen
+);
+MMRESULT WINAPI acmDriverPriority(
+  HACMDRIVERID hadid, DWORD dwPriority, DWORD fdwPriority
+);
+MMRESULT WINAPI acmDriverRemove(
+  HACMDRIVERID hadid, DWORD fdwRemove
+);
+MMRESULT WINAPI acmFilterChooseA(
+  PACMFILTERCHOOSEA pafltrc
+);
+MMRESULT WINAPI acmFilterChooseW(
+  PACMFILTERCHOOSEW pafltrc
+);
+MMRESULT WINAPI acmFilterDetailsA(
+  HACMDRIVER had, PACMFILTERDETAILSA pafd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmFilterDetailsW(
+  HACMDRIVER had, PACMFILTERDETAILSW pafd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmFilterEnumA(
+  HACMDRIVER had, PACMFILTERDETAILSA pafd, 
+  ACMFILTERENUMCBA fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT WINAPI acmFilterEnumW(
+  HACMDRIVER had, PACMFILTERDETAILSW pafd, 
+  ACMFILTERENUMCBW fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT WINAPI acmFilterTagDetailsA(
+  HACMDRIVER had, PACMFILTERTAGDETAILSA paftd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmFilterTagDetailsW(
+  HACMDRIVER had, PACMFILTERTAGDETAILSW paftd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmFilterTagEnumA(
+  HACMDRIVER had, PACMFILTERTAGDETAILSA paftd,
+  ACMFILTERTAGENUMCBA fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT WINAPI acmFilterTagEnumW(
+  HACMDRIVER had, PACMFILTERTAGDETAILSW paftd,
+  ACMFILTERTAGENUMCBW fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT WINAPI acmFormatChooseA(
+  PACMFORMATCHOOSEA pafmtc
+);
+MMRESULT WINAPI acmFormatChooseW(
+  PACMFORMATCHOOSEW pafmtc
+);
+MMRESULT WINAPI acmFormatDetailsA(
+  HACMDRIVER had, PACMFORMATDETAILSA pafd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmFormatDetailsW(
+  HACMDRIVER had, PACMFORMATDETAILSW pafd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmFormatEnumA(
+  HACMDRIVER had, PACMFORMATDETAILSA pafd,
+  ACMFORMATENUMCBA fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT WINAPI acmFormatEnumW(
+  HACMDRIVER had, PACMFORMATDETAILSW pafd,
+  ACMFORMATENUMCBW fnCallback, DWORD dwInstance,  DWORD fdwEnum
+);
+MMRESULT WINAPI acmFormatSuggest(
+  HACMDRIVER had, PWAVEFORMATEX pwfxSrc, PWAVEFORMATEX pwfxDst,
+  DWORD cbwfxDst, DWORD fdwSuggest
+);
+MMRESULT WINAPI acmFormatTagDetailsA(
+  HACMDRIVER had, PACMFORMATTAGDETAILSA paftd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmFormatTagDetailsW(
+  HACMDRIVER had, PACMFORMATTAGDETAILSW paftd, DWORD fdwDetails
+);
+MMRESULT WINAPI acmFormatTagEnumA(
+  HACMDRIVER had, PACMFORMATTAGDETAILSA paftd,
+  ACMFORMATTAGENUMCBA fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+MMRESULT WINAPI acmFormatTagEnumW(
+  HACMDRIVER had, PACMFORMATTAGDETAILSW paftd,
+  ACMFORMATTAGENUMCBW fnCallback, DWORD dwInstance, DWORD fdwEnum
+);
+DWORD WINAPI acmGetVersion(
+);
+MMRESULT WINAPI acmMetrics(
+  HACMOBJ hao, UINT  uMetric, LPVOID  pMetric
+);
+MMRESULT WINAPI acmStreamClose(
+  HACMSTREAM has, DWORD fdwClose
+);
+MMRESULT WINAPI acmStreamConvert(
+  HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwConvert
+);
+MMRESULT WINAPI acmStreamMessage(
+  HACMSTREAM has, UINT uMsg, LPARAM lParam1, LPARAM lParam2
+);
+MMRESULT WINAPI acmStreamOpen(
+  PHACMSTREAM phas, HACMDRIVER had, PWAVEFORMATEX pwfxSrc,
+  PWAVEFORMATEX pwfxDst, PWAVEFILTER pwfltr, DWORD dwCallback,
+  DWORD dwInstance, DWORD fdwOpen
+);
+MMRESULT WINAPI acmStreamPrepareHeader(
+  HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwPrepare
+);
+MMRESULT WINAPI acmStreamReset(
+  HACMSTREAM has, DWORD fdwReset
+);
+MMRESULT WINAPI acmStreamSize(
+  HACMSTREAM has, DWORD cbInput, 
+  LPDWORD pdwOutputBytes, DWORD fdwSize
+);
+MMRESULT WINAPI acmStreamUnprepareHeader(
+  HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwUnprepare
+);
+void MSACM_RegisterAllDrivers(void);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif /* defined(__cplusplus) */
+
+#endif  /* __WINE_MSACM_H */
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/msacmdrv.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,203 @@
+/*
+ *      msacmdrv.h   -       Declarations for MSACM driver
+ */
+
+#ifndef __WINE_MSACMDRV_H
+#define __WINE_MSACMDRV_H
+
+#include "windef.h"
+#include "msacm.h"
+
+/***********************************************************************
+ * Types
+ */
+
+/***********************************************************************
+ * Defines/Enums
+ */
+
+#define MAKE_ACM_VERSION(mjr, mnr, bld) \
+  (((long)(mjr)<<24) | ((long)(mnr)<<16) | ((long)bld))
+
+#define ACMDRVOPENDESC_SECTIONNAME_CHARS    
+
+#define ACMDM_DRIVER_NOTIFY             (ACMDM_BASE + 1)
+#define ACMDM_DRIVER_DETAILS            (ACMDM_BASE + 10)
+
+#define ACMDM_HARDWARE_WAVE_CAPS_INPUT  (ACMDM_BASE + 20)
+#define ACMDM_HARDWARE_WAVE_CAPS_OUTPUT (ACMDM_BASE + 21)
+
+#define ACMDM_FORMATTAG_DETAILS         (ACMDM_BASE + 25)
+#define ACMDM_FORMAT_DETAILS            (ACMDM_BASE + 26)
+#define ACMDM_FORMAT_SUGGEST            (ACMDM_BASE + 27)
+
+#define ACMDM_FILTERTAG_DETAILS         (ACMDM_BASE + 50)
+#define ACMDM_FILTER_DETAILS            (ACMDM_BASE + 51)
+
+#define ACMDM_STREAM_OPEN               (ACMDM_BASE + 76)
+#define ACMDM_STREAM_CLOSE              (ACMDM_BASE + 77)
+#define ACMDM_STREAM_SIZE               (ACMDM_BASE + 78)
+#define ACMDM_STREAM_CONVERT            (ACMDM_BASE + 79)
+#define ACMDM_STREAM_RESET              (ACMDM_BASE + 80)
+#define ACMDM_STREAM_PREPARE            (ACMDM_BASE + 81)
+#define ACMDM_STREAM_UNPREPARE          (ACMDM_BASE + 82)
+#define ACMDM_STREAM_UPDATE             (ACMDM_BASE + 83)
+
+/***********************************************************************
+ * Structures
+ */
+
+typedef struct _ACMDRVOPENDESCA
+{
+  DWORD  cbStruct;
+  FOURCC fccType;
+  FOURCC fccComp;
+  DWORD  dwVersion;
+  DWORD  dwFlags;
+  DWORD  dwError;
+  LPCSTR pszSectionName;
+  LPCSTR pszAliasName;
+  DWORD  dnDevNode;
+} ACMDRVOPENDESCA, *PACMDRVOPENDESCA;
+
+typedef struct _ACMDRVOPENDESCW
+{
+  DWORD   cbStruct;
+  FOURCC  fccType;
+  FOURCC  fccComp;
+  DWORD   dwVersion;
+  DWORD   dwFlags;
+  DWORD   dwError;
+  LPCWSTR pszSectionName;
+  LPCWSTR pszAliasName;
+  DWORD   dnDevNode;
+} ACMDRVOPENDESCW, *PACMDRVOPENDESCW;
+
+typedef struct _ACMDRVOPENDESC16
+{
+  DWORD  cbStruct;
+  FOURCC fccType;
+  FOURCC fccComp;
+  DWORD  dwVersion;
+  DWORD  dwFlags;
+  DWORD  dwError;
+  LPCSTR pszSectionName;
+  LPCSTR pszAliasName;
+  DWORD  dnDevNode;
+} ACMDRVOPENDESC16, *NPACMDRVOPENDESC16, *LPACMDRVOPENDESC16;
+
+typedef struct _ACMDRVSTREAMINSTANCE16
+{
+  DWORD            cbStruct;
+  LPWAVEFORMATEX   pwfxSrc;
+  LPWAVEFORMATEX   pwfxDst;
+  LPWAVEFILTER     pwfltr;
+  DWORD            dwCallback;
+  DWORD            dwInstance;
+  DWORD            fdwOpen;
+  DWORD            fdwDriver;
+  DWORD            dwDriver;
+  HACMSTREAM16     has;
+} ACMDRVSTREAMINSTANCE16, *NPACMDRVSTREAMINSTANCE16, *LPACMDRVSTREAMINSTANCE16;
+
+typedef struct _ACMDRVSTREAMINSTANCE
+{
+  DWORD           cbStruct;
+  PWAVEFORMATEX   pwfxSrc;
+  PWAVEFORMATEX   pwfxDst;
+  PWAVEFILTER     pwfltr;
+  DWORD           dwCallback;
+  DWORD           dwInstance;
+  DWORD           fdwOpen;
+  DWORD           fdwDriver;
+  DWORD           dwDriver;
+  HACMSTREAM    has;
+} ACMDRVSTREAMINSTANCE, *PACMDRVSTREAMINSTANCE;
+
+
+typedef struct _ACMDRVSTREAMHEADER16 *LPACMDRVSTREAMHEADER16;
+typedef struct _ACMDRVSTREAMHEADER16 {
+  DWORD  cbStruct;
+  DWORD  fdwStatus;
+  DWORD  dwUser;
+  LPBYTE pbSrc;
+  DWORD  cbSrcLength;
+  DWORD  cbSrcLengthUsed;
+  DWORD  dwSrcUser;
+  LPBYTE pbDst;
+  DWORD  cbDstLength;
+  DWORD  cbDstLengthUsed;
+  DWORD  dwDstUser;
+
+  DWORD fdwConvert;
+  LPACMDRVSTREAMHEADER16 *padshNext;
+  DWORD fdwDriver;
+  DWORD dwDriver;
+
+  /* Internal fields for ACM */
+  DWORD  fdwPrepared;
+  DWORD  dwPrepared;
+  LPBYTE pbPreparedSrc;
+  DWORD  cbPreparedSrcLength;
+  LPBYTE pbPreparedDst;
+  DWORD  cbPreparedDstLength;
+} ACMDRVSTREAMHEADER16, *NPACMDRVSTREAMHEADER16;
+
+typedef struct _ACMDRVSTREAMHEADER *PACMDRVSTREAMHEADER;
+typedef struct _ACMDRVSTREAMHEADER {
+  DWORD  cbStruct;
+  DWORD  fdwStatus;
+  DWORD  dwUser;
+  LPBYTE pbSrc;
+  DWORD  cbSrcLength;
+  DWORD  cbSrcLengthUsed;
+  DWORD  dwSrcUser;
+  LPBYTE pbDst;
+  DWORD  cbDstLength;
+  DWORD  cbDstLengthUsed;
+  DWORD  dwDstUser;
+
+  DWORD fdwConvert;
+  PACMDRVSTREAMHEADER *padshNext;
+  DWORD fdwDriver;
+  DWORD dwDriver;
+
+  /* Internal fields for ACM */
+  DWORD  fdwPrepared;
+  DWORD  dwPrepared;
+  LPBYTE pbPreparedSrc;
+  DWORD  cbPreparedSrcLength;
+  LPBYTE pbPreparedDst;
+  DWORD  cbPreparedDstLength;
+} ACMDRVSTREAMHEADER;
+
+typedef struct _ACMDRVSTREAMSIZE
+{
+  DWORD cbStruct;
+  DWORD fdwSize;
+  DWORD cbSrcLength;
+  DWORD cbDstLength;
+} ACMDRVSTREAMSIZE16, *NPACMDRVSTREAMSIZE16, *LPACMDRVSTREAMSIZE16,
+  ACMDRVSTREAMSIZE, *PACMDRVSTREAMSIZE;
+
+typedef struct _ACMDRVFORMATSUGGEST16
+{
+  DWORD            cbStruct;
+  DWORD            fdwSuggest;
+  LPWAVEFORMATEX   pwfxSrc;
+  DWORD            cbwfxSrc;
+  LPWAVEFORMATEX   pwfxDst;
+  DWORD            cbwfxDst;
+} ACMDRVFORMATSUGGEST16, *NPACMDRVFORMATSUGGEST, *LPACMDRVFORMATSUGGEST;
+
+typedef struct _ACMDRVFORMATSUGGEST
+{
+  DWORD           cbStruct;
+  DWORD           fdwSuggest;
+  PWAVEFORMATEX   pwfxSrc;
+  DWORD           cbwfxSrc;
+  PWAVEFORMATEX   pwfxDst;
+  DWORD           cbwfxDst;
+} ACMDRVFORMATSUGGEST, *PACMDRVFORMATSUGGEST;
+
+#endif  /* __WINE_MSACMDRV_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/ntdef.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,101 @@
+#ifndef __WINE_NTDEF_H
+#define __WINE_NTDEF_H
+
+#include "basetsd.h"
+#include "windef.h"
+
+#include "pshpack1.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NTAPI   __stdcall 
+
+#ifndef IN
+#define IN
+#endif
+
+#ifndef OUT
+#define OUT
+#endif
+
+#ifndef OPTIONAL
+#define OPTIONAL
+#endif
+
+#ifndef VOID
+#define VOID void
+#endif
+
+typedef LONG NTSTATUS;
+typedef NTSTATUS *PNTSTATUS;
+
+typedef short CSHORT;
+typedef CSHORT *PCSHORT;  
+
+typedef WCHAR * PWCHAR;
+
+/* NT lowlevel Strings (handled by Rtl* functions in NTDLL)
+ * If they are zero terminated, Length does not include the terminating 0.
+ */
+
+typedef struct _STRING {
+	USHORT	Length;
+	USHORT	MaximumLength;
+	PSTR	Buffer;
+} STRING,*PSTRING,ANSI_STRING,*PANSI_STRING;
+
+typedef struct _CSTRING {
+	USHORT	Length;
+	USHORT	MaximumLength;
+	PCSTR	Buffer;
+} CSTRING,*PCSTRING;
+
+typedef struct _UNICODE_STRING {
+	USHORT	Length;		/* bytes */
+	USHORT	MaximumLength;	/* bytes */
+	PWSTR	Buffer;
+} UNICODE_STRING,*PUNICODE_STRING;
+
+/*
+	Objects
+*/
+
+#define OBJ_INHERIT             0x00000002L
+#define OBJ_PERMANENT           0x00000010L
+#define OBJ_EXCLUSIVE           0x00000020L
+#define OBJ_CASE_INSENSITIVE    0x00000040L
+#define OBJ_OPENIF              0x00000080L
+#define OBJ_OPENLINK            0x00000100L
+#define OBJ_KERNEL_HANDLE       0x00000200L
+#define OBJ_VALID_ATTRIBUTES    0x000003F2L
+
+typedef struct _OBJECT_ATTRIBUTES 
+{   ULONG Length;
+    HANDLE RootDirectory;
+    PUNICODE_STRING ObjectName;
+    ULONG Attributes;
+    PVOID SecurityDescriptor;        /* type SECURITY_DESCRIPTOR */
+    PVOID SecurityQualityOfService;  /* type SECURITY_QUALITY_OF_SERVICE */
+} OBJECT_ATTRIBUTES;
+
+typedef OBJECT_ATTRIBUTES *POBJECT_ATTRIBUTES;
+
+#define InitializeObjectAttributes(p,n,a,r,s) \
+{	(p)->Length = sizeof(OBJECT_ATTRIBUTES); \
+	(p)->RootDirectory = r; \
+	(p)->Attributes = a; \
+	(p)->ObjectName = n; \
+	(p)->SecurityDescriptor = s; \
+	(p)->SecurityQualityOfService = NULL; \
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#include "poppack.h"
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/pe_image.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,81 @@
+#ifndef __WINE_PE_IMAGE_H
+#define __WINE_PE_IMAGE_H
+
+#include "windef.h"
+#include "winbase.h"
+
+#define PE_HEADER(module) \
+    ((IMAGE_NT_HEADERS*)((LPBYTE)(module) + \
+                         (((IMAGE_DOS_HEADER*)(module))->e_lfanew)))
+
+#define PE_SECTIONS(module) \
+    ((IMAGE_SECTION_HEADER*)((LPBYTE)&PE_HEADER(module)->OptionalHeader + \
+                           PE_HEADER(module)->FileHeader.SizeOfOptionalHeader))
+
+#define RVA_PTR(module,field) ((LPBYTE)(module) + PE_HEADER(module)->field)
+
+/* modreference used for attached processes
+ * all section are calculated here, relocations etc.
+ */
+typedef struct {
+	PIMAGE_IMPORT_DESCRIPTOR	pe_import;
+	PIMAGE_EXPORT_DIRECTORY	pe_export;
+	PIMAGE_RESOURCE_DIRECTORY	pe_resource;
+	int				tlsindex;
+} PE_MODREF;
+
+struct _wine_modref;
+extern int PE_unloadImage(HMODULE hModule);
+extern FARPROC PE_FindExportedFunction(struct _wine_modref *wm, LPCSTR funcName, WIN_BOOL snoop);
+extern WIN_BOOL PE_EnumResourceTypesA(HMODULE,ENUMRESTYPEPROCA,LONG);
+extern WIN_BOOL PE_EnumResourceTypesW(HMODULE,ENUMRESTYPEPROCW,LONG);
+extern WIN_BOOL PE_EnumResourceNamesA(HMODULE,LPCSTR,ENUMRESNAMEPROCA,LONG);
+extern WIN_BOOL PE_EnumResourceNamesW(HMODULE,LPCWSTR,ENUMRESNAMEPROCW,LONG);
+extern WIN_BOOL PE_EnumResourceLanguagesA(HMODULE,LPCSTR,LPCSTR,ENUMRESLANGPROCA,LONG);
+extern WIN_BOOL PE_EnumResourceLanguagesW(HMODULE,LPCWSTR,LPCWSTR,ENUMRESLANGPROCW,LONG);
+extern HRSRC PE_FindResourceExW(struct _wine_modref*,LPCWSTR,LPCWSTR,WORD);
+extern DWORD PE_SizeofResource(HMODULE,HRSRC);
+extern struct _wine_modref *PE_LoadLibraryExA(LPCSTR, DWORD);
+extern void PE_UnloadLibrary(struct _wine_modref *);
+extern HGLOBAL PE_LoadResource(struct _wine_modref *wm,HRSRC);
+extern HMODULE PE_LoadImage( int hFile, LPCSTR filename, WORD *version );
+extern struct _wine_modref *PE_CreateModule( HMODULE hModule, LPCSTR filename,
+                                             DWORD flags, WIN_BOOL builtin );
+extern WIN_BOOL PE_CreateProcess( HANDLE hFile, LPCSTR filename, LPCSTR cmd_line, LPCSTR env, 
+                              LPSECURITY_ATTRIBUTES psa, LPSECURITY_ATTRIBUTES tsa,
+                              WIN_BOOL inherit, DWORD flags, LPSTARTUPINFOA startup,
+                              LPPROCESS_INFORMATION info );
+
+extern void PE_InitTls(void);
+extern WIN_BOOL PE_InitDLL(struct _wine_modref *wm, DWORD type, LPVOID lpReserved);
+
+extern PIMAGE_RESOURCE_DIRECTORY GetResDirEntryA(PIMAGE_RESOURCE_DIRECTORY,LPCSTR,DWORD,WIN_BOOL);
+extern PIMAGE_RESOURCE_DIRECTORY GetResDirEntryW(PIMAGE_RESOURCE_DIRECTORY,LPCWSTR,DWORD,WIN_BOOL);
+
+typedef DWORD CALLBACK (*DLLENTRYPROC)(HMODULE,DWORD,LPVOID);
+
+typedef struct {
+	WORD	popl	WINE_PACKED;	/* 0x8f 0x05 */
+	DWORD	addr_popped WINE_PACKED;/* ...  */
+	BYTE	pushl1	WINE_PACKED;	/* 0x68 */
+	DWORD	newret WINE_PACKED;	/* ...  */
+	BYTE	pushl2 	WINE_PACKED;	/* 0x68 */
+	DWORD	origfun WINE_PACKED;	/* original function */
+	BYTE	ret1	WINE_PACKED;	/* 0xc3 */
+	WORD	addesp 	WINE_PACKED;	/* 0x83 0xc4 */
+	BYTE	nrofargs WINE_PACKED;	/* nr of arguments to add esp, */
+	BYTE	pushl3	WINE_PACKED;	/* 0x68 */
+	DWORD	oldret	WINE_PACKED;	/* Filled out from popl above  */
+	BYTE	ret2	WINE_PACKED;	/* 0xc3 */
+} ELF_STDCALL_STUB;
+
+typedef struct {
+	void*			dlhandle;
+	ELF_STDCALL_STUB	*stubs;
+} ELF_MODREF;
+
+extern struct _wine_modref *ELF_LoadLibraryExA( LPCSTR libname, DWORD flags);
+extern void ELF_UnloadLibrary(struct _wine_modref *);
+extern FARPROC ELF_FindExportedFunction(struct _wine_modref *wm, LPCSTR funcName);
+
+#endif /* __WINE_PE_IMAGE_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/poppack.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,15 @@
+#ifdef __WINE_PSHPACK_H
+#undef __WINE_PSHPACK_H
+
+#if defined(__GNUC__) || defined(__SUNPRO_C)
+#pragma pack()
+#elif defined(__SUNPRO_CC)
+#warning "Assumes default alignment is 4"
+#pragma pack(4)
+#elif !defined(RC_INVOKED)
+#error "Restoration of the previous alignment isn't supported by the compiler"
+#endif /* defined(__GNUC__) || defined(__SUNPRO_C) ; !defined(RC_INVOKED) */
+
+#else /* defined(__WINE_PSHPACK_H) */
+#error "Popping alignment isn't possible since no alignment has been pushed"
+#endif /* defined(__WINE_PSHPACK_H) */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/pshpack1.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,13 @@
+#ifndef __WINE_PSHPACK_H
+#define __WINE_PSHPACK_H 1
+
+#if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+//#pragma pack(1)
+#elif !defined(RC_INVOKED)
+#error "1 as alignment isn't supported by the compiler"
+#endif /* defined(__GNUC__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) ; !defined(RC_INVOKED) */
+
+#else /* !defined(__WINE_PSHPACK_H) */
+#error "Nested pushing of alignment isn't supported by the compiler"
+#endif /* !defined(__WINE_PSHPACK_H) */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/pshpack2.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,12 @@
+#ifndef __WINE_PSHPACK_H
+#define __WINE_PSHPACK_H 2
+
+#if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+//#pragma pack(2)
+#elif !defined(RC_INVOKED)
+#error "2 as alignment isn't supported by the compiler"
+#endif /* defined(__GNUC__) || defined(__SUNPRO_CC) ; !defined(RC_INVOKED) */
+
+#else /* !defined(__WINE_PSHPACK_H) */
+#error "Nested pushing of alignment isn't supported by the compiler"
+#endif /* !defined(__WINE_PSHPACK_H) */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/pshpack4.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,15 @@
+#ifndef __WINE_PSHPACK_H
+#define __WINE_PSHPACK_H 4
+
+#if defined(__GNUC__) || defined(__SUNPRO_CC)
+//#pragma pack(4)
+#elif defined(__SUNPRO_C)
+//#pragma pack()
+#elif !defined(RC_INVOKED)
+#error "4 as alignment isn't supported by the compiler"
+#endif /* defined(__GNUC__) || defined(__SUNPRO_CC) ; !defined(RC_INVOKED) */
+
+#else /* !defined(__WINE_PSHPACK_H) */
+#error "Nested pushing of alignment isn't supported by the compiler"
+#endif /* !defined(__WINE_PSHPACK_H) */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/pshpack8.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,12 @@
+#ifndef __WINE_PSHPACK_H
+#define __WINE_PSHPACK_H 8
+
+#if 0
+//#pragma pack(8)
+#elif !defined(RC_INVOKED)
+#error "8 as alignment is not supported"
+#endif /* 0 ; !defined(RC_INVOKED) */
+
+#else /* !defined(__WINE_PSHPACK_H) */
+#error "Nested pushing of alignment isn't supported by the compiler"
+#endif /* !defined(__WINE_PSHPACK_H) */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/vfw.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,654 @@
+#ifndef __WINE_VFW_H
+#define __WINE_VFW_H
+//#include "pshpack1.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifndef __WINE_WINGDI_H
+
+typedef struct
+{
+    short    bfType;
+    long   bfSize;
+    short    bfReserved1;
+    short    bfReserved2;
+    long   bfOffBits;
+} BITMAPFILEHEADER;
+
+typedef struct
+{
+    long 	biSize;
+    long  	biWidth;
+    long  	biHeight;
+    short 	biPlanes;
+    short 	biBitCount;
+    long 	biCompression;
+    long 	biSizeImage;
+    long  	biXPelsPerMeter;
+    long  	biYPelsPerMeter;
+    long 	biClrUsed;
+    long 	biClrImportant;
+} BITMAPINFOHEADER, *PBITMAPINFOHEADER, *LPBITMAPINFOHEADER;
+typedef struct {
+	BITMAPINFOHEADER bmiHeader;
+	int	bmiColors[1];
+} BITMAPINFO, *LPBITMAPINFO;
+#endif
+#define VFWAPI	
+#define VFWAPIV	
+#ifndef __WINE_WINDEF_H
+typedef long (__stdcall__ *DRIVERPROC)(long,HDRVR,unsigned int,long,long);
+#endif
+
+
+
+#ifndef mmioFOURCC
+#define mmioFOURCC( ch0, ch1, ch2, ch3 )				\
+	( (long)(unsigned char)(ch0) | ( (long)(unsigned char)(ch1) << 8 ) |		\
+	( (long)(unsigned char)(ch2) << 16 ) | ( (long)(unsigned char)(ch3) << 24 ) )
+#endif
+
+#ifndef aviTWOCC
+#define aviTWOCC(ch0, ch1) ((short)(unsigned char)(ch0) | ((short)(unsigned char)(ch1) << 8))
+#endif
+
+#define ICTYPE_VIDEO	mmioFOURCC('v', 'i', 'd', 'c')
+#define ICTYPE_AUDIO	mmioFOURCC('a', 'u', 'd', 'c')
+
+
+/* Installable Compressor M? */
+
+/* HIC struct (same layout as Win95 one) */
+typedef struct tagWINE_HIC {
+	long		magic;		/* 00: 'Smag' */
+	HANDLE	curthread;	/* 04: */
+	long		type;		/* 08: */
+	long		handler;	/* 0C: */
+	HDRVR		hdrv;		/* 10: */
+#ifndef __cplusplus
+	long		private;	/* 14:(handled by SendDriverMessage)*/
+#else	
+	long		_private;	/* 14:(handled by SendDriverMessage)*/
+#endif	
+	DRIVERPROC	driverproc;	/* 18:(handled by SendDriverMessage)*/
+	long		x1;		/* 1c: name? */
+	short		x2;		/* 20: */
+	long		x3;		/* 22: */
+					/* 26: */
+} WINE_HIC;
+
+/* error return codes */
+#define	ICERR_OK		0
+#define	ICERR_DONTDRAW		1
+#define	ICERR_NEWPALETTE	2
+#define	ICERR_GOTOKEYFRAME	3
+#define	ICERR_STOPDRAWING	4
+
+#define	ICERR_UNSUPPORTED	-1
+#define	ICERR_BADFORMAT		-2
+#define	ICERR_MEMORY		-3
+#define	ICERR_INTERNAL		-4
+#define	ICERR_BADFLAGS		-5
+#define	ICERR_BADPARAM		-6
+#define	ICERR_BADSIZE		-7
+#define	ICERR_BADHANDLE		-8
+#define	ICERR_CANTUPDATE	-9
+#define	ICERR_ABORT		-10
+#define	ICERR_ERROR		-100
+#define	ICERR_BADBITDEPTH	-200
+#define	ICERR_BADIMAGESIZE	-201
+
+#define	ICERR_CUSTOM		-400
+
+/* ICM Messages */
+#define	ICM_USER		(DRV_USER+0x0000)
+
+/* ICM driver message range */
+#define	ICM_RESERVED_LOW	(DRV_USER+0x1000)
+#define	ICM_RESERVED_HIGH	(DRV_USER+0x2000)
+#define	ICM_RESERVED		ICM_RESERVED_LOW
+
+#define	ICM_GETSTATE		(ICM_RESERVED+0)
+#define	ICM_SETSTATE		(ICM_RESERVED+1)
+#define	ICM_GETINFO		(ICM_RESERVED+2)
+
+#define	ICM_CONFIGURE		(ICM_RESERVED+10)
+#define	ICM_ABOUT		(ICM_RESERVED+11)
+/* */
+
+#define	ICM_GETDEFAULTQUALITY	(ICM_RESERVED+30)
+#define	ICM_GETQUALITY		(ICM_RESERVED+31)
+#define	ICM_SETQUALITY		(ICM_RESERVED+32)
+
+#define	ICM_SET			(ICM_RESERVED+40)
+#define	ICM_GET			(ICM_RESERVED+41)
+
+/* 2 constant FOURCC codes */
+#define ICM_FRAMERATE		mmioFOURCC('F','r','m','R')
+#define ICM_KEYFRAMERATE	mmioFOURCC('K','e','y','R')
+
+#define	ICM_COMPRESS_GET_FORMAT		(ICM_USER+4)
+#define	ICM_COMPRESS_GET_SIZE		(ICM_USER+5)
+#define	ICM_COMPRESS_QUERY		(ICM_USER+6)
+#define	ICM_COMPRESS_BEGIN		(ICM_USER+7)
+#define	ICM_COMPRESS			(ICM_USER+8)
+#define	ICM_COMPRESS_END		(ICM_USER+9)
+
+#define	ICM_DECOMPRESS_GET_FORMAT	(ICM_USER+10)
+#define	ICM_DECOMPRESS_QUERY		(ICM_USER+11)
+#define	ICM_DECOMPRESS_BEGIN		(ICM_USER+12)
+#define	ICM_DECOMPRESS			(ICM_USER+13)
+#define	ICM_DECOMPRESS_END		(ICM_USER+14)
+#define	ICM_DECOMPRESS_SET_PALETTE	(ICM_USER+29)
+#define	ICM_DECOMPRESS_GET_PALETTE	(ICM_USER+30)
+
+#define	ICM_DRAW_QUERY			(ICM_USER+31)
+#define	ICM_DRAW_BEGIN			(ICM_USER+15)
+#define	ICM_DRAW_GET_PALETTE		(ICM_USER+16)
+#define	ICM_DRAW_START			(ICM_USER+18)
+#define	ICM_DRAW_STOP			(ICM_USER+19)
+#define	ICM_DRAW_END			(ICM_USER+21)
+#define	ICM_DRAW_GETTIME		(ICM_USER+32)
+#define	ICM_DRAW			(ICM_USER+33)
+#define	ICM_DRAW_WINDOW			(ICM_USER+34)
+#define	ICM_DRAW_SETTIME		(ICM_USER+35)
+#define	ICM_DRAW_REALIZE		(ICM_USER+36)
+#define	ICM_DRAW_FLUSH			(ICM_USER+37)
+#define	ICM_DRAW_RENDERBUFFER		(ICM_USER+38)
+
+#define	ICM_DRAW_START_PLAY		(ICM_USER+39)
+#define	ICM_DRAW_STOP_PLAY		(ICM_USER+40)
+
+#define	ICM_DRAW_SUGGESTFORMAT		(ICM_USER+50)
+#define	ICM_DRAW_CHANGEPALETTE		(ICM_USER+51)
+
+#define	ICM_GETBUFFERSWANTED		(ICM_USER+41)
+
+#define	ICM_GETDEFAULTKEYFRAMERATE	(ICM_USER+42)
+
+#define	ICM_DECOMPRESSEX_BEGIN		(ICM_USER+60)
+#define	ICM_DECOMPRESSEX_QUERY		(ICM_USER+61)
+#define	ICM_DECOMPRESSEX		(ICM_USER+62)
+#define	ICM_DECOMPRESSEX_END		(ICM_USER+63)
+
+#define	ICM_COMPRESS_FRAMES_INFO	(ICM_USER+70)
+#define	ICM_SET_STATUS_PROC		(ICM_USER+72)
+
+/* structs */
+
+typedef struct {
+	long	dwSize;		/* 00: size */
+	long	fccType;	/* 04: type 'vidc' usually */
+	long	fccHandler;	/* 08: */
+	long	dwVersion;	/* 0c: version of compman opening you */
+	long	dwFlags;	/* 10: LOshort is type specific */
+	LRESULT	dwError;	/* 14: */
+	void*	pV1Reserved;	/* 18: */
+	void*	pV2Reserved;	/* 1c: */
+	long	dnDevNode;	/* 20: */
+				/* 24: */
+} ICOPEN,*LPICOPEN;
+
+#define ICCOMPRESS_KEYFRAME     0x00000001L
+
+typedef struct {
+    long		dwFlags;
+    LPBITMAPINFOHEADER	lpbiOutput;
+    void*		lpOutput;
+    LPBITMAPINFOHEADER	lpbiInput;
+    void*		lpInput;
+    long*		lpckid;
+    long*		lpdwFlags;
+    long		lFrameNum;
+    long		dwFrameSize;
+    long		dwQuality;
+    LPBITMAPINFOHEADER	lpbiPrev;
+    void*		lpPrev;
+} ICCOMPRESS;
+
+long VFWAPIV ICCompress(
+	HIC hic,long dwFlags,LPBITMAPINFOHEADER lpbiOutput,void* lpData,
+	LPBITMAPINFOHEADER lpbiInput,void* lpBits,long* lpckid,
+	long* lpdwFlags,long lFrameNum,long dwFrameSize,long dwQuality,
+	LPBITMAPINFOHEADER lpbiPrev,void* lpPrev
+);
+
+
+#define ICCompressGetFormat(hic, lpbiInput, lpbiOutput) 		\
+	ICSendMessage(							\
+	    hic,ICM_COMPRESS_GET_FORMAT,(long)(void*)(lpbiInput),	\
+	    (long)(void*)(lpbiOutput)					\
+	)
+
+#define ICCompressGetFormatSize(hic,lpbi) ICCompressGetFormat(hic,lpbi,NULL)
+
+#define ICGetDefaultKeyFrameRate(hic,lpint) 		\
+	ICSendMessage(					\
+	    hic, ICM_GETDEFAULTKEYFRAMERATE,		\
+	    (long)(void*)(lpint), 			\
+	    0	)		
+
+#define ICGetDefaultQuality(hic,lpint) 			\
+	ICSendMessage(					\
+	    hic, ICM_GETDEFAULTQUALITY,			\
+	    (long)(void*)(lpint), 			\
+	    0	)		
+	    	
+
+#define ICCompressBegin(hic, lpbiInput, lpbiOutput) 			\
+    ICSendMessage(							\
+    	hic, ICM_COMPRESS_BEGIN, (long)(void*)(lpbiInput),		\
+	(long)(void*)(lpbiOutput)					\
+    )
+
+#define ICCompressGetSize(hic, lpbiInput, lpbiOutput) 		\
+    ICSendMessage(							\
+    	hic, ICM_COMPRESS_GET_SIZE, (long)(void*)(lpbiInput), 	\
+	(long)(void*)(lpbiOutput)					\
+    )
+
+#define ICCompressQuery(hic, lpbiInput, lpbiOutput)		\
+    ICSendMessage(						\
+    	hic, ICM_COMPRESS_QUERY, (long)(void*)(lpbiInput),	\
+	(long)(void*)(lpbiOutput)				\
+    )
+
+
+#define ICCompressEnd(hic) ICSendMessage(hic, ICM_COMPRESS_END, 0, 0)
+
+/* ICCOMPRESSFRAMES.dwFlags */
+#define ICCOMPRESSFRAMES_PADDING        0x00000001
+typedef struct {
+    long               dwFlags;
+    LPBITMAPINFOHEADER  lpbiOutput;
+    LPARAM              lOutput;
+    LPBITMAPINFOHEADER  lpbiInput;
+    LPARAM              lInput;
+    long                lStartFrame;
+    long                lFrameCount;
+    long                lQuality;
+    long                lDataRate;
+    long                lKeyRate;
+    long               dwRate;
+    long               dwScale;
+    long               dwOverheadPerFrame;
+    long               dwReserved2;
+    long CALLBACK (*GetData)(LPARAM lInput,long lFrame,void* lpBits,long len);
+    long CALLBACK (*PutData)(LPARAM lOutput,long lFrame,void* lpBits,long len);
+} ICCOMPRESSFRAMES;
+
+/* Values for wMode of ICOpen() */
+#define	ICMODE_COMPRESS		1
+#define	ICMODE_DECOMPRESS	2
+#define	ICMODE_FASTDECOMPRESS	3
+#define	ICMODE_QUERY		4
+#define	ICMODE_FASTCOMPRESS	5
+#define	ICMODE_DRAW		8
+
+/* quality flags */
+#define ICQUALITY_LOW       0
+#define ICQUALITY_HIGH      10000
+#define ICQUALITY_DEFAULT   -1
+
+typedef struct {
+	long	dwSize;		/* 00: */
+	long	fccType;	/* 04:compressor type     'vidc' 'audc' */
+	long	fccHandler;	/* 08:compressor sub-type 'rle ' 'jpeg' 'pcm '*/
+	long	dwFlags;	/* 0c:flags LOshort is type specific */
+	long	dwVersion;	/* 10:version of the driver */
+	long	dwVersionICM;	/* 14:version of the ICM used */
+	/*
+	 * under Win32, the driver always returns UNICODE strings.
+	 */
+	WCHAR	szName[16];		/* 18:short name */
+	WCHAR	szDescription[128];	/* 38:long name */
+	WCHAR	szDriver[128];		/* 138:driver that contains compressor*/
+					/* 238: */
+} ICINFO;
+
+/* ICINFO.dwFlags */
+#define	VIDCF_QUALITY		0x0001  /* supports quality */
+#define	VIDCF_CRUNCH		0x0002  /* supports crunching to a frame size */
+#define	VIDCF_TEMPORAL		0x0004  /* supports inter-frame compress */
+#define	VIDCF_COMPRESSFRAMES	0x0008  /* wants the compress all frames message */
+#define	VIDCF_DRAW		0x0010  /* supports drawing */
+#define	VIDCF_FASTTEMPORALC	0x0020  /* does not need prev frame on compress */
+#define	VIDCF_FASTTEMPORALD	0x0080  /* does not need prev frame on decompress */
+#define	VIDCF_QUALITYTIME	0x0040  /* supports temporal quality */
+
+#define	VIDCF_FASTTEMPORAL	(VIDCF_FASTTEMPORALC|VIDCF_FASTTEMPORALD)
+
+
+/* function shortcuts */
+/* ICM_ABOUT */
+#define ICMF_ABOUT_QUERY         0x00000001
+
+#define ICQueryAbout(hic) \
+	(ICSendMessage(hic,ICM_ABOUT,(long)-1,ICMF_ABOUT_QUERY)==ICERR_OK)
+
+#define ICAbout(hic, hwnd) ICSendMessage(hic,ICM_ABOUT,(long)(unsigned int)(hwnd),0)
+
+/* ICM_CONFIGURE */
+#define ICMF_CONFIGURE_QUERY	0x00000001
+#define ICQueryConfigure(hic) \
+	(ICSendMessage(hic,ICM_CONFIGURE,(long)-1,ICMF_CONFIGURE_QUERY)==ICERR_OK)
+
+#define ICConfigure(hic,hwnd) \
+	ICSendMessage(hic,ICM_CONFIGURE,(long)(unsigned int)(hwnd),0)
+
+/* Decompression stuff */
+#define ICDECOMPRESS_HURRYUP		0x80000000	/* don't draw just buffer (hurry up!) */
+#define ICDECOMPRESS_UPDATE		0x40000000	/* don't draw just update screen */
+#define ICDECOMPRESS_PREROL		0x20000000	/* this frame is before real start */
+#define ICDECOMPRESS_NULLFRAME		0x10000000	/* repeat last frame */
+#define ICDECOMPRESS_NOTKEYFRAME	0x08000000	/* this frame is not a key frame */
+
+typedef struct {
+    long		dwFlags;	/* flags (from AVI index...) */
+    LPBITMAPINFOHEADER	lpbiInput;	/* BITMAPINFO of compressed data */
+    void*		lpInput;	/* compressed data */
+    LPBITMAPINFOHEADER	lpbiOutput;	/* DIB to decompress to */
+    void*		lpOutput;
+    long		ckid;		/* ckid from AVI file */
+} ICDECOMPRESS;
+
+typedef struct {
+    long		dwFlags;
+    LPBITMAPINFOHEADER	lpbiSrc;
+    void*		lpSrc;
+    LPBITMAPINFOHEADER	lpbiDst;
+    void*		lpDst;
+
+    /* changed for ICM_DECOMPRESSEX */
+    INT		xDst;       /* destination rectangle */
+    INT		yDst;
+    INT		dxDst;
+    INT		dyDst;
+
+    INT		xSrc;       /* source rectangle */
+    INT		ySrc;
+    INT		dxSrc;
+    INT		dySrc;
+} ICDECOMPRESSEX;
+
+
+long VFWAPIV ICDecompress(HIC hic,long dwFlags,LPBITMAPINFOHEADER lpbiFormat,void* lpData,LPBITMAPINFOHEADER lpbi,void* lpBits);
+
+
+#define ICDecompressBegin(hic, lpbiInput, lpbiOutput) 	\
+    ICSendMessage(						\
+    	hic, ICM_DECOMPRESS_BEGIN, (long)(void*)(lpbiInput),	\
+	(long)(void*)(lpbiOutput)				\
+    )
+
+#define ICDecompressQuery(hic, lpbiInput, lpbiOutput) 	\
+    ICSendMessage(						\
+    	hic,ICM_DECOMPRESS_QUERY, (long)(void*)(lpbiInput),	\
+	(long) (void*)(lpbiOutput)				\
+    )
+
+#define ICDecompressGetFormat(hic, lpbiInput, lpbiOutput)		\
+    ((long)ICSendMessage(						\
+    	hic,ICM_DECOMPRESS_GET_FORMAT, (long)(void*)(lpbiInput),	\
+	(long)(void*)(lpbiOutput)					\
+    ))
+
+#define ICDecompressGetFormatSize(hic, lpbi) 				\
+	ICDecompressGetFormat(hic, lpbi, NULL)
+
+#define ICDecompressGetPalette(hic, lpbiInput, lpbiOutput)		\
+    ICSendMessage(							\
+    	hic, ICM_DECOMPRESS_GET_PALETTE, (long)(void*)(lpbiInput), 	\
+	(long)(void*)(lpbiOutput)					\
+    )
+
+#define ICDecompressSetPalette(hic,lpbiPalette)	\
+        ICSendMessage(				\
+		hic,ICM_DECOMPRESS_SET_PALETTE,		\
+		(long)(void*)(lpbiPalette),0		\
+	)
+
+#define ICDecompressEnd(hic) ICSendMessage(hic, ICM_DECOMPRESS_END, 0, 0)
+
+
+#define ICDRAW_QUERY        0x00000001L   /* test for support */
+#define ICDRAW_FULLSCREEN   0x00000002L   /* draw to full screen */
+#define ICDRAW_HDC          0x00000004L   /* draw to a HDC/HWND */
+
+
+WIN_BOOL	VFWAPI	ICInfo(long fccType, long fccHandler, ICINFO * lpicinfo);
+LRESULT	VFWAPI	ICGetInfo(HIC hic,ICINFO *picinfo, long cb);
+HIC	VFWAPI	ICOpen(long fccType, long fccHandler, UINT wMode);
+HIC	VFWAPI	ICOpenFunction(long fccType, long fccHandler, unsigned int wMode, void* lpfnHandler);
+
+LRESULT VFWAPI ICClose(HIC hic);
+LRESULT	VFWAPI ICSendMessage(HIC hic, unsigned int msg, long dw1, long dw2);
+HIC	VFWAPI ICLocate(long fccType, long fccHandler, LPBITMAPINFOHEADER lpbiIn, LPBITMAPINFOHEADER lpbiOut, short wFlags);
+
+int VFWAPI ICDoSomething();
+
+long	VFWAPIV	ICDrawBegin(
+        HIC			hic,
+        long			dwFlags,/* flags */
+        HPALETTE		hpal,	/* palette to draw with */
+        HWND			hwnd,	/* window to draw to */
+        HDC			hdc,	/* HDC to draw to */
+        INT			xDst,	/* destination rectangle */
+        INT			yDst,
+        INT			dxDst,
+        INT			dyDst,
+        LPBITMAPINFOHEADER	lpbi,	/* format of frame to draw */
+        INT			xSrc,	/* source rectangle */
+        INT			ySrc,
+        INT			dxSrc,
+        INT			dySrc,
+        long			dwRate,	/* frames/second = (dwRate/dwScale) */
+        long			dwScale
+);
+
+/* as passed to ICM_DRAW_BEGIN (FIXME: correct only for Win32?)  */
+typedef struct {
+	long		dwFlags;
+	HPALETTE	hpal;
+	HWND		hwnd;
+	HDC		hdc;
+	INT		xDst;
+	INT		yDst;
+	INT		dxDst;
+	INT		dyDst;
+	LPBITMAPINFOHEADER	lpbi;
+	INT		xSrc;
+	INT		ySrc;
+	INT		dxSrc;
+	INT		dySrc;
+	long		dwRate;
+	long		dwScale;
+} ICDRAWBEGIN;
+
+#define ICDRAW_HURRYUP      0x80000000L   /* don't draw just buffer (hurry up!) */
+#define ICDRAW_UPDATE       0x40000000L   /* don't draw just update screen */
+#define ICDRAW_PREROLL      0x20000000L   /* this frame is before real start */
+#define ICDRAW_NULLFRAME    0x10000000L   /* repeat last frame */
+#define ICDRAW_NOTKEYFRAME  0x08000000L   /* this frame is not a key frame */
+
+typedef struct {
+	long	dwFlags;
+	void*	lpFormat;
+	void*	lpData;
+	long	cbData;
+	long	lTime;
+} ICDRAW;
+
+long VFWAPIV ICDraw(HIC hic,long dwFlags,void* lpFormat,void* lpData,long cbData,long lTime);
+
+
+#define	AVIGETFRAMEF_BESTDISPLAYFMT	1
+
+typedef struct _AVISTREAMINFOA {
+    long	fccType;
+    long	fccHandler;
+    long	dwFlags;        /* AVIIF_* */
+    long	dwCaps;
+    short	wPriority;
+    short	wLanguage;
+    long	dwScale;
+    long	dwRate;		/* dwRate / dwScale == samples/second */
+    long	dwStart;
+    long	dwLength;	/* In units above... */
+    long	dwInitialFrames;
+    long	dwSuggestedBufferSize;
+    long	dwQuality;
+    long	dwSampleSize;
+    RECT	rcFrame;
+    long	dwEditCount;
+    long	dwFormatChangeCount;
+    char	szName[64];
+} AVISTREAMINFOA, * LPAVISTREAMINFOA, *PAVISTREAMINFOA;
+
+typedef struct _AVISTREAMINFOW {
+    long	fccType;
+    long	fccHandler;
+    long	dwFlags;
+    long	dwCaps;
+    short	wPriority;
+    short	wLanguage;
+    long	dwScale;
+    long	dwRate;		/* dwRate / dwScale == samples/second */
+    long	dwStart;
+    long	dwLength;	/* In units above... */
+    long	dwInitialFrames;
+    long	dwSuggestedBufferSize;
+    long	dwQuality;
+    long	dwSampleSize;
+    RECT	rcFrame;
+    long	dwEditCount;
+    long	dwFormatChangeCount;
+    short	szName[64];
+} AVISTREAMINFOW, * LPAVISTREAMINFOW, *PAVISTREAMINFOW;
+DECL_WINELIB_TYPE_AW(AVISTREAMINFO)
+DECL_WINELIB_TYPE_AW(LPAVISTREAMINFO)
+DECL_WINELIB_TYPE_AW(PAVISTREAMINFO)
+
+#define AVISTREAMINFO_DISABLED		0x00000001
+#define AVISTREAMINFO_FORMATCHANGES	0x00010000
+
+/* AVIFILEINFO.dwFlags */
+#define AVIFILEINFO_HASINDEX		0x00000010
+#define AVIFILEINFO_MUSTUSEINDEX	0x00000020
+#define AVIFILEINFO_ISINTERLEAVED	0x00000100
+#define AVIFILEINFO_WASCAPTUREFILE	0x00010000
+#define AVIFILEINFO_COPYRIGHTED		0x00020000
+
+/* AVIFILEINFO.dwCaps */
+#define AVIFILECAPS_CANREAD		0x00000001
+#define AVIFILECAPS_CANWRITE		0x00000002
+#define AVIFILECAPS_ALLKEYFRAMES	0x00000010
+#define AVIFILECAPS_NOCOMPRESSION	0x00000020
+
+typedef struct _AVIFILEINFOW {
+    long               dwMaxBytesPerSec;
+    long               dwFlags;
+    long               dwCaps;
+    long               dwStreams;
+    long               dwSuggestedBufferSize;
+    long               dwWidth;
+    long               dwHeight;
+    long               dwScale;        
+    long               dwRate;
+    long               dwLength;
+    long               dwEditCount;
+    short               szFileType[64];
+} AVIFILEINFOW, * LPAVIFILEINFOW, *PAVIFILEINFOW;
+
+typedef struct _AVIFILEINFOA {
+    long               dwMaxBytesPerSec;
+    long               dwFlags;
+    long               dwCaps;
+    long               dwStreams;
+    long               dwSuggestedBufferSize;
+    long               dwWidth;
+    long               dwHeight;
+    long               dwScale;        
+    long               dwRate;
+    long               dwLength;
+    long               dwEditCount;
+    char		szFileType[64];
+} AVIFILEINFOA, * LPAVIFILEINFOA, *PAVIFILEINFOA;
+
+DECL_WINELIB_TYPE_AW(AVIFILEINFO)
+DECL_WINELIB_TYPE_AW(PAVIFILEINFO)
+DECL_WINELIB_TYPE_AW(LPAVIFILEINFO)
+
+/* AVICOMPRESSOPTIONS.dwFlags. determines presence of fields in below struct */
+#define AVICOMPRESSF_INTERLEAVE	0x00000001
+#define AVICOMPRESSF_DATARATE	0x00000002
+#define AVICOMPRESSF_KEYFRAMES	0x00000004
+#define AVICOMPRESSF_VALID	0x00000008
+
+typedef struct {
+    long	fccType;		/* stream type, for consistency */
+    long	fccHandler;		/* compressor */
+    long	dwKeyFrameEvery;	/* keyframe rate */
+    long	dwQuality;		/* compress quality 0-10,000 */
+    long	dwBytesPerSecond;	/* unsigned chars per second */
+    long	dwFlags;		/* flags... see below */
+    void*	lpFormat;		/* save format */
+    long	cbFormat;
+    void*	lpParms;		/* compressor options */
+    long	cbParms;
+    long	dwInterleaveEvery;	/* for non-video streams only */
+} AVICOMPRESSOPTIONS, *LPAVICOMPRESSOPTIONS,*PAVICOMPRESSOPTIONS;
+
+
+
+typedef struct {
+    long		cbSize;		// set to sizeof(COMPVARS) before
+					// calling ICCompressorChoose
+    long		dwFlags;	// see below...
+    HIC			hic;		// HIC of chosen compressor
+    long               fccType;	// basically ICTYPE_VIDEO
+    long               fccHandler;	// handler of chosen compressor or
+					// "" or "DIB "
+    LPBITMAPINFO	lpbiIn;		// input format
+    LPBITMAPINFO	lpbiOut;	// output format - will compress to this
+    void*		lpBitsOut;
+    void*		lpBitsPrev;
+    long		lFrame;
+    long		lKey;		// key frames how often?
+    long		lDataRate;	// desired data rate KB/Sec
+    long		lQ;		// desired quality
+    long		lKeyCount;
+    void*		lpState;	// state of compressor
+    long		cbState;	// size of the state
+} COMPVARS, *PCOMPVARS;
+
+// FLAGS for dwFlags element of COMPVARS structure:
+
+
+#define AVIERR_OK		0
+#define MAKE_AVIERR(error)	MAKE_SCODE(SEVERITY_ERROR,FACILITY_ITF,0x4000+error)
+
+#define AVIERR_UNSUPPORTED	MAKE_AVIERR(101)
+#define AVIERR_BADFORMAT	MAKE_AVIERR(102)
+#define AVIERR_MEMORY		MAKE_AVIERR(103)
+#define AVIERR_INTERNAL		MAKE_AVIERR(104)
+#define AVIERR_BADFLAGS		MAKE_AVIERR(105)
+#define AVIERR_BADPARAM		MAKE_AVIERR(106)
+#define AVIERR_BADSIZE		MAKE_AVIERR(107)
+#define AVIERR_BADHANDLE	MAKE_AVIERR(108)
+#define AVIERR_FILEREAD		MAKE_AVIERR(109)
+#define AVIERR_FILEWRITE	MAKE_AVIERR(110)
+#define AVIERR_FILEOPEN		MAKE_AVIERR(111)
+#define AVIERR_COMPRESSOR	MAKE_AVIERR(112)
+#define AVIERR_NOCOMPRESSOR	MAKE_AVIERR(113)
+#define AVIERR_READONLY		MAKE_AVIERR(114)
+#define AVIERR_NODATA		MAKE_AVIERR(115)
+#define AVIERR_BUFFERTOOSMALL	MAKE_AVIERR(116)
+#define AVIERR_CANTCOMPRESS	MAKE_AVIERR(117)
+#define AVIERR_USERABORT	MAKE_AVIERR(198)
+#define AVIERR_ERROR		MAKE_AVIERR(199)
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __WINE_VFW_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/winbase.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,1791 @@
+#ifndef __WINE_WINBASE_H
+#define __WINE_WINBASE_H
+
+#include "basetsd.h"
+#include "winnt.h"
+#include "winestring.h"
+#include "pshpack1.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct tagCOORD {
+    INT16 x;
+    INT16 y;
+} COORD, *LPCOORD;
+
+
+  /* Windows Exit Procedure flag values */
+#define	WEP_FREE_DLL        0
+#define	WEP_SYSTEM_EXIT     1
+
+typedef DWORD CALLBACK (*LPTHREAD_START_ROUTINE)(LPVOID);
+
+#define EXCEPTION_DEBUG_EVENT       1
+#define CREATE_THREAD_DEBUG_EVENT   2
+#define CREATE_PROCESS_DEBUG_EVENT  3
+#define EXIT_THREAD_DEBUG_EVENT     4
+#define EXIT_PROCESS_DEBUG_EVENT    5
+#define LOAD_DLL_DEBUG_EVENT        6
+#define UNLOAD_DLL_DEBUG_EVENT      7
+#define OUTPUT_DEBUG_STRING_EVENT   8
+#define RIP_EVENT                   9
+
+typedef struct _EXCEPTION_DEBUG_INFO {
+    EXCEPTION_RECORD ExceptionRecord;
+    DWORD dwFirstChance;
+} EXCEPTION_DEBUG_INFO;
+
+typedef struct _CREATE_THREAD_DEBUG_INFO {
+    HANDLE hThread;
+    LPVOID lpThreadLocalBase;
+    LPTHREAD_START_ROUTINE lpStartAddress;
+} CREATE_THREAD_DEBUG_INFO;
+
+typedef struct _CREATE_PROCESS_DEBUG_INFO {
+    HANDLE hFile;
+    HANDLE hProcess;
+    HANDLE hThread;
+    LPVOID lpBaseOfImage;
+    DWORD dwDebugInfoFileOffset;
+    DWORD nDebugInfoSize;
+    LPVOID lpThreadLocalBase;
+    LPTHREAD_START_ROUTINE lpStartAddress;
+    LPVOID lpImageName;
+    WORD fUnicode;
+} CREATE_PROCESS_DEBUG_INFO;
+
+typedef struct _EXIT_THREAD_DEBUG_INFO {
+    DWORD dwExitCode;
+} EXIT_THREAD_DEBUG_INFO;
+
+typedef struct _EXIT_PROCESS_DEBUG_INFO {
+    DWORD dwExitCode;
+} EXIT_PROCESS_DEBUG_INFO;
+
+typedef struct _LOAD_DLL_DEBUG_INFO {
+    HANDLE hFile;
+    LPVOID   lpBaseOfDll;
+    DWORD    dwDebugInfoFileOffset;
+    DWORD    nDebugInfoSize;
+    LPVOID   lpImageName;
+    WORD     fUnicode;
+} LOAD_DLL_DEBUG_INFO;
+
+typedef struct _UNLOAD_DLL_DEBUG_INFO {
+    LPVOID lpBaseOfDll;
+} UNLOAD_DLL_DEBUG_INFO;
+
+typedef struct _OUTPUT_DEBUG_STRING_INFO {
+    LPSTR lpDebugStringData;
+    WORD  fUnicode;
+    WORD  nDebugStringLength;
+} OUTPUT_DEBUG_STRING_INFO;
+
+typedef struct _RIP_INFO {
+    DWORD dwError;
+    DWORD dwType;
+} RIP_INFO;
+
+typedef struct _DEBUG_EVENT {
+    DWORD dwDebugEventCode;
+    DWORD dwProcessId;
+    DWORD dwThreadId;
+    union {
+        EXCEPTION_DEBUG_INFO      Exception;
+        CREATE_THREAD_DEBUG_INFO  CreateThread;
+        CREATE_PROCESS_DEBUG_INFO CreateProcessInfo;
+        EXIT_THREAD_DEBUG_INFO    ExitThread;
+        EXIT_PROCESS_DEBUG_INFO   ExitProcess;
+        LOAD_DLL_DEBUG_INFO       LoadDll;
+        UNLOAD_DLL_DEBUG_INFO     UnloadDll;
+        OUTPUT_DEBUG_STRING_INFO  DebugString;
+        RIP_INFO                  RipInfo;
+    } u;
+} DEBUG_EVENT, *LPDEBUG_EVENT;
+
+#define OFS_MAXPATHNAME 128
+typedef struct
+{
+    BYTE cBytes;
+    BYTE fFixedDisk;
+    WORD nErrCode;
+    BYTE reserved[4];
+    BYTE szPathName[OFS_MAXPATHNAME];
+} OFSTRUCT, *LPOFSTRUCT;
+
+#define OF_READ               0x0000
+#define OF_WRITE              0x0001
+#define OF_READWRITE          0x0002
+#define OF_SHARE_COMPAT       0x0000
+#define OF_SHARE_EXCLUSIVE    0x0010
+#define OF_SHARE_DENY_WRITE   0x0020
+#define OF_SHARE_DENY_READ    0x0030
+#define OF_SHARE_DENY_NONE    0x0040
+#define OF_PARSE              0x0100
+#define OF_DELETE             0x0200
+#define OF_VERIFY             0x0400   /* Used with OF_REOPEN */
+#define OF_SEARCH             0x0400   /* Used without OF_REOPEN */
+#define OF_CANCEL             0x0800
+#define OF_CREATE             0x1000
+#define OF_PROMPT             0x2000
+#define OF_EXIST              0x4000
+#define OF_REOPEN             0x8000
+
+/* SetErrorMode values */
+#define SEM_FAILCRITICALERRORS      0x0001
+#define SEM_NOGPFAULTERRORBOX       0x0002
+#define SEM_NOALIGNMENTFAULTEXCEPT  0x0004
+#define SEM_NOOPENFILEERRORBOX      0x8000
+
+/* CopyFileEx flags */
+#define COPY_FILE_FAIL_IF_EXISTS        0x00000001
+#define COPY_FILE_RESTARTABLE           0x00000002
+#define COPY_FILE_OPEN_SOURCE_FOR_WRITE 0x00000004
+
+/* GetTempFileName() Flags */
+#define TF_FORCEDRIVE	        0x80
+
+#define DRIVE_CANNOTDETERMINE      0
+#define DRIVE_DOESNOTEXIST         1
+#define DRIVE_REMOVABLE            2
+#define DRIVE_FIXED                3
+#define DRIVE_REMOTE               4
+/* Win32 additions */
+#define DRIVE_CDROM                5
+#define DRIVE_RAMDISK              6
+
+/* The security attributes structure */
+typedef struct _SECURITY_ATTRIBUTES
+{
+    DWORD   nLength;
+    LPVOID  lpSecurityDescriptor;
+    WIN_BOOL  bInheritHandle;
+} SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES;
+
+#ifndef _FILETIME_
+#define _FILETIME_
+/* 64 bit number of 100 nanoseconds intervals since January 1, 1601 */
+typedef struct
+{
+  DWORD  dwLowDateTime;
+  DWORD  dwHighDateTime;
+} FILETIME, *LPFILETIME;
+#endif /* _FILETIME_ */
+
+/* Find* structures */
+typedef struct
+{
+    DWORD     dwFileAttributes;
+    FILETIME  ftCreationTime;
+    FILETIME  ftLastAccessTime;
+    FILETIME  ftLastWriteTime;
+    DWORD     nFileSizeHigh;
+    DWORD     nFileSizeLow;
+    DWORD     dwReserved0;
+    DWORD     dwReserved1;
+    CHAR      cFileName[260];
+    CHAR      cAlternateFileName[14];
+} WIN32_FIND_DATAA, *LPWIN32_FIND_DATAA;
+
+typedef struct
+{
+    DWORD     dwFileAttributes;
+    FILETIME  ftCreationTime;
+    FILETIME  ftLastAccessTime;
+    FILETIME  ftLastWriteTime;
+    DWORD     nFileSizeHigh;
+    DWORD     nFileSizeLow;
+    DWORD     dwReserved0;
+    DWORD     dwReserved1;
+    WCHAR     cFileName[260];
+    WCHAR     cAlternateFileName[14];
+} WIN32_FIND_DATAW, *LPWIN32_FIND_DATAW;
+
+DECL_WINELIB_TYPE_AW(WIN32_FIND_DATA)
+DECL_WINELIB_TYPE_AW(LPWIN32_FIND_DATA)
+
+typedef struct
+{
+    LPVOID lpData;
+    DWORD cbData;
+    BYTE cbOverhead;
+    BYTE iRegionIndex;
+    WORD wFlags;
+    union {
+        struct {
+            HANDLE hMem;
+            DWORD dwReserved[3];
+        } Block;
+        struct {
+            DWORD dwCommittedSize;
+            DWORD dwUnCommittedSize;
+            LPVOID lpFirstBlock;
+            LPVOID lpLastBlock;
+        } Region;
+    } Foo;
+} PROCESS_HEAP_ENTRY, *LPPROCESS_HEAP_ENTRY;
+
+#define PROCESS_HEAP_REGION                   0x0001
+#define PROCESS_HEAP_UNCOMMITTED_RANGE        0x0002
+#define PROCESS_HEAP_ENTRY_BUSY               0x0004
+#define PROCESS_HEAP_ENTRY_MOVEABLE           0x0010
+#define PROCESS_HEAP_ENTRY_DDESHARE           0x0020
+
+#define INVALID_HANDLE_VALUE16  ((HANDLE16) -1)
+#define INVALID_HANDLE_VALUE  ((HANDLE) -1)
+
+#define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
+
+/* comm */
+
+#define CBR_110	0xFF10
+#define CBR_300	0xFF11
+#define CBR_600	0xFF12
+#define CBR_1200	0xFF13
+#define CBR_2400	0xFF14
+#define CBR_4800	0xFF15
+#define CBR_9600	0xFF16
+#define CBR_14400	0xFF17
+#define CBR_19200	0xFF18
+#define CBR_38400	0xFF1B
+#define CBR_56000	0xFF1F
+#define CBR_128000	0xFF23
+#define CBR_256000	0xFF27
+
+#define NOPARITY	0
+#define ODDPARITY	1
+#define EVENPARITY	2
+#define MARKPARITY	3
+#define SPACEPARITY	4
+#define ONESTOPBIT	0
+#define ONE5STOPBITS	1
+#define TWOSTOPBITS	2
+
+#define IGNORE		0
+#define INFINITE16      0xFFFF
+#define INFINITE      0xFFFFFFFF
+
+#define CE_RXOVER	0x0001
+#define CE_OVERRUN	0x0002
+#define CE_RXPARITY	0x0004
+#define CE_FRAME	0x0008
+#define CE_BREAK	0x0010
+#define CE_CTSTO	0x0020
+#define CE_DSRTO	0x0040
+#define CE_RLSDTO	0x0080
+#define CE_TXFULL	0x0100
+#define CE_PTO		0x0200
+#define CE_IOE		0x0400
+#define CE_DNS		0x0800
+#define CE_OOP		0x1000
+#define CE_MODE	0x8000
+
+#define IE_BADID	-1
+#define IE_OPEN	-2
+#define IE_NOPEN	-3
+#define IE_MEMORY	-4
+#define IE_DEFAULT	-5
+#define IE_HARDWARE	-10
+#define IE_BYTESIZE	-11
+#define IE_BAUDRATE	-12
+
+#define EV_RXCHAR	0x0001
+#define EV_RXFLAG	0x0002
+#define EV_TXEMPTY	0x0004
+#define EV_CTS		0x0008
+#define EV_DSR		0x0010
+#define EV_RLSD	0x0020
+#define EV_BREAK	0x0040
+#define EV_ERR		0x0080
+#define EV_RING	0x0100
+#define EV_PERR	0x0200
+#define EV_CTSS	0x0400
+#define EV_DSRS	0x0800
+#define EV_RLSDS	0x1000
+#define EV_RINGTE	0x2000
+#define EV_RingTe	EV_RINGTE
+
+#define SETXOFF	1
+#define SETXON		2
+#define SETRTS		3
+#define CLRRTS		4
+#define SETDTR		5
+#define CLRDTR		6
+#define RESETDEV	7
+#define SETBREAK	8
+#define CLRBREAK	9
+
+#define GETBASEIRQ	10
+
+/* Purge functions for Comm Port */
+#define PURGE_TXABORT       0x0001  /* Kill the pending/current writes to the 
+				       comm port */
+#define PURGE_RXABORT       0x0002  /*Kill the pending/current reads to 
+				     the comm port */
+#define PURGE_TXCLEAR       0x0004  /* Kill the transmit queue if there*/
+#define PURGE_RXCLEAR       0x0008  /* Kill the typeahead buffer if there*/
+
+
+/* Modem Status Flags */
+#define MS_CTS_ON           ((DWORD)0x0010)
+#define MS_DSR_ON           ((DWORD)0x0020)
+#define MS_RING_ON          ((DWORD)0x0040)
+#define MS_RLSD_ON          ((DWORD)0x0080)
+
+#define	RTS_CONTROL_DISABLE	0
+#define	RTS_CONTROL_ENABLE	1
+#define	RTS_CONTROL_HANDSHAKE	2
+#define	RTS_CONTROL_TOGGLE	3
+
+#define	DTR_CONTROL_DISABLE	0
+#define	DTR_CONTROL_ENABLE	1
+#define	DTR_CONTROL_HANDSHAKE	2
+
+#define CSTF_CTSHOLD	0x01
+#define CSTF_DSRHOLD	0x02
+#define CSTF_RLSDHOLD	0x04
+#define CSTF_XOFFHOLD	0x08
+#define CSTF_XOFFSENT	0x10
+#define CSTF_EOF	0x20
+#define CSTF_TXIM	0x40
+
+#define MAKEINTRESOURCEA(i) (LPSTR)((DWORD)((WORD)(i)))
+#define MAKEINTRESOURCEW(i) (LPWSTR)((DWORD)((WORD)(i)))
+#define MAKEINTRESOURCE WINELIB_NAME_AW(MAKEINTRESOURCE)
+
+/* Predefined resource types */
+#define RT_CURSORA         MAKEINTRESOURCEA(1)
+#define RT_CURSORW         MAKEINTRESOURCEW(1)
+#define RT_CURSOR            WINELIB_NAME_AW(RT_CURSOR)
+#define RT_BITMAPA         MAKEINTRESOURCEA(2)
+#define RT_BITMAPW         MAKEINTRESOURCEW(2)
+#define RT_BITMAP            WINELIB_NAME_AW(RT_BITMAP)
+#define RT_ICONA           MAKEINTRESOURCEA(3)
+#define RT_ICONW           MAKEINTRESOURCEW(3)
+#define RT_ICON              WINELIB_NAME_AW(RT_ICON)
+#define RT_MENUA           MAKEINTRESOURCEA(4)
+#define RT_MENUW           MAKEINTRESOURCEW(4)
+#define RT_MENU              WINELIB_NAME_AW(RT_MENU)
+#define RT_DIALOGA         MAKEINTRESOURCEA(5)
+#define RT_DIALOGW         MAKEINTRESOURCEW(5)
+#define RT_DIALOG            WINELIB_NAME_AW(RT_DIALOG)
+#define RT_STRINGA         MAKEINTRESOURCEA(6)
+#define RT_STRINGW         MAKEINTRESOURCEW(6)
+#define RT_STRING            WINELIB_NAME_AW(RT_STRING)
+#define RT_FONTDIRA        MAKEINTRESOURCEA(7)
+#define RT_FONTDIRW        MAKEINTRESOURCEW(7)
+#define RT_FONTDIR           WINELIB_NAME_AW(RT_FONTDIR)
+#define RT_FONTA           MAKEINTRESOURCEA(8)
+#define RT_FONTW           MAKEINTRESOURCEW(8)
+#define RT_FONT              WINELIB_NAME_AW(RT_FONT)
+#define RT_ACCELERATORA    MAKEINTRESOURCEA(9)
+#define RT_ACCELERATORW    MAKEINTRESOURCEW(9)
+#define RT_ACCELERATOR       WINELIB_NAME_AW(RT_ACCELERATOR)
+#define RT_RCDATAA         MAKEINTRESOURCEA(10)
+#define RT_RCDATAW         MAKEINTRESOURCEW(10)
+#define RT_RCDATA            WINELIB_NAME_AW(RT_RCDATA)
+#define RT_MESSAGELISTA    MAKEINTRESOURCEA(11)
+#define RT_MESSAGELISTW    MAKEINTRESOURCEW(11)
+#define RT_MESSAGELIST       WINELIB_NAME_AW(RT_MESSAGELIST)
+#define RT_GROUP_CURSORA   MAKEINTRESOURCEA(12)
+#define RT_GROUP_CURSORW   MAKEINTRESOURCEW(12)
+#define RT_GROUP_CURSOR      WINELIB_NAME_AW(RT_GROUP_CURSOR)
+#define RT_GROUP_ICONA     MAKEINTRESOURCEA(14)
+#define RT_GROUP_ICONW     MAKEINTRESOURCEW(14)
+#define RT_GROUP_ICON        WINELIB_NAME_AW(RT_GROUP_ICON)
+
+
+#define LMEM_FIXED          0   
+#define LMEM_MOVEABLE       0x0002
+#define LMEM_NOCOMPACT      0x0010
+#define LMEM_NODISCARD      0x0020
+#define LMEM_ZEROINIT       0x0040
+#define LMEM_MODIFY         0x0080
+#define LMEM_DISCARDABLE    0x0F00
+#define LMEM_DISCARDED	    0x4000
+#define LMEM_LOCKCOUNT	    0x00FF
+
+#define LPTR (LMEM_FIXED | LMEM_ZEROINIT)
+
+#define GMEM_FIXED          0x0000
+#define GMEM_MOVEABLE       0x0002
+#define GMEM_NOCOMPACT      0x0010
+#define GMEM_NODISCARD      0x0020
+#define GMEM_ZEROINIT       0x0040
+#define GMEM_MODIFY         0x0080
+#define GMEM_DISCARDABLE    0x0100
+#define GMEM_NOT_BANKED     0x1000
+#define GMEM_SHARE          0x2000
+#define GMEM_DDESHARE       0x2000
+#define GMEM_NOTIFY         0x4000
+#define GMEM_LOWER          GMEM_NOT_BANKED
+#define GMEM_DISCARDED      0x4000
+#define GMEM_LOCKCOUNT      0x00ff
+#define GMEM_INVALID_HANDLE 0x8000
+
+#define GHND                (GMEM_MOVEABLE | GMEM_ZEROINIT)
+#define GPTR                (GMEM_FIXED | GMEM_ZEROINIT)
+
+
+typedef struct tagMEMORYSTATUS
+{
+    DWORD    dwLength;
+    DWORD    dwMemoryLoad;
+    DWORD    dwTotalPhys;
+    DWORD    dwAvailPhys;
+    DWORD    dwTotalPageFile;
+    DWORD    dwAvailPageFile;
+    DWORD    dwTotalVirtual;
+    DWORD    dwAvailVirtual;
+} MEMORYSTATUS, *LPMEMORYSTATUS;
+
+
+#ifndef NOLOGERROR
+
+/* LogParamError and LogError values */
+
+/* Error modifier bits */
+#define ERR_WARNING             0x8000
+#define ERR_PARAM               0x4000
+
+#define ERR_SIZE_MASK           0x3000
+#define ERR_BYTE                0x1000
+#define ERR_WORD                0x2000
+#define ERR_DWORD               0x3000
+
+/* LogParamError() values */
+
+/* Generic parameter values */
+#define ERR_BAD_VALUE           0x6001
+#define ERR_BAD_FLAGS           0x6002
+#define ERR_BAD_INDEX           0x6003
+#define ERR_BAD_DVALUE          0x7004
+#define ERR_BAD_DFLAGS          0x7005
+#define ERR_BAD_DINDEX          0x7006
+#define ERR_BAD_PTR             0x7007
+#define ERR_BAD_FUNC_PTR        0x7008
+#define ERR_BAD_SELECTOR        0x6009
+#define ERR_BAD_STRING_PTR      0x700a
+#define ERR_BAD_HANDLE          0x600b
+
+/* KERNEL parameter errors */
+#define ERR_BAD_HINSTANCE       0x6020
+#define ERR_BAD_HMODULE         0x6021
+#define ERR_BAD_GLOBAL_HANDLE   0x6022
+#define ERR_BAD_LOCAL_HANDLE    0x6023
+#define ERR_BAD_ATOM            0x6024
+#define ERR_BAD_HFILE           0x6025
+
+/* USER parameter errors */
+#define ERR_BAD_HWND            0x6040
+#define ERR_BAD_HMENU           0x6041
+#define ERR_BAD_HCURSOR         0x6042
+#define ERR_BAD_HICON           0x6043
+#define ERR_BAD_HDWP            0x6044
+#define ERR_BAD_CID             0x6045
+#define ERR_BAD_HDRVR           0x6046
+
+/* GDI parameter errors */
+#define ERR_BAD_COORDS          0x7060
+#define ERR_BAD_GDI_OBJECT      0x6061
+#define ERR_BAD_HDC             0x6062
+#define ERR_BAD_HPEN            0x6063
+#define ERR_BAD_HFONT           0x6064
+#define ERR_BAD_HBRUSH          0x6065
+#define ERR_BAD_HBITMAP         0x6066
+#define ERR_BAD_HRGN            0x6067
+#define ERR_BAD_HPALETTE        0x6068
+#define ERR_BAD_HMETAFILE       0x6069
+
+
+/* LogError() values */
+
+/* KERNEL errors */
+#define ERR_GALLOC              0x0001
+#define ERR_GREALLOC            0x0002
+#define ERR_GLOCK               0x0003
+#define ERR_LALLOC              0x0004
+#define ERR_LREALLOC            0x0005
+#define ERR_LLOCK               0x0006
+#define ERR_ALLOCRES            0x0007
+#define ERR_LOCKRES             0x0008
+#define ERR_LOADMODULE          0x0009
+
+/* USER errors */
+#define ERR_CREATEDLG           0x0040
+#define ERR_CREATEDLG2          0x0041
+#define ERR_REGISTERCLASS       0x0042
+#define ERR_DCBUSY              0x0043
+#define ERR_CREATEWND           0x0044
+#define ERR_STRUCEXTRA          0x0045
+#define ERR_LOADSTR             0x0046
+#define ERR_LOADMENU            0x0047
+#define ERR_NESTEDBEGINPAINT    0x0048
+#define ERR_BADINDEX            0x0049
+#define ERR_CREATEMENU          0x004a
+
+/* GDI errors */
+#define ERR_CREATEDC            0x0080
+#define ERR_CREATEMETA          0x0081
+#define ERR_DELOBJSELECTED      0x0082
+#define ERR_SELBITMAP           0x0083
+
+
+
+/* Debugging support (DEBUG SYSTEM ONLY) */
+typedef struct
+{
+    UINT16  flags;
+    DWORD   dwOptions WINE_PACKED;
+    DWORD   dwFilter WINE_PACKED;
+    CHAR    achAllocModule[8] WINE_PACKED;
+    DWORD   dwAllocBreak WINE_PACKED;
+    DWORD   dwAllocCount WINE_PACKED;
+} WINDEBUGINFO, *LPWINDEBUGINFO;
+
+/* WINDEBUGINFO flags values */
+#define WDI_OPTIONS         0x0001
+#define WDI_FILTER          0x0002
+#define WDI_ALLOCBREAK      0x0004
+
+/* dwOptions values */
+#define DBO_CHECKHEAP       0x0001
+#define DBO_BUFFERFILL      0x0004
+#define DBO_DISABLEGPTRAPPING 0x0010
+#define DBO_CHECKFREE       0x0020
+
+#define DBO_SILENT          0x8000
+
+#define DBO_TRACEBREAK      0x2000
+#define DBO_WARNINGBREAK    0x1000
+#define DBO_NOERRORBREAK    0x0800
+#define DBO_NOFATALBREAK    0x0400
+#define DBO_INT3BREAK       0x0100
+
+/* DebugOutput flags values */
+#define DBF_TRACE           0x0000
+#define DBF_WARNING         0x4000
+#define DBF_ERROR           0x8000
+#define DBF_FATAL           0xc000
+
+/* dwFilter values */
+#define DBF_KERNEL          0x1000
+#define DBF_KRN_MEMMAN      0x0001
+#define DBF_KRN_LOADMODULE  0x0002
+#define DBF_KRN_SEGMENTLOAD 0x0004
+#define DBF_USER            0x0800
+#define DBF_GDI             0x0400
+#define DBF_MMSYSTEM        0x0040
+#define DBF_PENWIN          0x0020
+#define DBF_APPLICATION     0x0008
+#define DBF_DRIVER          0x0010
+
+#endif /* NOLOGERROR */
+
+typedef struct {
+        WORD wYear;
+        WORD wMonth;
+        WORD wDayOfWeek;
+        WORD wDay;
+        WORD wHour;
+        WORD wMinute;
+        WORD wSecond;
+        WORD wMilliseconds;
+} SYSTEMTIME, *LPSYSTEMTIME;
+
+/* The 'overlapped' data structure used by async I/O functions.
+ */
+typedef struct {
+        DWORD Internal;
+        DWORD InternalHigh;
+        DWORD Offset;
+        DWORD OffsetHigh;
+        HANDLE hEvent;
+} OVERLAPPED, *LPOVERLAPPED;
+
+/* Process startup information.
+ */
+
+/* STARTUPINFO.dwFlags */
+#define	STARTF_USESHOWWINDOW	0x00000001
+#define	STARTF_USESIZE		0x00000002
+#define	STARTF_USEPOSITION	0x00000004
+#define	STARTF_USECOUNTCHARS	0x00000008
+#define	STARTF_USEFILLATTRIBUTE	0x00000010
+#define	STARTF_RUNFULLSCREEN	0x00000020
+#define	STARTF_FORCEONFEEDBACK	0x00000040
+#define	STARTF_FORCEOFFFEEDBACK	0x00000080
+#define	STARTF_USESTDHANDLES	0x00000100
+#define	STARTF_USEHOTKEY	0x00000200
+
+typedef struct {
+        DWORD cb;		/* 00: size of struct */
+        LPSTR lpReserved;	/* 04: */
+        LPSTR lpDesktop;	/* 08: */
+        LPSTR lpTitle;		/* 0c: */
+        DWORD dwX;		/* 10: */
+        DWORD dwY;		/* 14: */
+        DWORD dwXSize;		/* 18: */
+        DWORD dwYSize;		/* 1c: */
+        DWORD dwXCountChars;	/* 20: */
+        DWORD dwYCountChars;	/* 24: */
+        DWORD dwFillAttribute;	/* 28: */
+        DWORD dwFlags;		/* 2c: */
+        WORD wShowWindow;	/* 30: */
+        WORD cbReserved2;	/* 32: */
+        BYTE *lpReserved2;	/* 34: */
+        HANDLE hStdInput;	/* 38: */
+        HANDLE hStdOutput;	/* 3c: */
+        HANDLE hStdError;	/* 40: */
+} STARTUPINFOA, *LPSTARTUPINFOA;
+
+typedef struct {
+        DWORD cb;
+        LPWSTR lpReserved;
+        LPWSTR lpDesktop;
+        LPWSTR lpTitle;
+        DWORD dwX;
+        DWORD dwY;
+        DWORD dwXSize;
+        DWORD dwYSize;
+        DWORD dwXCountChars;
+        DWORD dwYCountChars;
+        DWORD dwFillAttribute;
+        DWORD dwFlags;
+        WORD wShowWindow;
+        WORD cbReserved2;
+        BYTE *lpReserved2;
+        HANDLE hStdInput;
+        HANDLE hStdOutput;
+        HANDLE hStdError;
+} STARTUPINFOW, *LPSTARTUPINFOW;
+
+DECL_WINELIB_TYPE_AW(STARTUPINFO)
+DECL_WINELIB_TYPE_AW(LPSTARTUPINFO)
+
+typedef struct {
+	HANDLE	hProcess;
+	HANDLE	hThread;
+	DWORD		dwProcessId;
+	DWORD		dwThreadId;
+} PROCESS_INFORMATION,*LPPROCESS_INFORMATION;
+
+typedef struct {
+        LONG Bias;
+        WCHAR StandardName[32];
+        SYSTEMTIME StandardDate;
+        LONG StandardBias;
+        WCHAR DaylightName[32];
+        SYSTEMTIME DaylightDate;
+        LONG DaylightBias;
+} TIME_ZONE_INFORMATION, *LPTIME_ZONE_INFORMATION;
+
+#define TIME_ZONE_ID_UNKNOWN    0
+#define TIME_ZONE_ID_STANDARD   1
+#define TIME_ZONE_ID_DAYLIGHT   2
+
+/* CreateProcess: dwCreationFlag values
+ */
+#define DEBUG_PROCESS               0x00000001
+#define DEBUG_ONLY_THIS_PROCESS     0x00000002
+#define CREATE_SUSPENDED            0x00000004
+#define DETACHED_PROCESS            0x00000008
+#define CREATE_NEW_CONSOLE          0x00000010
+#define NORMAL_PRIORITY_CLASS       0x00000020
+#define IDLE_PRIORITY_CLASS         0x00000040
+#define HIGH_PRIORITY_CLASS         0x00000080
+#define REALTIME_PRIORITY_CLASS     0x00000100
+#define CREATE_NEW_PROCESS_GROUP    0x00000200
+#define CREATE_UNICODE_ENVIRONMENT  0x00000400
+#define CREATE_SEPARATE_WOW_VDM     0x00000800
+#define CREATE_SHARED_WOW_VDM       0x00001000
+#define CREATE_DEFAULT_ERROR_MODE   0x04000000
+#define CREATE_NO_WINDOW            0x08000000
+#define PROFILE_USER                0x10000000
+#define PROFILE_KERNEL              0x20000000
+#define PROFILE_SERVER              0x40000000
+
+
+/* File object type definitions
+ */
+#define FILE_TYPE_UNKNOWN       0
+#define FILE_TYPE_DISK          1
+#define FILE_TYPE_CHAR          2
+#define FILE_TYPE_PIPE          3
+#define FILE_TYPE_REMOTE        32768
+
+/* File creation flags
+ */
+#define FILE_FLAG_WRITE_THROUGH    0x80000000UL
+#define FILE_FLAG_OVERLAPPED 	   0x40000000L
+#define FILE_FLAG_NO_BUFFERING     0x20000000L
+#define FILE_FLAG_RANDOM_ACCESS    0x10000000L
+#define FILE_FLAG_SEQUENTIAL_SCAN  0x08000000L
+#define FILE_FLAG_DELETE_ON_CLOSE  0x04000000L
+#define FILE_FLAG_BACKUP_SEMANTICS 0x02000000L
+#define FILE_FLAG_POSIX_SEMANTICS  0x01000000L
+#define CREATE_NEW              1
+#define CREATE_ALWAYS           2
+#define OPEN_EXISTING           3
+#define OPEN_ALWAYS             4
+#define TRUNCATE_EXISTING       5
+
+/* Standard handle identifiers
+ */
+#define STD_INPUT_HANDLE        ((DWORD) -10)
+#define STD_OUTPUT_HANDLE       ((DWORD) -11)
+#define STD_ERROR_HANDLE        ((DWORD) -12)
+
+typedef struct
+{
+  int dwFileAttributes;
+  FILETIME ftCreationTime;
+  FILETIME ftLastAccessTime;
+  FILETIME ftLastWriteTime;
+  int dwVolumeSerialNumber;
+  int nFileSizeHigh;
+  int nFileSizeLow;
+  int nNumberOfLinks;
+  int nFileIndexHigh;
+  int nFileIndexLow;
+} BY_HANDLE_FILE_INFORMATION ;
+
+
+typedef struct _SYSTEM_POWER_STATUS
+{
+  WIN_BOOL16  ACLineStatus;
+  BYTE    BatteryFlag;
+  BYTE    BatteryLifePercent;
+  BYTE    reserved;
+  DWORD   BatteryLifeTime;
+  DWORD   BatteryFullLifeTime;
+} SYSTEM_POWER_STATUS, *LPSYSTEM_POWER_STATUS;
+
+typedef struct _MEMORY_BASIC_INFORMATION
+{
+    LPVOID   BaseAddress;
+    LPVOID   AllocationBase;
+    DWORD    AllocationProtect;
+    DWORD    RegionSize;
+    DWORD    State;
+    DWORD    Protect;
+    DWORD    Type;
+} MEMORY_BASIC_INFORMATION,*LPMEMORY_BASIC_INFORMATION;
+
+
+typedef WIN_BOOL CALLBACK (*CODEPAGE_ENUMPROCA)(LPSTR);
+typedef WIN_BOOL CALLBACK (*CODEPAGE_ENUMPROCW)(LPWSTR);
+DECL_WINELIB_TYPE_AW(CODEPAGE_ENUMPROC)
+typedef WIN_BOOL CALLBACK (*LOCALE_ENUMPROCA)(LPSTR);
+typedef WIN_BOOL CALLBACK (*LOCALE_ENUMPROCW)(LPWSTR);
+DECL_WINELIB_TYPE_AW(LOCALE_ENUMPROC)
+
+typedef struct tagSYSTEM_INFO
+{
+    union {
+	DWORD	dwOemId; /* Obsolete field - do not use */
+	struct {
+		WORD wProcessorArchitecture;
+		WORD wReserved;
+	} DUMMYSTRUCTNAME;
+    } DUMMYUNIONNAME;
+    DWORD	dwPageSize;
+    LPVOID	lpMinimumApplicationAddress;
+    LPVOID	lpMaximumApplicationAddress;
+    DWORD	dwActiveProcessorMask;
+    DWORD	dwNumberOfProcessors;
+    DWORD	dwProcessorType;
+    DWORD	dwAllocationGranularity;
+    WORD	wProcessorLevel;
+    WORD	wProcessorRevision;
+} SYSTEM_INFO, *LPSYSTEM_INFO;
+
+/* {G,S}etPriorityClass */
+#define	NORMAL_PRIORITY_CLASS	0x00000020
+#define	IDLE_PRIORITY_CLASS	0x00000040
+#define	HIGH_PRIORITY_CLASS	0x00000080
+#define	REALTIME_PRIORITY_CLASS	0x00000100
+
+typedef WIN_BOOL CALLBACK (*ENUMRESTYPEPROCA)(HMODULE,LPSTR,LONG);
+typedef WIN_BOOL CALLBACK (*ENUMRESTYPEPROCW)(HMODULE,LPWSTR,LONG);
+typedef WIN_BOOL CALLBACK (*ENUMRESNAMEPROCA)(HMODULE,LPCSTR,LPSTR,LONG);
+typedef WIN_BOOL CALLBACK (*ENUMRESNAMEPROCW)(HMODULE,LPCWSTR,LPWSTR,LONG);
+typedef WIN_BOOL CALLBACK (*ENUMRESLANGPROCA)(HMODULE,LPCSTR,LPCSTR,WORD,LONG);
+typedef WIN_BOOL CALLBACK (*ENUMRESLANGPROCW)(HMODULE,LPCWSTR,LPCWSTR,WORD,LONG);
+
+DECL_WINELIB_TYPE_AW(ENUMRESTYPEPROC)
+DECL_WINELIB_TYPE_AW(ENUMRESNAMEPROC)
+DECL_WINELIB_TYPE_AW(ENUMRESLANGPROC)
+
+/* flags that can be passed to LoadLibraryEx */
+#define	DONT_RESOLVE_DLL_REFERENCES	0x00000001
+#define	LOAD_LIBRARY_AS_DATAFILE	0x00000002
+#define	LOAD_WITH_ALTERED_SEARCH_PATH	0x00000008
+
+/* ifdef _x86_ ... */
+typedef struct _LDT_ENTRY {
+    WORD	LimitLow;
+    WORD	BaseLow;
+    union {
+	struct {
+	    BYTE	BaseMid;
+	    BYTE	Flags1;/*Declare as bytes to avoid alignment problems */
+	    BYTE	Flags2; 
+	    BYTE	BaseHi;
+	} Bytes;
+	struct {	    
+	    unsigned	BaseMid		: 8;
+	    unsigned	Type		: 5;
+	    unsigned	Dpl		: 2;
+	    unsigned	Pres		: 1;
+	    unsigned	LimitHi		: 4;
+	    unsigned	Sys		: 1;
+	    unsigned	Reserved_0	: 1;
+	    unsigned	Default_Big	: 1;
+	    unsigned	Granularity	: 1;
+	    unsigned	BaseHi		: 8;
+	} Bits;
+    } HighWord;
+} LDT_ENTRY, *LPLDT_ENTRY;
+
+
+typedef enum _GET_FILEEX_INFO_LEVELS {
+    GetFileExInfoStandard
+} GET_FILEEX_INFO_LEVELS;
+
+typedef struct _WIN32_FILE_ATTRIBUTES_DATA {
+    DWORD    dwFileAttributes;
+    FILETIME ftCreationTime;
+    FILETIME ftLastAccessTime;
+    FILETIME ftLastWriteTime;
+    DWORD    nFileSizeHigh;
+    DWORD    nFileSizeLow;
+} WIN32_FILE_ATTRIBUTE_DATA, *LPWIN32_FILE_ATTRIBUTE_DATA;
+
+typedef struct _DllVersionInfo {
+    DWORD cbSize;
+    DWORD dwMajorVersion;
+    DWORD dwMinorVersion;
+    DWORD dwBuildNumber;
+    DWORD dwPlatformID;
+} DLLVERSIONINFO;
+
+/*
+ * This one seems to be a Win32 only definition. It also is defined with
+ * WINAPI instead of CALLBACK in the windows headers.
+ */
+typedef DWORD WINAPI (*LPPROGRESS_ROUTINE)(LARGE_INTEGER, LARGE_INTEGER, LARGE_INTEGER, 
+                                           LARGE_INTEGER, DWORD, DWORD, HANDLE,
+                                           HANDLE, LPVOID);
+
+
+#define WAIT_FAILED		0xffffffff
+#define WAIT_OBJECT_0		0
+#define WAIT_ABANDONED		STATUS_ABANDONED_WAIT_0
+#define WAIT_ABANDONED_0	STATUS_ABANDONED_WAIT_0
+#define WAIT_IO_COMPLETION	STATUS_USER_APC
+#define WAIT_TIMEOUT		STATUS_TIMEOUT
+#define STILL_ACTIVE            STATUS_PENDING
+
+#define	PAGE_NOACCESS		0x01
+#define	PAGE_READONLY		0x02
+#define	PAGE_READWRITE		0x04
+#define	PAGE_WRITECOPY		0x08
+#define	PAGE_EXECUTE		0x10
+#define	PAGE_EXECUTE_READ	0x20
+#define	PAGE_EXECUTE_READWRITE	0x40
+#define	PAGE_EXECUTE_WRITECOPY	0x80
+#define	PAGE_GUARD		0x100
+#define	PAGE_NOCACHE		0x200
+
+#define MEM_COMMIT              0x00001000
+#define MEM_RESERVE             0x00002000
+#define MEM_DECOMMIT            0x00004000
+#define MEM_RELEASE             0x00008000
+#define MEM_FREE                0x00010000
+#define MEM_PRIVATE             0x00020000
+#define MEM_MAPPED              0x00040000
+#define MEM_TOP_DOWN            0x00100000
+#ifdef __WINE__
+#define MEM_SYSTEM              0x80000000
+#endif
+
+#define SEC_FILE                0x00800000
+#define SEC_IMAGE               0x01000000
+#define SEC_RESERVE             0x04000000
+#define SEC_COMMIT              0x08000000
+#define SEC_NOCACHE             0x10000000
+
+#define FILE_BEGIN              0
+#define FILE_CURRENT            1
+#define FILE_END                2
+
+#define FILE_CASE_SENSITIVE_SEARCH      0x00000001
+#define FILE_CASE_PRESERVED_NAMES       0x00000002
+#define FILE_UNICODE_ON_DISK            0x00000004
+#define FILE_PERSISTENT_ACLS            0x00000008
+
+#define FILE_MAP_COPY                   0x00000001
+#define FILE_MAP_WRITE                  0x00000002
+#define FILE_MAP_READ                   0x00000004
+#define FILE_MAP_ALL_ACCESS             0x000f001f
+
+#define MOVEFILE_REPLACE_EXISTING       0x00000001
+#define MOVEFILE_COPY_ALLOWED           0x00000002
+#define MOVEFILE_DELAY_UNTIL_REBOOT     0x00000004
+
+#define FS_CASE_SENSITIVE               FILE_CASE_SENSITIVE_SEARCH
+#define FS_CASE_IS_PRESERVED            FILE_CASE_PRESERVED_NAMES
+#define FS_UNICODE_STORED_ON_DISK       FILE_UNICODE_ON_DISK
+
+#define EXCEPTION_ACCESS_VIOLATION          STATUS_ACCESS_VIOLATION
+#define EXCEPTION_DATATYPE_MISALIGNMENT     STATUS_DATATYPE_MISALIGNMENT
+#define EXCEPTION_BREAKPOINT                STATUS_BREAKPOINT
+#define EXCEPTION_SINGLE_STEP               STATUS_SINGLE_STEP
+#define EXCEPTION_ARRAY_BOUNDS_EXCEEDED     STATUS_ARRAY_BOUNDS_EXCEEDED
+#define EXCEPTION_FLT_DENORMAL_OPERAND      STATUS_FLOAT_DENORMAL_OPERAND
+#define EXCEPTION_FLT_DIVIDE_BY_ZERO        STATUS_FLOAT_DIVIDE_BY_ZERO
+#define EXCEPTION_FLT_INEXACT_RESULT        STATUS_FLOAT_INEXACT_RESULT
+#define EXCEPTION_FLT_INVALID_OPERATION     STATUS_FLOAT_INVALID_OPERATION
+#define EXCEPTION_FLT_OVERFLOW              STATUS_FLOAT_OVERFLOW
+#define EXCEPTION_FLT_STACK_CHECK           STATUS_FLOAT_STACK_CHECK
+#define EXCEPTION_FLT_UNDERFLOW             STATUS_FLOAT_UNDERFLOW
+#define EXCEPTION_INT_DIVIDE_BY_ZERO        STATUS_INTEGER_DIVIDE_BY_ZERO
+#define EXCEPTION_INT_OVERFLOW              STATUS_INTEGER_OVERFLOW
+#define EXCEPTION_PRIV_INSTRUCTION          STATUS_PRIVILEGED_INSTRUCTION
+#define EXCEPTION_IN_PAGE_ERROR             STATUS_IN_PAGE_ERROR
+#define EXCEPTION_ILLEGAL_INSTRUCTION       STATUS_ILLEGAL_INSTRUCTION
+#define EXCEPTION_NONCONTINUABLE_EXCEPTION  STATUS_NONCONTINUABLE_EXCEPTION
+#define EXCEPTION_STACK_OVERFLOW            STATUS_STACK_OVERFLOW
+#define EXCEPTION_INVALID_DISPOSITION       STATUS_INVALID_DISPOSITION
+#define EXCEPTION_GUARD_PAGE                STATUS_GUARD_PAGE_VIOLATION
+#define EXCEPTION_INVALID_HANDLE            STATUS_INVALID_HANDLE
+#define CONTROL_C_EXIT                      STATUS_CONTROL_C_EXIT
+
+/* Wine extension; Windows doesn't have a name for this code */
+#define EXCEPTION_CRITICAL_SECTION_WAIT     0xc0000194
+
+#define DUPLICATE_CLOSE_SOURCE		0x00000001
+#define DUPLICATE_SAME_ACCESS		0x00000002
+
+#define HANDLE_FLAG_INHERIT             0x00000001
+#define HANDLE_FLAG_PROTECT_FROM_CLOSE  0x00000002
+
+#define HINSTANCE_ERROR 32
+
+#define THREAD_PRIORITY_LOWEST          THREAD_BASE_PRIORITY_MIN
+#define THREAD_PRIORITY_BELOW_NORMAL    (THREAD_PRIORITY_LOWEST+1)
+#define THREAD_PRIORITY_NORMAL          0
+#define THREAD_PRIORITY_HIGHEST         THREAD_BASE_PRIORITY_MAX
+#define THREAD_PRIORITY_ABOVE_NORMAL    (THREAD_PRIORITY_HIGHEST-1)
+#define THREAD_PRIORITY_ERROR_RETURN    (0x7fffffff)
+#define THREAD_PRIORITY_TIME_CRITICAL   THREAD_BASE_PRIORITY_LOWRT
+#define THREAD_PRIORITY_IDLE            THREAD_BASE_PRIORITY_IDLE
+
+/* Could this type be considered opaque? */
+typedef struct {
+	LPVOID	DebugInfo;
+	LONG LockCount;
+	LONG RecursionCount;
+	HANDLE OwningThread;
+	HANDLE LockSemaphore;
+	DWORD Reserved;
+}CRITICAL_SECTION;
+
+#ifdef __WINE__
+#define CRITICAL_SECTION_INIT { 0, -1, 0, 0, 0, 0 }
+#endif
+
+typedef struct {
+        DWORD dwOSVersionInfoSize;
+        DWORD dwMajorVersion;
+        DWORD dwMinorVersion;
+        DWORD dwBuildNumber;
+        DWORD dwPlatformId;
+        CHAR szCSDVersion[128];
+} OSVERSIONINFO16;
+
+typedef struct {
+	DWORD dwOSVersionInfoSize;
+	DWORD dwMajorVersion;
+	DWORD dwMinorVersion;
+	DWORD dwBuildNumber;
+	DWORD dwPlatformId;
+	CHAR szCSDVersion[128];
+} OSVERSIONINFOA;
+
+typedef struct {
+	DWORD dwOSVersionInfoSize;
+	DWORD dwMajorVersion;
+	DWORD dwMinorVersion;
+	DWORD dwBuildNumber;
+	DWORD dwPlatformId;
+	WCHAR szCSDVersion[128];
+} OSVERSIONINFOW;
+
+DECL_WINELIB_TYPE_AW(OSVERSIONINFO)
+
+#define VER_PLATFORM_WIN32s             0
+#define VER_PLATFORM_WIN32_WINDOWS      1
+#define VER_PLATFORM_WIN32_NT           2
+
+typedef struct tagCOMSTAT
+{
+    DWORD status;
+    DWORD cbInQue;
+    DWORD cbOutQue;
+} COMSTAT,*LPCOMSTAT;
+
+typedef struct tagDCB
+{
+    DWORD DCBlength;
+    DWORD BaudRate;
+    unsigned fBinary               :1;
+    unsigned fParity               :1;
+    unsigned fOutxCtsFlow          :1;
+    unsigned fOutxDsrFlow          :1;
+    unsigned fDtrControl           :2;
+    unsigned fDsrSensitivity       :1;
+    unsigned fTXContinueOnXoff     :1;
+    unsigned fOutX                 :1;
+    unsigned fInX                  :1;
+    unsigned fErrorChar            :1;
+    unsigned fNull                 :1;
+    unsigned fRtsControl           :2;
+    unsigned fAbortOnError         :1;
+    unsigned fDummy2               :17;
+    WORD wReserved;
+    WORD XonLim;
+    WORD XoffLim;
+    BYTE ByteSize;
+    BYTE Parity;
+    BYTE StopBits;
+    char XonChar;
+    char XoffChar;
+    char ErrorChar;
+    char EofChar;
+    char EvtChar;
+} DCB, *LPDCB;
+
+
+
+typedef struct tagCOMMTIMEOUTS {
+	DWORD	ReadIntervalTimeout;
+	DWORD	ReadTotalTimeoutMultiplier;
+	DWORD	ReadTotalTimeoutConstant;
+	DWORD	WriteTotalTimeoutMultiplier;
+	DWORD	WriteTotalTimeoutConstant;
+} COMMTIMEOUTS,*LPCOMMTIMEOUTS;
+  
+#include "poppack.h"
+
+typedef void CALLBACK (*PAPCFUNC)(ULONG_PTR);
+typedef void CALLBACK (*PTIMERAPCROUTINE)(LPVOID,DWORD,DWORD);
+
+WIN_BOOL      WINAPI ClearCommError(INT,LPDWORD,LPCOMSTAT);
+WIN_BOOL      WINAPI BuildCommDCBA(LPCSTR,LPDCB);
+WIN_BOOL      WINAPI BuildCommDCBW(LPCWSTR,LPDCB);
+#define     BuildCommDCB WINELIB_NAME_AW(BuildCommDCB)
+WIN_BOOL      WINAPI BuildCommDCBAndTimeoutsA(LPCSTR,LPDCB,LPCOMMTIMEOUTS);
+WIN_BOOL      WINAPI BuildCommDCBAndTimeoutsW(LPCWSTR,LPDCB,LPCOMMTIMEOUTS);
+#define     BuildCommDCBAndTimeouts WINELIB_NAME_AW(BuildCommDCBAndTimeouts)
+WIN_BOOL      WINAPI GetCommTimeouts(HANDLE,LPCOMMTIMEOUTS);
+WIN_BOOL      WINAPI SetCommTimeouts(HANDLE,LPCOMMTIMEOUTS);
+WIN_BOOL      WINAPI GetCommState(INT,LPDCB);
+WIN_BOOL      WINAPI SetCommState(INT,LPDCB);
+WIN_BOOL      WINAPI TransmitCommChar(INT,CHAR);
+WIN_BOOL      WINAPI SetupComm(HANDLE, DWORD, DWORD);
+WIN_BOOL      WINAPI GetCommProperties(HANDLE, LPDCB *);
+  
+/*DWORD WINAPI GetVersion( void );*/
+WIN_BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16*);
+WIN_BOOL WINAPI GetVersionExA(OSVERSIONINFOA*);
+WIN_BOOL WINAPI GetVersionExW(OSVERSIONINFOW*);
+#define GetVersionEx WINELIB_NAME_AW(GetVersionEx)
+
+/*int WinMain(HINSTANCE, HINSTANCE prev, char *cmd, int show);*/
+
+void      WINAPI DeleteCriticalSection(CRITICAL_SECTION *lpCrit);
+void      WINAPI EnterCriticalSection(CRITICAL_SECTION *lpCrit);
+WIN_BOOL      WINAPI TryEnterCriticalSection(CRITICAL_SECTION *lpCrit);
+void      WINAPI InitializeCriticalSection(CRITICAL_SECTION *lpCrit);
+void      WINAPI LeaveCriticalSection(CRITICAL_SECTION *lpCrit);
+void      WINAPI MakeCriticalSectionGlobal(CRITICAL_SECTION *lpCrit);
+WIN_BOOL    WINAPI GetProcessWorkingSetSize(HANDLE,LPDWORD,LPDWORD);
+DWORD     WINAPI QueueUserAPC(PAPCFUNC,HANDLE,ULONG_PTR);
+void      WINAPI RaiseException(DWORD,DWORD,DWORD,const LPDWORD);
+WIN_BOOL    WINAPI SetProcessWorkingSetSize(HANDLE,DWORD,DWORD);
+WIN_BOOL    WINAPI TerminateProcess(HANDLE,DWORD);
+WIN_BOOL    WINAPI TerminateThread(HANDLE,DWORD);
+WIN_BOOL    WINAPI GetExitCodeThread(HANDLE,LPDWORD); 
+
+/* GetBinaryType return values.
+ */
+
+#define SCS_32BIT_BINARY    0
+#define SCS_DOS_BINARY      1
+#define SCS_WOW_BINARY      2
+#define SCS_PIF_BINARY      3
+#define SCS_POSIX_BINARY    4
+#define SCS_OS216_BINARY    5
+
+WIN_BOOL WINAPI GetBinaryTypeA( LPCSTR lpApplicationName, LPDWORD lpBinaryType );
+WIN_BOOL WINAPI GetBinaryTypeW( LPCWSTR lpApplicationName, LPDWORD lpBinaryType );
+#define GetBinaryType WINELIB_NAME_AW(GetBinaryType)
+
+WIN_BOOL16      WINAPI GetWinDebugInfo16(LPWINDEBUGINFO,UINT16);
+WIN_BOOL16      WINAPI SetWinDebugInfo16(LPWINDEBUGINFO);
+/* Declarations for functions that exist only in Win32 */
+
+
+WIN_BOOL        WINAPI AttachThreadInput(DWORD,DWORD,WIN_BOOL);
+WIN_BOOL        WINAPI AccessCheck(PSECURITY_DESCRIPTOR,HANDLE,DWORD,PGENERIC_MAPPING,PPRIVILEGE_SET,LPDWORD,LPDWORD,LPWIN_BOOL);
+WIN_BOOL        WINAPI AdjustTokenPrivileges(HANDLE,WIN_BOOL,LPVOID,DWORD,LPVOID,LPDWORD);
+WIN_BOOL        WINAPI AllocateAndInitializeSid(PSID_IDENTIFIER_AUTHORITY,BYTE,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,PSID *);
+WIN_BOOL        WINAPI AllocateLocallyUniqueId(PLUID);
+WIN_BOOL      WINAPI AllocConsole(void);
+WIN_BOOL      WINAPI AreFileApisANSI(void);
+WIN_BOOL        WINAPI BackupEventLogA(HANDLE,LPCSTR);
+WIN_BOOL        WINAPI BackupEventLogW(HANDLE,LPCWSTR);
+#define     BackupEventLog WINELIB_NAME_AW(BackupEventLog)
+WIN_BOOL        WINAPI Beep(DWORD,DWORD);
+WIN_BOOL        WINAPI CancelWaitableTimer(HANDLE);
+WIN_BOOL        WINAPI ClearEventLogA(HANDLE,LPCSTR);
+WIN_BOOL        WINAPI ClearEventLogW(HANDLE,LPCWSTR);
+#define     ClearEventLog WINELIB_NAME_AW(ClearEventLog)
+WIN_BOOL        WINAPI CloseEventLog(HANDLE);
+WIN_BOOL      WINAPI CloseHandle(HANDLE);
+WIN_BOOL      WINAPI ContinueDebugEvent(DWORD,DWORD,DWORD);
+HANDLE    WINAPI ConvertToGlobalHandle(HANDLE hSrc);
+WIN_BOOL      WINAPI CopyFileA(LPCSTR,LPCSTR,WIN_BOOL);
+WIN_BOOL      WINAPI CopyFileW(LPCWSTR,LPCWSTR,WIN_BOOL);
+#define     CopyFile WINELIB_NAME_AW(CopyFile)
+WIN_BOOL      WINAPI CopyFileExA(LPCSTR, LPCSTR, LPPROGRESS_ROUTINE, LPVOID, LPWIN_BOOL, DWORD);
+WIN_BOOL      WINAPI CopyFileExW(LPCWSTR, LPCWSTR, LPPROGRESS_ROUTINE, LPVOID, LPWIN_BOOL, DWORD);
+#define     CopyFileEx WINELIB_NAME_AW(CopyFileEx)
+WIN_BOOL        WINAPI CopySid(DWORD,PSID,PSID);
+INT       WINAPI CompareFileTime(LPFILETIME,LPFILETIME);
+HANDLE    WINAPI CreateEventA(LPSECURITY_ATTRIBUTES,WIN_BOOL,WIN_BOOL,LPCSTR);
+HANDLE    WINAPI CreateEventW(LPSECURITY_ATTRIBUTES,WIN_BOOL,WIN_BOOL,LPCWSTR);
+#define     CreateEvent WINELIB_NAME_AW(CreateEvent)
+HANDLE     WINAPI CreateFileA(LPCSTR,DWORD,DWORD,LPSECURITY_ATTRIBUTES,
+                                 DWORD,DWORD,HANDLE);
+HANDLE     WINAPI CreateFileW(LPCWSTR,DWORD,DWORD,LPSECURITY_ATTRIBUTES,
+                                 DWORD,DWORD,HANDLE);
+#define     CreateFile WINELIB_NAME_AW(CreateFile)
+HANDLE    WINAPI CreateFileMappingA(HANDLE,LPSECURITY_ATTRIBUTES,DWORD,
+                                        DWORD,DWORD,LPCSTR);
+HANDLE    WINAPI CreateFileMappingW(HANDLE,LPSECURITY_ATTRIBUTES,DWORD,
+                                        DWORD,DWORD,LPCWSTR);
+#define     CreateFileMapping WINELIB_NAME_AW(CreateFileMapping)
+HANDLE    WINAPI CreateMutexA(LPSECURITY_ATTRIBUTES,WIN_BOOL,LPCSTR);
+HANDLE    WINAPI CreateMutexW(LPSECURITY_ATTRIBUTES,WIN_BOOL,LPCWSTR);
+#define     CreateMutex WINELIB_NAME_AW(CreateMutex)
+WIN_BOOL      WINAPI CreatePipe(PHANDLE,PHANDLE,LPSECURITY_ATTRIBUTES,DWORD);
+WIN_BOOL      WINAPI CreateProcessA(LPCSTR,LPSTR,LPSECURITY_ATTRIBUTES,
+                                    LPSECURITY_ATTRIBUTES,WIN_BOOL,DWORD,LPVOID,LPCSTR,
+                                    LPSTARTUPINFOA,LPPROCESS_INFORMATION);
+WIN_BOOL      WINAPI CreateProcessW(LPCWSTR,LPWSTR,LPSECURITY_ATTRIBUTES,
+                                    LPSECURITY_ATTRIBUTES,WIN_BOOL,DWORD,LPVOID,LPCWSTR,
+                                    LPSTARTUPINFOW,LPPROCESS_INFORMATION);
+#define     CreateProcess WINELIB_NAME_AW(CreateProcess)
+HANDLE    WINAPI CreateSemaphoreA(LPSECURITY_ATTRIBUTES,LONG,LONG,LPCSTR);
+HANDLE    WINAPI CreateSemaphoreW(LPSECURITY_ATTRIBUTES,LONG,LONG,LPCWSTR);
+#define     CreateSemaphore WINELIB_NAME_AW(CreateSemaphore)
+HANDLE      WINAPI CreateThread(LPSECURITY_ATTRIBUTES,DWORD,LPTHREAD_START_ROUTINE,LPVOID,DWORD,LPDWORD);
+HANDLE      WINAPI CreateWaitableTimerA(LPSECURITY_ATTRIBUTES,WIN_BOOL,LPCSTR);
+HANDLE      WINAPI CreateWaitableTimerW(LPSECURITY_ATTRIBUTES,WIN_BOOL,LPCWSTR);
+#define     CreateWaitableTimer WINELIB_NAME_AW(CreateWaitableTimer)
+WIN_BOOL        WINAPI DebugActiveProcess(DWORD);
+void        WINAPI DebugBreak(void);
+WIN_BOOL        WINAPI DeregisterEventSource(HANDLE);
+WIN_BOOL        WINAPI DisableThreadLibraryCalls(HMODULE);
+WIN_BOOL        WINAPI DosDateTimeToFileTime(WORD,WORD,LPFILETIME);
+WIN_BOOL        WINAPI DuplicateHandle(HANDLE,HANDLE,HANDLE,HANDLE*,DWORD,WIN_BOOL,DWORD);
+WIN_BOOL        WINAPI EnumDateFormatsA(DATEFMT_ENUMPROCA lpDateFmtEnumProc, LCID Locale, DWORD dwFlags);
+WIN_BOOL        WINAPI EnumDateFormatsW(DATEFMT_ENUMPROCW lpDateFmtEnumProc, LCID Locale, DWORD dwFlags);
+#define     EnumDateFormats WINELIB_NAME_AW(EnumDateFormats)
+WIN_BOOL      WINAPI EnumResourceLanguagesA(HMODULE,LPCSTR,LPCSTR,
+                                            ENUMRESLANGPROCA,LONG);
+WIN_BOOL      WINAPI EnumResourceLanguagesW(HMODULE,LPCWSTR,LPCWSTR,
+                                            ENUMRESLANGPROCW,LONG);
+#define     EnumResourceLanguages WINELIB_NAME_AW(EnumResourceLanguages)
+WIN_BOOL      WINAPI EnumResourceNamesA(HMODULE,LPCSTR,ENUMRESNAMEPROCA,
+                                        LONG);
+WIN_BOOL      WINAPI EnumResourceNamesW(HMODULE,LPCWSTR,ENUMRESNAMEPROCW,
+                                        LONG);
+#define     EnumResourceNames WINELIB_NAME_AW(EnumResourceNames)
+WIN_BOOL      WINAPI EnumResourceTypesA(HMODULE,ENUMRESTYPEPROCA,LONG);
+WIN_BOOL      WINAPI EnumResourceTypesW(HMODULE,ENUMRESTYPEPROCW,LONG);
+#define     EnumResourceTypes WINELIB_NAME_AW(EnumResourceTypes)
+WIN_BOOL      WINAPI EnumSystemCodePagesA(CODEPAGE_ENUMPROCA,DWORD);
+WIN_BOOL      WINAPI EnumSystemCodePagesW(CODEPAGE_ENUMPROCW,DWORD);
+#define     EnumSystemCodePages WINELIB_NAME_AW(EnumSystemCodePages)
+WIN_BOOL      WINAPI EnumSystemLocalesA(LOCALE_ENUMPROCA,DWORD);
+WIN_BOOL      WINAPI EnumSystemLocalesW(LOCALE_ENUMPROCW,DWORD);
+#define     EnumSystemLocales WINELIB_NAME_AW(EnumSystemLocales)
+WIN_BOOL      WINAPI EnumTimeFormatsA(TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags);
+WIN_BOOL      WINAPI EnumTimeFormatsW(TIMEFMT_ENUMPROCW lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags);
+#define     EnumTimeFormats WINELIB_NAME_AW(EnumTimeFormats)
+WIN_BOOL        WINAPI EqualSid(PSID, PSID);
+WIN_BOOL        WINAPI EqualPrefixSid(PSID,PSID);
+VOID        WINAPI ExitProcess(DWORD) WINE_NORETURN;
+VOID        WINAPI ExitThread(DWORD) WINE_NORETURN;
+DWORD       WINAPI ExpandEnvironmentStringsA(LPCSTR,LPSTR,DWORD);
+DWORD       WINAPI ExpandEnvironmentStringsW(LPCWSTR,LPWSTR,DWORD);
+#define     ExpandEnvironmentStrings WINELIB_NAME_AW(ExpandEnvironmentStrings)
+WIN_BOOL      WINAPI FileTimeToDosDateTime(const FILETIME*,LPWORD,LPWORD);
+WIN_BOOL      WINAPI FileTimeToLocalFileTime(const FILETIME*,LPFILETIME);
+WIN_BOOL      WINAPI FileTimeToSystemTime(const FILETIME*,LPSYSTEMTIME);
+HANDLE    WINAPI FindFirstChangeNotificationA(LPCSTR,WIN_BOOL,DWORD);
+HANDLE    WINAPI FindFirstChangeNotificationW(LPCWSTR,WIN_BOOL,DWORD);
+#define     FindFirstChangeNotification WINELIB_NAME_AW(FindFirstChangeNotification)
+WIN_BOOL      WINAPI FindNextChangeNotification(HANDLE);
+WIN_BOOL      WINAPI FindCloseChangeNotification(HANDLE);
+HRSRC     WINAPI FindResourceExA(HMODULE,LPCSTR,LPCSTR,WORD);
+HRSRC     WINAPI FindResourceExW(HMODULE,LPCWSTR,LPCWSTR,WORD);
+#define     FindResourceEx WINELIB_NAME_AW(FindResourceEx)
+WIN_BOOL      WINAPI FlushConsoleInputBuffer(HANDLE);
+WIN_BOOL      WINAPI FlushFileBuffers(HANDLE);
+WIN_BOOL      WINAPI FlushViewOfFile(LPCVOID, DWORD);
+DWORD       WINAPI FormatMessageA(DWORD,LPCVOID,DWORD,DWORD,LPSTR,
+				    DWORD,LPDWORD);
+DWORD       WINAPI FormatMessageW(DWORD,LPCVOID,DWORD,DWORD,LPWSTR,
+				    DWORD,LPDWORD);
+#define     FormatMessage WINELIB_NAME_AW(FormatMessage)
+WIN_BOOL      WINAPI FreeConsole(void);
+WIN_BOOL      WINAPI FreeEnvironmentStringsA(LPSTR);
+WIN_BOOL      WINAPI FreeEnvironmentStringsW(LPWSTR);
+#define     FreeEnvironmentStrings WINELIB_NAME_AW(FreeEnvironmentStrings)
+PVOID       WINAPI FreeSid(PSID);
+UINT      WINAPI GetACP(void);
+LPCSTR      WINAPI GetCommandLineA(void);
+LPCWSTR     WINAPI GetCommandLineW(void);
+#define     GetCommandLine WINELIB_NAME_AW(GetCommandLine)
+WIN_BOOL      WINAPI GetComputerNameA(LPSTR,LPDWORD);
+WIN_BOOL      WINAPI GetComputerNameW(LPWSTR,LPDWORD);
+#define     GetComputerName WINELIB_NAME_AW(GetComputerName)
+UINT      WINAPI GetConsoleCP(void);
+WIN_BOOL      WINAPI GetConsoleMode(HANDLE,LPDWORD);
+UINT      WINAPI GetConsoleOutputCP(void);
+DWORD       WINAPI GetConsoleTitleA(LPSTR,DWORD);
+DWORD       WINAPI GetConsoleTitleW(LPWSTR,DWORD);
+#define     GetConsoleTitle WINELIB_NAME_AW(GetConsoleTitle)
+WIN_BOOL        WINAPI GetCommMask(HANDLE, LPDWORD);
+WIN_BOOL        WINAPI GetCommModemStatus(HANDLE, LPDWORD);
+HANDLE      WINAPI GetCurrentProcess(void);
+HANDLE      WINAPI GetCurrentThread(void);
+INT         WINAPI GetDateFormatA(LCID,DWORD,LPSYSTEMTIME,LPCSTR,LPSTR,INT);
+INT         WINAPI GetDateFormatW(LCID,DWORD,LPSYSTEMTIME,LPCWSTR,LPWSTR,INT);
+#define     GetDateFormat WINELIB_NAME_AW(GetDateFormat)
+LPSTR       WINAPI GetEnvironmentStringsA(void);
+LPWSTR      WINAPI GetEnvironmentStringsW(void);
+#define     GetEnvironmentStrings WINELIB_NAME_AW(GetEnvironmentStrings)
+DWORD       WINAPI GetEnvironmentVariableA(LPCSTR,LPSTR,DWORD);
+DWORD       WINAPI GetEnvironmentVariableW(LPCWSTR,LPWSTR,DWORD);
+#define     GetEnvironmentVariable WINELIB_NAME_AW(GetEnvironmentVariable)
+WIN_BOOL      WINAPI GetFileAttributesExA(LPCSTR,GET_FILEEX_INFO_LEVELS,LPVOID);
+WIN_BOOL      WINAPI GetFileAttributesExW(LPCWSTR,GET_FILEEX_INFO_LEVELS,LPVOID);
+#define     GetFileattributesEx WINELIB_NAME_AW(GetFileAttributesEx)
+DWORD       WINAPI GetFileInformationByHandle(HANDLE,BY_HANDLE_FILE_INFORMATION*);
+WIN_BOOL        WINAPI GetFileSecurityA(LPCSTR,SECURITY_INFORMATION,PSECURITY_DESCRIPTOR,DWORD,LPDWORD);
+WIN_BOOL        WINAPI GetFileSecurityW(LPCWSTR,SECURITY_INFORMATION,PSECURITY_DESCRIPTOR,DWORD,LPDWORD);
+#define     GetFileSecurity WINELIB_NAME_AW(GetFileSecurity)
+DWORD       WINAPI GetFileSize(HANDLE,LPDWORD);
+WIN_BOOL        WINAPI GetFileTime(HANDLE,LPFILETIME,LPFILETIME,LPFILETIME);
+DWORD       WINAPI GetFileType(HANDLE);
+DWORD       WINAPI GetFullPathNameA(LPCSTR,DWORD,LPSTR,LPSTR*);
+DWORD       WINAPI GetFullPathNameW(LPCWSTR,DWORD,LPWSTR,LPWSTR*);
+#define     GetFullPathName WINELIB_NAME_AW(GetFullPathName)
+WIN_BOOL      WINAPI GetHandleInformation(HANDLE,LPDWORD);
+COORD       WINAPI GetLargestConsoleWindowSize(HANDLE);
+DWORD       WINAPI GetLengthSid(PSID);
+VOID        WINAPI GetLocalTime(LPSYSTEMTIME);
+DWORD       WINAPI GetLogicalDrives(void);
+DWORD       WINAPI GetLongPathNameA(LPCSTR,LPSTR,DWORD);
+DWORD       WINAPI GetLongPathNameW(LPCWSTR,LPWSTR,DWORD);
+#define     GetLongPathName WINELIB_NAME_AW(GetLongPathName)
+WIN_BOOL      WINAPI GetNumberOfConsoleInputEvents(HANDLE,LPDWORD);
+WIN_BOOL      WINAPI GetNumberOfConsoleMouseButtons(LPDWORD);
+WIN_BOOL        WINAPI GetNumberOfEventLogRecords(HANDLE,PDWORD);
+UINT      WINAPI GetOEMCP(void);
+WIN_BOOL        WINAPI GetOldestEventLogRecord(HANDLE,PDWORD);
+DWORD       WINAPI GetPriorityClass(HANDLE);
+DWORD       WINAPI GetProcessVersion(DWORD);
+WIN_BOOL        WINAPI GetSecurityDescriptorControl(PSECURITY_DESCRIPTOR,PSECURITY_DESCRIPTOR_CONTROL,LPDWORD);
+WIN_BOOL        WINAPI GetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR,LPWIN_BOOL,PACL *,LPWIN_BOOL);
+WIN_BOOL        WINAPI GetSecurityDescriptorGroup(PSECURITY_DESCRIPTOR,PSID *,LPWIN_BOOL);
+DWORD       WINAPI GetSecurityDescriptorLength(PSECURITY_DESCRIPTOR);
+WIN_BOOL        WINAPI GetSecurityDescriptorOwner(PSECURITY_DESCRIPTOR,PSID *,LPWIN_BOOL);
+WIN_BOOL        WINAPI GetSecurityDescriptorSacl(PSECURITY_DESCRIPTOR,LPWIN_BOOL,PACL *,LPWIN_BOOL);
+PSID_IDENTIFIER_AUTHORITY WINAPI GetSidIdentifierAuthority(PSID);
+DWORD       WINAPI GetSidLengthRequired(BYTE);
+PDWORD      WINAPI GetSidSubAuthority(PSID,DWORD);
+PUCHAR      WINAPI GetSidSubAuthorityCount(PSID);
+DWORD       WINAPI GetShortPathNameA(LPCSTR,LPSTR,DWORD);
+DWORD       WINAPI GetShortPathNameW(LPCWSTR,LPWSTR,DWORD);
+#define     GetShortPathName WINELIB_NAME_AW(GetShortPathName)
+HFILE     WINAPI GetStdHandle(DWORD);
+WIN_BOOL      WINAPI GetStringTypeExA(LCID,DWORD,LPCSTR,INT,LPWORD);
+WIN_BOOL      WINAPI GetStringTypeExW(LCID,DWORD,LPCWSTR,INT,LPWORD);
+#define     GetStringTypeEx WINELIB_NAME_AW(GetStringTypeEx)
+VOID        WINAPI GetSystemInfo(LPSYSTEM_INFO);
+WIN_BOOL        WINAPI GetSystemPowerStatus(LPSYSTEM_POWER_STATUS);
+VOID        WINAPI GetSystemTime(LPSYSTEMTIME);
+VOID        WINAPI GetSystemTimeAsFileTime(LPFILETIME);
+INT         WINAPI GetTimeFormatA(LCID,DWORD,LPSYSTEMTIME,LPCSTR,LPSTR,INT);
+INT         WINAPI GetTimeFormatW(LCID,DWORD,LPSYSTEMTIME,LPCWSTR,LPWSTR,INT);
+#define     GetTimeFormat WINELIB_NAME_AW(GetTimeFormat)
+WIN_BOOL        WINAPI GetThreadContext(HANDLE,CONTEXT *);
+LCID        WINAPI GetThreadLocale(void);
+INT       WINAPI GetThreadPriority(HANDLE);
+WIN_BOOL      WINAPI GetThreadSelectorEntry(HANDLE,DWORD,LPLDT_ENTRY);
+WIN_BOOL        WINAPI GetThreadTimes(HANDLE,LPFILETIME,LPFILETIME,LPFILETIME,LPFILETIME);
+WIN_BOOL        WINAPI GetTokenInformation(HANDLE,TOKEN_INFORMATION_CLASS,LPVOID,DWORD,LPDWORD);
+WIN_BOOL        WINAPI GetUserNameA(LPSTR,LPDWORD);
+WIN_BOOL        WINAPI GetUserNameW(LPWSTR,LPDWORD);
+#define     GetUserName WINELIB_NAME_AW(GetUserName)
+VOID        WINAPI GlobalMemoryStatus(LPMEMORYSTATUS);
+LPVOID      WINAPI HeapAlloc(HANDLE,DWORD,DWORD);
+DWORD       WINAPI HeapCompact(HANDLE,DWORD);
+HANDLE    WINAPI HeapCreate(DWORD,DWORD,DWORD);
+WIN_BOOL      WINAPI HeapDestroy(HANDLE);
+WIN_BOOL      WINAPI HeapFree(HANDLE,DWORD,LPVOID);
+WIN_BOOL      WINAPI HeapLock(HANDLE);
+LPVOID      WINAPI HeapReAlloc(HANDLE,DWORD,LPVOID,DWORD);
+DWORD       WINAPI HeapSize(HANDLE,DWORD,LPVOID);
+WIN_BOOL      WINAPI HeapUnlock(HANDLE);
+WIN_BOOL      WINAPI HeapValidate(HANDLE,DWORD,LPCVOID);
+WIN_BOOL        WINAPI HeapWalk(HANDLE,LPPROCESS_HEAP_ENTRY);
+WIN_BOOL        WINAPI InitializeSid(PSID,PSID_IDENTIFIER_AUTHORITY,BYTE);
+WIN_BOOL        WINAPI IsValidSecurityDescriptor(PSECURITY_DESCRIPTOR);
+WIN_BOOL        WINAPI IsValidSid(PSID);
+WIN_BOOL        WINAPI ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL);
+WIN_BOOL        WINAPI IsDBCSLeadByteEx(UINT,BYTE);
+WIN_BOOL        WINAPI IsProcessorFeaturePresent(DWORD);
+WIN_BOOL        WINAPI IsValidLocale(DWORD,DWORD);
+WIN_BOOL        WINAPI LookupAccountSidA(LPCSTR,PSID,LPSTR,LPDWORD,LPSTR,LPDWORD,PSID_NAME_USE);
+WIN_BOOL        WINAPI LookupAccountSidW(LPCWSTR,PSID,LPWSTR,LPDWORD,LPWSTR,LPDWORD,PSID_NAME_USE);
+#define     LookupAccountSid WINELIB_NAME_AW(LookupAccountSidW)
+WIN_BOOL        WINAPI LocalFileTimeToFileTime(const FILETIME*,LPFILETIME);
+WIN_BOOL        WINAPI LockFile(HANDLE,DWORD,DWORD,DWORD,DWORD);
+WIN_BOOL        WINAPI LockFileEx(HANDLE, DWORD, DWORD, DWORD, DWORD, LPOVERLAPPED);    
+WIN_BOOL        WINAPI LookupPrivilegeValueA(LPCSTR,LPCSTR,LPVOID);
+WIN_BOOL        WINAPI LookupPrivilegeValueW(LPCWSTR,LPCWSTR,LPVOID);
+#define     LookupPrivilegeValue WINELIB_NAME_AW(LookupPrivilegeValue)
+WIN_BOOL        WINAPI MakeSelfRelativeSD(PSECURITY_DESCRIPTOR,PSECURITY_DESCRIPTOR,LPDWORD);
+HMODULE   WINAPI MapHModuleSL(HMODULE16);
+HMODULE16   WINAPI MapHModuleLS(HMODULE);
+SEGPTR      WINAPI MapLS(LPVOID);
+LPVOID      WINAPI MapSL(SEGPTR);
+LPVOID      WINAPI MapViewOfFile(HANDLE,DWORD,DWORD,DWORD,DWORD);
+LPVOID      WINAPI MapViewOfFileEx(HANDLE,DWORD,DWORD,DWORD,DWORD,LPVOID);
+WIN_BOOL      WINAPI MoveFileA(LPCSTR,LPCSTR);
+WIN_BOOL      WINAPI MoveFileW(LPCWSTR,LPCWSTR);
+#define     MoveFile WINELIB_NAME_AW(MoveFile)
+WIN_BOOL      WINAPI MoveFileExA(LPCSTR,LPCSTR,DWORD);
+WIN_BOOL      WINAPI MoveFileExW(LPCWSTR,LPCWSTR,DWORD);
+#define     MoveFileEx WINELIB_NAME_AW(MoveFileEx)
+INT       WINAPI MultiByteToWideChar(UINT,DWORD,LPCSTR,INT,LPWSTR,INT);
+WIN_BOOL        WINAPI NotifyChangeEventLog(HANDLE,HANDLE);
+INT       WINAPI WideCharToMultiByte(UINT,DWORD,LPCWSTR,INT,LPSTR,INT,LPCSTR,WIN_BOOL*);
+HANDLE      WINAPI OpenBackupEventLogA(LPCSTR,LPCSTR);
+HANDLE      WINAPI OpenBackupEventLogW(LPCWSTR,LPCWSTR);
+#define     OpenBackupEventLog WINELIB_NAME_AW(OpenBackupEventLog)
+HANDLE    WINAPI OpenEventA(DWORD,WIN_BOOL,LPCSTR);
+HANDLE    WINAPI OpenEventW(DWORD,WIN_BOOL,LPCWSTR);
+#define     OpenEvent WINELIB_NAME_AW(OpenEvent)
+HANDLE      WINAPI OpenEventLogA(LPCSTR,LPCSTR);
+HANDLE      WINAPI OpenEventLogW(LPCWSTR,LPCWSTR);
+#define     OpenEventLog WINELIB_NAME_AW(OpenEventLog)
+HANDLE    WINAPI OpenFileMappingA(DWORD,WIN_BOOL,LPCSTR);
+HANDLE    WINAPI OpenFileMappingW(DWORD,WIN_BOOL,LPCWSTR);
+#define     OpenFileMapping WINELIB_NAME_AW(OpenFileMapping)
+HANDLE    WINAPI OpenMutexA(DWORD,WIN_BOOL,LPCSTR);
+HANDLE    WINAPI OpenMutexW(DWORD,WIN_BOOL,LPCWSTR);
+#define     OpenMutex WINELIB_NAME_AW(OpenMutex)
+HANDLE    WINAPI OpenProcess(DWORD,WIN_BOOL,DWORD);
+WIN_BOOL        WINAPI OpenProcessToken(HANDLE,DWORD,PHANDLE);
+HANDLE    WINAPI OpenSemaphoreA(DWORD,WIN_BOOL,LPCSTR);
+HANDLE    WINAPI OpenSemaphoreW(DWORD,WIN_BOOL,LPCWSTR);
+#define     OpenSemaphore WINELIB_NAME_AW(OpenSemaphore)
+WIN_BOOL        WINAPI OpenThreadToken(HANDLE,DWORD,WIN_BOOL,PHANDLE);
+HANDLE      WINAPI OpenWaitableTimerA(DWORD,WIN_BOOL,LPCSTR);
+HANDLE      WINAPI OpenWaitableTimerW(DWORD,WIN_BOOL,LPCWSTR);
+#define     OpenWaitableTimer WINELIB_NAME_AW(OpenWaitableTimer)
+WIN_BOOL        WINAPI PulseEvent(HANDLE);
+WIN_BOOL        WINAPI PurgeComm(HANDLE,DWORD);
+DWORD       WINAPI QueryDosDeviceA(LPCSTR,LPSTR,DWORD);
+DWORD       WINAPI QueryDosDeviceW(LPCWSTR,LPWSTR,DWORD);
+#define     QueryDosDevice WINELIB_NAME_AW(QueryDosDevice)
+WIN_BOOL      WINAPI QueryPerformanceCounter(PLARGE_INTEGER);
+WIN_BOOL      WINAPI ReadConsoleA(HANDLE,LPVOID,DWORD,LPDWORD,LPVOID);
+WIN_BOOL      WINAPI ReadConsoleW(HANDLE,LPVOID,DWORD,LPDWORD,LPVOID);
+#define     ReadConsole WINELIB_NAME_AW(ReadConsole)
+WIN_BOOL      WINAPI ReadConsoleOutputCharacterA(HANDLE,LPSTR,DWORD,
+						 COORD,LPDWORD);
+#define     ReadConsoleOutputCharacter WINELIB_NAME_AW(ReadConsoleOutputCharacter)
+WIN_BOOL        WINAPI ReadEventLogA(HANDLE,DWORD,DWORD,LPVOID,DWORD,DWORD *,DWORD *);
+WIN_BOOL        WINAPI ReadEventLogW(HANDLE,DWORD,DWORD,LPVOID,DWORD,DWORD *,DWORD *);
+#define     ReadEventLog WINELIB_NAME_AW(ReadEventLog)
+WIN_BOOL      WINAPI ReadFile(HANDLE,LPVOID,DWORD,LPDWORD,LPOVERLAPPED);
+HANDLE      WINAPI RegisterEventSourceA(LPCSTR,LPCSTR);
+HANDLE      WINAPI RegisterEventSourceW(LPCWSTR,LPCWSTR);
+#define     RegisterEventSource WINELIB_NAME_AW(RegisterEventSource)
+WIN_BOOL      WINAPI ReleaseMutex(HANDLE);
+WIN_BOOL      WINAPI ReleaseSemaphore(HANDLE,LONG,LPLONG);
+WIN_BOOL        WINAPI ReportEventA(HANDLE,WORD,WORD,DWORD,PSID,WORD,DWORD,LPCSTR *,LPVOID);
+WIN_BOOL        WINAPI ReportEventW(HANDLE,WORD,WORD,DWORD,PSID,WORD,DWORD,LPCWSTR *,LPVOID);
+#define     ReportEvent WINELIB_NAME_AW(ReportEvent)
+WIN_BOOL      WINAPI ResetEvent(HANDLE);
+DWORD       WINAPI ResumeThread(HANDLE);
+WIN_BOOL        WINAPI RevertToSelf(void);
+DWORD       WINAPI SearchPathA(LPCSTR,LPCSTR,LPCSTR,DWORD,LPSTR,LPSTR*);
+DWORD       WINAPI SearchPathW(LPCWSTR,LPCWSTR,LPCWSTR,DWORD,LPWSTR,LPWSTR*);
+#define     SearchPath WINELIB_NAME_AW(SearchPath)
+WIN_BOOL      WINAPI SetCommMask(INT,DWORD);
+WIN_BOOL      WINAPI SetComputerNameA(LPCSTR);
+WIN_BOOL      WINAPI SetComputerNameW(LPCWSTR);
+#define     SetComputerName WINELIB_NAME_AW(SetComputerName)
+WIN_BOOL      WINAPI SetConsoleCursorPosition(HANDLE,COORD);
+WIN_BOOL      WINAPI SetConsoleMode(HANDLE,DWORD);
+WIN_BOOL      WINAPI SetConsoleTitleA(LPCSTR);
+WIN_BOOL      WINAPI SetConsoleTitleW(LPCWSTR);
+#define     SetConsoleTitle WINELIB_NAME_AW(SetConsoleTitle)
+WIN_BOOL      WINAPI SetEndOfFile(HANDLE);
+WIN_BOOL      WINAPI SetEnvironmentVariableA(LPCSTR,LPCSTR);
+WIN_BOOL      WINAPI SetEnvironmentVariableW(LPCWSTR,LPCWSTR);
+#define     SetEnvironmentVariable WINELIB_NAME_AW(SetEnvironmentVariable)
+WIN_BOOL      WINAPI SetEvent(HANDLE);
+VOID        WINAPI SetFileApisToANSI(void);
+VOID        WINAPI SetFileApisToOEM(void);
+DWORD       WINAPI SetFilePointer(HANDLE,LONG,LPLONG,DWORD);
+WIN_BOOL        WINAPI SetFileSecurityA(LPCSTR,SECURITY_INFORMATION,PSECURITY_DESCRIPTOR);
+WIN_BOOL        WINAPI SetFileSecurityW(LPCWSTR,SECURITY_INFORMATION,PSECURITY_DESCRIPTOR);
+#define     SetFileSecurity WINELIB_NAME_AW(SetFileSecurity)
+WIN_BOOL        WINAPI SetFileTime(HANDLE,const FILETIME*,const FILETIME*,const FILETIME*);
+WIN_BOOL        WINAPI SetHandleInformation(HANDLE,DWORD,DWORD);
+WIN_BOOL        WINAPI SetPriorityClass(HANDLE,DWORD);
+WIN_BOOL        WINAPI SetLocalTime(const SYSTEMTIME*);
+WIN_BOOL        WINAPI SetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR,WIN_BOOL,PACL,WIN_BOOL);
+WIN_BOOL        WINAPI SetSecurityDescriptorGroup(PSECURITY_DESCRIPTOR,PSID,WIN_BOOL);
+WIN_BOOL        WINAPI SetSecurityDescriptorOwner(PSECURITY_DESCRIPTOR,PSID,WIN_BOOL);
+WIN_BOOL        WINAPI SetSecurityDescriptorSacl(PSECURITY_DESCRIPTOR,WIN_BOOL,PACL,WIN_BOOL);
+WIN_BOOL      WINAPI SetStdHandle(DWORD,HANDLE);
+WIN_BOOL      WINAPI SetSystemPowerState(WIN_BOOL,WIN_BOOL);
+WIN_BOOL      WINAPI SetSystemTime(const SYSTEMTIME*);
+DWORD       WINAPI SetThreadAffinityMask(HANDLE,DWORD);
+WIN_BOOL        WINAPI SetThreadContext(HANDLE,const CONTEXT *);
+WIN_BOOL        WINAPI SetThreadLocale(LCID);
+WIN_BOOL        WINAPI SetThreadPriority(HANDLE,INT);
+WIN_BOOL        WINAPI SetTimeZoneInformation(const LPTIME_ZONE_INFORMATION);
+WIN_BOOL        WINAPI SetWaitableTimer(HANDLE,const LARGE_INTEGER*,LONG,PTIMERAPCROUTINE,LPVOID,WIN_BOOL);
+VOID        WINAPI Sleep(DWORD);
+DWORD       WINAPI SleepEx(DWORD,WIN_BOOL);
+DWORD       WINAPI SuspendThread(HANDLE);
+WIN_BOOL      WINAPI SystemTimeToFileTime(const SYSTEMTIME*,LPFILETIME);
+DWORD       WINAPI TlsAlloc(void);
+WIN_BOOL      WINAPI TlsFree(DWORD);
+LPVOID      WINAPI TlsGetValue(DWORD);
+WIN_BOOL      WINAPI TlsSetValue(DWORD,LPVOID);
+VOID        WINAPI UnMapLS(SEGPTR);
+WIN_BOOL      WINAPI UnlockFile(HANDLE,DWORD,DWORD,DWORD,DWORD);
+WIN_BOOL      WINAPI UnmapViewOfFile(LPVOID);
+LPVOID      WINAPI VirtualAlloc(LPVOID,DWORD,DWORD,DWORD);
+WIN_BOOL      WINAPI VirtualFree(LPVOID,DWORD,DWORD);
+WIN_BOOL      WINAPI VirtualLock(LPVOID,DWORD);
+WIN_BOOL      WINAPI VirtualProtect(LPVOID,DWORD,DWORD,LPDWORD);
+WIN_BOOL      WINAPI VirtualProtectEx(HANDLE,LPVOID,DWORD,DWORD,LPDWORD);
+DWORD       WINAPI VirtualQuery(LPCVOID,LPMEMORY_BASIC_INFORMATION,DWORD);
+DWORD       WINAPI VirtualQueryEx(HANDLE,LPCVOID,LPMEMORY_BASIC_INFORMATION,DWORD);
+WIN_BOOL      WINAPI VirtualUnlock(LPVOID,DWORD);
+WIN_BOOL      WINAPI WaitCommEvent(HANDLE,LPDWORD,LPOVERLAPPED);
+WIN_BOOL      WINAPI WaitForDebugEvent(LPDEBUG_EVENT,DWORD);
+DWORD       WINAPI WaitForMultipleObjects(DWORD,const HANDLE*,WIN_BOOL,DWORD);
+DWORD       WINAPI WaitForMultipleObjectsEx(DWORD,const HANDLE*,WIN_BOOL,DWORD,WIN_BOOL);
+DWORD       WINAPI WaitForSingleObject(HANDLE,DWORD);
+DWORD       WINAPI WaitForSingleObjectEx(HANDLE,DWORD,WIN_BOOL);
+WIN_BOOL      WINAPI WriteConsoleA(HANDLE,LPCVOID,DWORD,LPDWORD,LPVOID);
+WIN_BOOL      WINAPI WriteConsoleW(HANDLE,LPCVOID,DWORD,LPDWORD,LPVOID);
+#define     WriteConsole WINELIB_NAME_AW(WriteConsole)
+WIN_BOOL      WINAPI WriteFile(HANDLE,LPCVOID,DWORD,LPDWORD,LPOVERLAPPED);
+LANGID      WINAPI GetSystemDefaultLangID(void);
+LCID        WINAPI GetSystemDefaultLCID(void);
+LANGID      WINAPI GetUserDefaultLangID(void);
+LCID        WINAPI GetUserDefaultLCID(void);
+ATOM        WINAPI AddAtomA(LPCSTR);
+ATOM        WINAPI AddAtomW(LPCWSTR);
+#define     AddAtom WINELIB_NAME_AW(AddAtom)
+UINT      WINAPI CompareStringA(DWORD,DWORD,LPCSTR,DWORD,LPCSTR,DWORD);
+UINT      WINAPI CompareStringW(DWORD,DWORD,LPCWSTR,DWORD,LPCWSTR,DWORD);
+#define     CompareString WINELIB_NAME_AW(CompareString)
+WIN_BOOL      WINAPI CreateDirectoryA(LPCSTR,LPSECURITY_ATTRIBUTES);
+WIN_BOOL      WINAPI CreateDirectoryW(LPCWSTR,LPSECURITY_ATTRIBUTES);
+#define     CreateDirectory WINELIB_NAME_AW(CreateDirectory)
+WIN_BOOL      WINAPI CreateDirectoryExA(LPCSTR,LPCSTR,LPSECURITY_ATTRIBUTES);
+WIN_BOOL      WINAPI CreateDirectoryExW(LPCWSTR,LPCWSTR,LPSECURITY_ATTRIBUTES);
+#define     CreateDirectoryEx WINELIB_NAME_AW(CreateDirectoryEx)
+WIN_BOOL        WINAPI DefineDosDeviceA(DWORD,LPCSTR,LPCSTR);
+#define     DefineHandleTable(w) ((w),TRUE)
+ATOM        WINAPI DeleteAtom(ATOM);
+WIN_BOOL      WINAPI DeleteFileA(LPCSTR);
+WIN_BOOL      WINAPI DeleteFileW(LPCWSTR);
+#define     DeleteFile WINELIB_NAME_AW(DeleteFile)
+void        WINAPI FatalAppExitA(UINT,LPCSTR);
+void        WINAPI FatalAppExitW(UINT,LPCWSTR);
+#define     FatalAppExit WINELIB_NAME_AW(FatalAppExit)
+ATOM        WINAPI FindAtomA(LPCSTR);
+ATOM        WINAPI FindAtomW(LPCWSTR);
+#define     FindAtom WINELIB_NAME_AW(FindAtom)
+WIN_BOOL      WINAPI FindClose(HANDLE);
+HANDLE16    WINAPI FindFirstFile16(LPCSTR,LPWIN32_FIND_DATAA);
+HANDLE    WINAPI FindFirstFileA(LPCSTR,LPWIN32_FIND_DATAA);
+HANDLE    WINAPI FindFirstFileW(LPCWSTR,LPWIN32_FIND_DATAW);
+#define     FindFirstFile WINELIB_NAME_AW(FindFirstFile)
+WIN_BOOL16      WINAPI FindNextFile16(HANDLE16,LPWIN32_FIND_DATAA);
+WIN_BOOL      WINAPI FindNextFileA(HANDLE,LPWIN32_FIND_DATAA);
+WIN_BOOL      WINAPI FindNextFileW(HANDLE,LPWIN32_FIND_DATAW);
+#define     FindNextFile WINELIB_NAME_AW(FindNextFile)
+HRSRC     WINAPI FindResourceA(HMODULE,LPCSTR,LPCSTR);
+HRSRC     WINAPI FindResourceW(HMODULE,LPCWSTR,LPCWSTR);
+#define     FindResource WINELIB_NAME_AW(FindResource)
+VOID        WINAPI FreeLibrary16(HINSTANCE16);
+WIN_BOOL      WINAPI FreeLibrary(HMODULE);
+#define     FreeModule(handle) FreeLibrary(handle)
+#define     FreeProcInstance(proc) /*nothing*/
+WIN_BOOL      WINAPI FreeResource(HGLOBAL);
+UINT      WINAPI GetAtomNameA(ATOM,LPSTR,INT);
+UINT      WINAPI GetAtomNameW(ATOM,LPWSTR,INT);
+#define     GetAtomName WINELIB_NAME_AW(GetAtomName)
+UINT      WINAPI GetCurrentDirectoryA(UINT,LPSTR);
+UINT      WINAPI GetCurrentDirectoryW(UINT,LPWSTR);
+#define     GetCurrentDirectory WINELIB_NAME_AW(GetCurrentDirectory)
+WIN_BOOL      WINAPI GetDiskFreeSpaceA(LPCSTR,LPDWORD,LPDWORD,LPDWORD,LPDWORD);
+WIN_BOOL      WINAPI GetDiskFreeSpaceW(LPCWSTR,LPDWORD,LPDWORD,LPDWORD,LPDWORD);
+#define     GetDiskFreeSpace WINELIB_NAME_AW(GetDiskFreeSpace)
+WIN_BOOL      WINAPI GetDiskFreeSpaceExA(LPCSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER);
+WIN_BOOL      WINAPI GetDiskFreeSpaceExW(LPCWSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER);
+#define     GetDiskFreeSpaceEx WINELIB_NAME_AW(GetDiskFreeSpaceEx)
+UINT      WINAPI GetDriveTypeA(LPCSTR);
+UINT      WINAPI GetDriveTypeW(LPCWSTR);
+#define     GetDriveType WINELIB_NAME_AW(GetDriveType)
+DWORD       WINAPI GetFileAttributesA(LPCSTR);
+DWORD       WINAPI GetFileAttributesW(LPCWSTR);
+#define     GetFileAttributes WINELIB_NAME_AW(GetFileAttributes)
+#define     GetFreeSpace(w) (0x100000L)
+UINT      WINAPI GetLogicalDriveStringsA(UINT,LPSTR);
+UINT      WINAPI GetLogicalDriveStringsW(UINT,LPWSTR);
+#define     GetLogicalDriveStrings WINELIB_NAME_AW(GetLogicalDriveStrings)
+INT       WINAPI GetLocaleInfoA(LCID,LCTYPE,LPSTR,INT);
+INT       WINAPI GetLocaleInfoW(LCID,LCTYPE,LPWSTR,INT);
+#define     GetLocaleInfo WINELIB_NAME_AW(GetLocaleInfo)
+DWORD       WINAPI GetModuleFileNameA(HMODULE,LPSTR,DWORD);
+DWORD       WINAPI GetModuleFileNameW(HMODULE,LPWSTR,DWORD);
+#define     GetModuleFileName WINELIB_NAME_AW(GetModuleFileName)
+HMODULE     WINAPI GetModuleHandleA(LPCSTR);
+HMODULE     WINAPI GetModuleHandleW(LPCWSTR);
+#define     GetModuleHandle WINELIB_NAME_AW(GetModuleHandle)
+WIN_BOOL        WINAPI GetOverlappedResult(HANDLE,LPOVERLAPPED,LPDWORD,WIN_BOOL);
+UINT        WINAPI GetPrivateProfileIntA(LPCSTR,LPCSTR,INT,LPCSTR);
+UINT        WINAPI GetPrivateProfileIntW(LPCWSTR,LPCWSTR,INT,LPCWSTR);
+#define     GetPrivateProfileInt WINELIB_NAME_AW(GetPrivateProfileInt)
+INT         WINAPI GetPrivateProfileSectionA(LPCSTR,LPSTR,DWORD,LPCSTR);
+INT         WINAPI GetPrivateProfileSectionW(LPCWSTR,LPWSTR,DWORD,LPCWSTR);
+#define     GetPrivateProfileSection WINELIB_NAME_AW(GetPrivateProfileSection)
+DWORD       WINAPI GetPrivateProfileSectionNamesA(LPSTR,DWORD,LPCSTR);
+DWORD       WINAPI GetPrivateProfileSectionNamesW(LPWSTR,DWORD,LPCWSTR);
+#define     GetPrivateProfileSectionNames WINELIB_NAME_AW(GetPrivateProfileSectionNames)
+INT       WINAPI GetPrivateProfileStringA(LPCSTR,LPCSTR,LPCSTR,LPSTR,UINT,LPCSTR);
+INT       WINAPI GetPrivateProfileStringW(LPCWSTR,LPCWSTR,LPCWSTR,LPWSTR,UINT,LPCWSTR);
+#define     GetPrivateProfileString WINELIB_NAME_AW(GetPrivateProfileString)
+WIN_BOOL      WINAPI GetPrivateProfileStructA(LPCSTR,LPCSTR,LPVOID,UINT,LPCSTR);
+WIN_BOOL      WINAPI GetPrivateProfileStructW(LPCWSTR,LPCWSTR,LPVOID,UINT,LPCWSTR);
+#define     GetPrivateProfileStruct WINELIB_NAME_AW(GetPrivateProfileStruct)
+FARPROC   WINAPI GetProcAddress(HMODULE,LPCSTR);
+UINT      WINAPI GetProfileIntA(LPCSTR,LPCSTR,INT);
+UINT      WINAPI GetProfileIntW(LPCWSTR,LPCWSTR,INT);
+#define     GetProfileInt WINELIB_NAME_AW(GetProfileInt)
+INT       WINAPI GetProfileSectionA(LPCSTR,LPSTR,DWORD);
+INT       WINAPI GetProfileSectionW(LPCWSTR,LPWSTR,DWORD);
+#define     GetProfileSection WINELIB_NAME_AW(GetProfileSection)
+INT       WINAPI GetProfileStringA(LPCSTR,LPCSTR,LPCSTR,LPSTR,UINT);
+INT       WINAPI GetProfileStringW(LPCWSTR,LPCWSTR,LPCWSTR,LPWSTR,UINT);
+#define     GetProfileString WINELIB_NAME_AW(GetProfileString)
+VOID        WINAPI GetStartupInfoA(LPSTARTUPINFOA);
+VOID        WINAPI GetStartupInfoW(LPSTARTUPINFOW);
+#define     GetStartupInfo WINELIB_NAME_AW(GetStartupInfo)
+WIN_BOOL      WINAPI GetStringTypeA(LCID,DWORD,LPCSTR,INT,LPWORD);
+WIN_BOOL      WINAPI GetStringTypeW(DWORD,LPCWSTR,INT,LPWORD);
+#define     GetStringType WINELIB_NAME_AW(GetStringType)
+UINT      WINAPI GetSystemDirectoryA(LPSTR,UINT);
+UINT      WINAPI GetSystemDirectoryW(LPWSTR,UINT);
+#define     GetSystemDirectory WINELIB_NAME_AW(GetSystemDirectory)
+UINT      WINAPI GetTempFileNameA(LPCSTR,LPCSTR,UINT,LPSTR);
+UINT      WINAPI GetTempFileNameW(LPCWSTR,LPCWSTR,UINT,LPWSTR);
+#define     GetTempFileName WINELIB_NAME_AW(GetTempFileName)
+UINT      WINAPI GetTempPathA(UINT,LPSTR);
+UINT      WINAPI GetTempPathW(UINT,LPWSTR);
+#define     GetTempPath WINELIB_NAME_AW(GetTempPath)
+LONG        WINAPI GetVersion(void);
+WIN_BOOL      WINAPI GetExitCodeProcess(HANDLE,LPDWORD);
+WIN_BOOL      WINAPI GetVolumeInformationA(LPCSTR,LPSTR,DWORD,LPDWORD,LPDWORD,LPDWORD,LPSTR,DWORD);
+WIN_BOOL      WINAPI GetVolumeInformationW(LPCWSTR,LPWSTR,DWORD,LPDWORD,LPDWORD,LPDWORD,LPWSTR,DWORD);
+#define     GetVolumeInformation WINELIB_NAME_AW(GetVolumeInformation)
+UINT      WINAPI GetWindowsDirectoryA(LPSTR,UINT);
+UINT      WINAPI GetWindowsDirectoryW(LPWSTR,UINT);
+#define     GetWindowsDirectory WINELIB_NAME_AW(GetWindowsDirectory)
+HGLOBAL16   WINAPI GlobalAlloc16(UINT16,DWORD);
+HGLOBAL   WINAPI GlobalAlloc(UINT,DWORD);
+DWORD       WINAPI GlobalCompact(DWORD);
+UINT      WINAPI GlobalFlags(HGLOBAL);
+HGLOBAL16   WINAPI GlobalFree16(HGLOBAL16);
+HGLOBAL   WINAPI GlobalFree(HGLOBAL);
+HGLOBAL   WINAPI GlobalHandle(LPCVOID);
+WORD        WINAPI GlobalFix16(HGLOBAL16);
+VOID        WINAPI GlobalFix(HGLOBAL);
+LPVOID      WINAPI GlobalLock16(HGLOBAL16);
+LPVOID      WINAPI GlobalLock(HGLOBAL);
+HGLOBAL   WINAPI GlobalReAlloc(HGLOBAL,DWORD,UINT);
+DWORD       WINAPI GlobalSize16(HGLOBAL16);
+DWORD       WINAPI GlobalSize(HGLOBAL);
+VOID        WINAPI GlobalUnfix16(HGLOBAL16);
+VOID        WINAPI GlobalUnfix(HGLOBAL);
+WIN_BOOL16      WINAPI GlobalUnlock16(HGLOBAL16);
+WIN_BOOL      WINAPI GlobalUnlock(HGLOBAL);
+WIN_BOOL16      WINAPI GlobalUnWire16(HGLOBAL16);
+WIN_BOOL      WINAPI GlobalUnWire(HGLOBAL);
+SEGPTR      WINAPI GlobalWire16(HGLOBAL16);
+LPVOID      WINAPI GlobalWire(HGLOBAL);
+WIN_BOOL      WINAPI InitAtomTable(DWORD);
+WIN_BOOL      WINAPI IsBadCodePtr(FARPROC);
+WIN_BOOL      WINAPI IsBadHugeReadPtr(LPCVOID,UINT);
+WIN_BOOL      WINAPI IsBadHugeWritePtr(LPVOID,UINT);
+WIN_BOOL      WINAPI IsBadReadPtr(LPCVOID,UINT);
+WIN_BOOL      WINAPI IsBadStringPtrA(LPCSTR,UINT);
+WIN_BOOL      WINAPI IsBadStringPtrW(LPCWSTR,UINT);
+#define     IsBadStringPtr WINELIB_NAME_AW(IsBadStringPtr)
+WIN_BOOL        WINAPI IsBadWritePtr(LPVOID,UINT);
+WIN_BOOL        WINAPI IsDBCSLeadByte(BYTE);
+WIN_BOOL        WINAPI IsDebuggerPresent(void);
+HINSTANCE16 WINAPI LoadLibrary16(LPCSTR);
+HMODULE   WINAPI LoadLibraryA(LPCSTR);
+HMODULE   WINAPI LoadLibraryW(LPCWSTR);
+#define     LoadLibrary WINELIB_NAME_AW(LoadLibrary)
+HMODULE   WINAPI LoadLibraryExA(LPCSTR,HANDLE,DWORD);
+HMODULE   WINAPI LoadLibraryExW(LPCWSTR,HANDLE,DWORD);
+#define     LoadLibraryEx WINELIB_NAME_AW(LoadLibraryEx)
+HINSTANCE16 WINAPI LoadModule16(LPCSTR,LPVOID);
+HINSTANCE WINAPI LoadModule(LPCSTR,LPVOID);
+HGLOBAL   WINAPI LoadResource(HMODULE,HRSRC);
+HLOCAL    WINAPI LocalAlloc(UINT,DWORD);
+UINT      WINAPI LocalCompact(UINT);
+UINT      WINAPI LocalFlags(HLOCAL);
+HLOCAL    WINAPI LocalFree(HLOCAL);
+HLOCAL    WINAPI LocalHandle(LPCVOID);
+LPVOID      WINAPI LocalLock(HLOCAL);
+HLOCAL    WINAPI LocalReAlloc(HLOCAL,DWORD,UINT);
+UINT      WINAPI LocalShrink(HGLOBAL,UINT);
+UINT      WINAPI LocalSize(HLOCAL);
+WIN_BOOL      WINAPI LocalUnlock(HLOCAL);
+LPVOID      WINAPI LockResource(HGLOBAL);
+#define     LockSegment(handle) GlobalFix((HANDLE)(handle))
+#define     MakeProcInstance(proc,inst) (proc)
+HFILE16     WINAPI OpenFile16(LPCSTR,OFSTRUCT*,UINT16);
+HFILE     WINAPI OpenFile(LPCSTR,OFSTRUCT*,UINT);
+VOID        WINAPI OutputDebugStringA(LPCSTR);
+VOID        WINAPI OutputDebugStringW(LPCWSTR);
+#define     OutputDebugString WINELIB_NAME_AW(OutputDebugString)
+WIN_BOOL        WINAPI ReadProcessMemory(HANDLE, LPCVOID, LPVOID, DWORD, LPDWORD);
+WIN_BOOL        WINAPI RemoveDirectoryA(LPCSTR);
+WIN_BOOL        WINAPI RemoveDirectoryW(LPCWSTR);
+#define     RemoveDirectory WINELIB_NAME_AW(RemoveDirectory)
+WIN_BOOL      WINAPI SetCurrentDirectoryA(LPCSTR);
+WIN_BOOL      WINAPI SetCurrentDirectoryW(LPCWSTR);
+#define     SetCurrentDirectory WINELIB_NAME_AW(SetCurrentDirectory)
+UINT      WINAPI SetErrorMode(UINT);
+WIN_BOOL      WINAPI SetFileAttributesA(LPCSTR,DWORD);
+WIN_BOOL      WINAPI SetFileAttributesW(LPCWSTR,DWORD);
+#define     SetFileAttributes WINELIB_NAME_AW(SetFileAttributes)
+UINT      WINAPI SetHandleCount(UINT);
+#define     SetSwapAreaSize(w) (w)
+WIN_BOOL        WINAPI SetVolumeLabelA(LPCSTR,LPCSTR);
+WIN_BOOL        WINAPI SetVolumeLabelW(LPCWSTR,LPCWSTR);
+#define     SetVolumeLabel WINELIB_NAME_AW(SetVolumeLabel)
+DWORD       WINAPI SizeofResource(HMODULE,HRSRC);
+#define     UnlockSegment(handle) GlobalUnfix((HANDLE)(handle))
+WIN_BOOL      WINAPI WritePrivateProfileSectionA(LPCSTR,LPCSTR,LPCSTR);
+WIN_BOOL      WINAPI WritePrivateProfileSectionW(LPCWSTR,LPCWSTR,LPCWSTR);
+#define     WritePrivateProfileSection WINELIB_NAME_AW(WritePrivateProfileSection)
+WIN_BOOL      WINAPI WritePrivateProfileStringA(LPCSTR,LPCSTR,LPCSTR,LPCSTR);
+WIN_BOOL      WINAPI WritePrivateProfileStringW(LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR);
+#define     WritePrivateProfileString WINELIB_NAME_AW(WritePrivateProfileString)
+WIN_BOOL	     WINAPI WriteProfileSectionA(LPCSTR,LPCSTR);
+WIN_BOOL	     WINAPI WriteProfileSectionW(LPCWSTR,LPCWSTR);
+#define     WritePrivateProfileSection WINELIB_NAME_AW(WritePrivateProfileSection)
+WIN_BOOL      WINAPI WritePrivateProfileStructA(LPCSTR,LPCSTR,LPVOID,UINT,LPCSTR);
+WIN_BOOL      WINAPI WritePrivateProfileStructW(LPCWSTR,LPCWSTR,LPVOID,UINT,LPCWSTR);
+#define     WritePrivateProfileStruct WINELIB_NAME_AW(WritePrivateProfileStruct)
+WIN_BOOL        WINAPI WriteProcessMemory(HANDLE, LPVOID, LPVOID, DWORD, LPDWORD);
+WIN_BOOL        WINAPI WriteProfileStringA(LPCSTR,LPCSTR,LPCSTR);
+WIN_BOOL        WINAPI WriteProfileStringW(LPCWSTR,LPCWSTR,LPCWSTR);
+#define     WriteProfileString WINELIB_NAME_AW(WriteProfileString)
+#define     Yield32()
+LPSTR       WINAPI lstrcatA(LPSTR,LPCSTR);
+LPWSTR      WINAPI lstrcatW(LPWSTR,LPCWSTR);
+#define     lstrcat WINELIB_NAME_AW(lstrcat)
+LPSTR       WINAPI lstrcpyA(LPSTR,LPCSTR);
+LPWSTR      WINAPI lstrcpyW(LPWSTR,LPCWSTR);
+#define     lstrcpy WINELIB_NAME_AW(lstrcpy)
+LPSTR       WINAPI lstrcpynA(LPSTR,LPCSTR,INT);
+LPWSTR      WINAPI lstrcpynW(LPWSTR,LPCWSTR,INT);
+#define     lstrcpyn WINELIB_NAME_AW(lstrcpyn)
+INT       WINAPI lstrlenA(LPCSTR);
+INT       WINAPI lstrlenW(LPCWSTR);
+#define     lstrlen WINELIB_NAME_AW(lstrlen)
+HINSTANCE WINAPI WinExec(LPCSTR,UINT);
+LONG        WINAPI _hread(HFILE,LPVOID,LONG);
+LONG        WINAPI _hwrite(HFILE,LPCSTR,LONG);
+HFILE     WINAPI _lcreat(LPCSTR,INT);
+HFILE     WINAPI _lclose(HFILE);
+LONG        WINAPI _llseek(HFILE,LONG,INT);
+HFILE     WINAPI _lopen(LPCSTR,INT);
+UINT      WINAPI _lread(HFILE,LPVOID,UINT);
+UINT      WINAPI _lwrite(HFILE,LPCSTR,UINT);
+SEGPTR      WINAPI WIN16_GlobalLock16(HGLOBAL16);
+INT       WINAPI lstrcmpA(LPCSTR,LPCSTR);
+INT       WINAPI lstrcmpW(LPCWSTR,LPCWSTR);
+#define     lstrcmp WINELIB_NAME_AW(lstrcmp)
+INT       WINAPI lstrcmpiA(LPCSTR,LPCSTR);
+INT       WINAPI lstrcmpiW(LPCWSTR,LPCWSTR);
+#define     lstrcmpi WINELIB_NAME_AW(lstrcmpi)
+
+/* compatibility macros */
+#define     FillMemory RtlFillMemory
+#define     MoveMemory RtlMoveMemory
+#define     ZeroMemory RtlZeroMemory
+#define     CopyMemory RtlCopyMemory
+
+DWORD       WINAPI GetCurrentProcessId(void);
+DWORD       WINAPI GetCurrentThreadId(void);
+DWORD       WINAPI GetLastError(void);
+HANDLE      WINAPI GetProcessHeap(void);
+PVOID       WINAPI InterlockedCompareExchange(PVOID*,PVOID,PVOID);
+LONG        WINAPI InterlockedDecrement(PLONG);
+LONG        WINAPI InterlockedExchange(PLONG,LONG);
+LONG        WINAPI InterlockedExchangeAdd(PLONG,LONG);
+LONG        WINAPI InterlockedIncrement(PLONG);
+VOID        WINAPI SetLastError(DWORD);
+
+#ifdef __WINE__
+#define GetCurrentProcess() ((HANDLE)0xffffffff)
+#define GetCurrentThread()  ((HANDLE)0xfffffffe)
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* __WINE_WINBASE_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/windef.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,656 @@
+/*
+ * Basic types definitions
+ *
+ * Copyright 1996 Alexandre Julliard
+ */
+
+#ifndef __WINE_WINDEF_H
+#define __WINE_WINDEF_H
+
+#ifdef __WINE__
+# include "config.h"
+# undef UNICODE
+#endif
+
+#ifdef _EGCS_
+#define __stdcall
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Misc. constants. */
+
+#ifdef FALSE
+#undef FALSE
+#endif
+#define FALSE 0
+
+#ifdef TRUE
+#undef TRUE
+#endif
+#define TRUE  1
+
+#ifdef NULL
+#undef NULL
+#endif
+#define NULL  0
+
+/* Macros to map Winelib names to the correct implementation name */
+/* depending on __WINE__ and UNICODE macros.                      */
+/* Note that Winelib is purely Win32.                             */
+
+#ifdef __WINE__
+# define WINELIB_NAME_AW(func) \
+    func##_must_be_suffixed_with_W_or_A_in_this_context \
+    func##_must_be_suffixed_with_W_or_A_in_this_context
+#else  /* __WINE__ */
+# ifdef UNICODE
+#  define WINELIB_NAME_AW(func) func##W
+# else
+#  define WINELIB_NAME_AW(func) func##A
+# endif  /* UNICODE */
+#endif  /* __WINE__ */
+
+#ifdef __WINE__
+# define DECL_WINELIB_TYPE_AW(type)  /* nothing */
+#else   /* __WINE__ */
+# define DECL_WINELIB_TYPE_AW(type)  typedef WINELIB_NAME_AW(type) type;
+#endif  /* __WINE__ */
+
+#ifndef NONAMELESSSTRUCT
+# if defined(__WINE__) || !defined(_FORCENAMELESSSTRUCT)
+#  define NONAMELESSSTRUCT
+# endif
+#endif /* !defined(NONAMELESSSTRUCT) */
+
+#ifndef NONAMELESSUNION
+# if defined(__WINE__) || !defined(_FORCENAMELESSUNION) || !defined(__cplusplus)
+#  define NONAMELESSUNION
+# endif
+#endif /* !defined(NONAMELESSUNION) */
+
+#ifndef NONAMELESSSTRUCT
+#define DUMMYSTRUCTNAME
+#define DUMMYSTRUCTNAME1
+#define DUMMYSTRUCTNAME2
+#define DUMMYSTRUCTNAME3
+#define DUMMYSTRUCTNAME4
+#define DUMMYSTRUCTNAME5
+#else /* !defined(NONAMELESSSTRUCT) */
+#define DUMMYSTRUCTNAME   s
+#define DUMMYSTRUCTNAME1  s1
+#define DUMMYSTRUCTNAME2  s2
+#define DUMMYSTRUCTNAME3  s3
+#define DUMMYSTRUCTNAME4  s4
+#define DUMMYSTRUCTNAME5  s5
+#endif /* !defined(NONAMELESSSTRUCT) */
+
+#ifndef NONAMELESSUNION
+#define DUMMYUNIONNAME
+#define DUMMYUNIONNAME1
+#define DUMMYUNIONNAME2
+#define DUMMYUNIONNAME3
+#define DUMMYUNIONNAME4
+#define DUMMYUNIONNAME5
+#else /* !defined(NONAMELESSUNION) */
+#define DUMMYUNIONNAME   u
+#define DUMMYUNIONNAME1  u1
+#define DUMMYUNIONNAME2  u2
+#define DUMMYUNIONNAME3  u3
+#define DUMMYUNIONNAME4  u4
+#define DUMMYUNIONNAME5  u5
+#endif /* !defined(NONAMELESSUNION) */
+
+/* Calling conventions definitions */
+
+#ifdef __i386__
+# if defined(__GNUC__) && ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 7)))
+#  ifndef _EGCS_ 
+#define __stdcall __attribute__((__stdcall__))
+#define __cdecl   __attribute__((__cdecl__))
+#  define __RESTORE_ES  __asm__ __volatile__("pushl %ds\n\tpopl %es")
+#  endif
+# else
+//#  error You need gcc >= 2.7 to build Wine on a 386
+# endif
+#else 
+# define __stdcall
+# define __cdecl
+# define __RESTORE_ES
+#endif
+
+#define CALLBACK    __stdcall
+#define WINAPI      __stdcall
+#define APIPRIVATE  __stdcall
+#define PASCAL      __stdcall
+#define pascal      __stdcall
+#define _pascal     __stdcall
+#define _stdcall    __stdcall
+#define _fastcall   __stdcall
+#define __fastcall  __stdcall
+#define __export    __stdcall
+#define CDECL       __cdecl
+#define _CDECL      __cdecl
+#define cdecl       __cdecl
+#define _cdecl      __cdecl
+#define WINAPIV     __cdecl
+#define APIENTRY    WINAPI
+
+#define __declspec(x)
+#define dllimport
+#define dllexport
+
+#define CONST       const
+
+/* Standard data types. These are the same for emulator and library. */
+
+typedef void            VOID;
+typedef int             INT;
+typedef unsigned int    UINT;
+typedef unsigned short  WORD;
+typedef unsigned long   DWORD;
+typedef unsigned long   ULONG;
+typedef unsigned char   BYTE;
+typedef long            LONG;
+typedef short           SHORT;
+typedef unsigned short  USHORT;
+typedef char            CHAR;
+typedef unsigned char   UCHAR;
+
+typedef LONG SCODE;
+
+/* Some systems might have wchar_t, but we really need 16 bit characters */
+typedef unsigned short  WCHAR;
+typedef int             WIN_BOOL;
+typedef double          DATE;
+typedef double          DOUBLE;
+typedef double          LONGLONG;
+typedef double          ULONGLONG;
+
+/* FIXME: Wine does not compile with strict on, therefore strict
+ * handles are presently only usable on machines where sizeof(UINT) ==
+ * sizeof(void*).  HANDLEs are supposed to be void* but a large amount
+ * of WINE code operates on HANDLES as if they are UINTs. So to WINE
+ * they exist as UINTs but to the Winelib user who turns on strict,
+ * they exist as void*. If there is a size difference between UINT and
+ * void* then things get ugly.  */
+#ifdef STRICT
+typedef VOID*           HANDLE;
+#else
+typedef UINT            HANDLE;
+#endif
+
+
+typedef HANDLE         *LPHANDLE;
+
+/* Integer types. These are the same for emulator and library. */
+typedef UINT            WPARAM;
+typedef LONG            LPARAM;
+typedef LONG            HRESULT;
+typedef LONG            LRESULT;
+typedef WORD            ATOM;
+typedef WORD            CATCHBUF[9];
+typedef WORD           *LPCATCHBUF;
+typedef HANDLE          HHOOK;
+typedef HANDLE          HMONITOR;
+typedef DWORD           LCID;
+typedef WORD            LANGID;
+typedef DWORD           LCTYPE;
+typedef float           FLOAT;
+
+/* Pointers types. These are the same for emulator and library. */
+/* winnt types */
+typedef VOID           *PVOID;
+typedef const void     *PCVOID;
+typedef CHAR           *PCHAR;
+typedef UCHAR          *PUCHAR;
+typedef BYTE           *PBYTE;
+typedef WORD           *PWORD;
+typedef USHORT         *PUSHORT;
+typedef SHORT          *PSHORT;
+typedef ULONG          *PULONG;
+typedef LONG           *PLONG;
+typedef DWORD          *PDWORD;
+/* common win32 types */
+typedef CHAR           *LPSTR;
+typedef CHAR           *PSTR;
+typedef const CHAR     *LPCSTR;
+typedef const CHAR     *PCSTR;
+typedef WCHAR          *LPWSTR;
+typedef WCHAR          *PWSTR;
+typedef const WCHAR    *LPCWSTR;
+typedef const WCHAR    *PCWSTR;
+typedef BYTE           *LPBYTE;
+typedef WORD           *LPWORD;
+typedef DWORD          *LPDWORD;
+typedef LONG           *LPLONG;
+typedef VOID           *LPVOID;
+typedef const VOID     *LPCVOID;
+typedef INT            *PINT;
+typedef INT            *LPINT;
+typedef UINT           *PUINT;
+typedef UINT           *LPUINT;
+typedef FLOAT          *PFLOAT;
+typedef FLOAT          *LPFLOAT;
+typedef WIN_BOOL           *PWIN_BOOL;
+typedef WIN_BOOL           *LPWIN_BOOL;
+
+/* Special case: a segmented pointer is just a pointer in the user's code. */
+
+#ifdef __WINE__
+typedef DWORD SEGPTR;
+#else
+typedef void* SEGPTR;
+#endif /* __WINE__ */
+
+/* Handle types that exist both in Win16 and Win32. */
+
+#ifdef STRICT
+#define DECLARE_HANDLE(a) \
+	typedef struct a##__ { int unused; } *a; \
+	typedef a *P##a; \
+	typedef a *LP##a
+#else /*STRICT*/
+#define DECLARE_HANDLE(a) \
+	typedef HANDLE a; \
+	typedef a *P##a; \
+	typedef a *LP##a
+#endif /*STRICT*/
+
+DECLARE_HANDLE(HACMDRIVERID);
+DECLARE_HANDLE(HACMDRIVER);
+DECLARE_HANDLE(HACMOBJ);
+DECLARE_HANDLE(HACMSTREAM);
+DECLARE_HANDLE(HMETAFILEPICT);
+
+DECLARE_HANDLE(HACCEL);
+DECLARE_HANDLE(HBITMAP);
+DECLARE_HANDLE(HBRUSH);
+DECLARE_HANDLE(HCOLORSPACE);
+DECLARE_HANDLE(HCURSOR);
+DECLARE_HANDLE(HDC);
+DECLARE_HANDLE(HDROP);
+DECLARE_HANDLE(HDRVR);
+DECLARE_HANDLE(HDWP);
+DECLARE_HANDLE(HENHMETAFILE);
+DECLARE_HANDLE(HFILE);
+DECLARE_HANDLE(HFONT);
+DECLARE_HANDLE(HICON);
+DECLARE_HANDLE(HINSTANCE);
+DECLARE_HANDLE(HKEY);
+DECLARE_HANDLE(HMENU);
+DECLARE_HANDLE(HMETAFILE);
+DECLARE_HANDLE(HMIDI);
+DECLARE_HANDLE(HMIDIIN);
+DECLARE_HANDLE(HMIDIOUT);
+DECLARE_HANDLE(HMIDISTRM);
+DECLARE_HANDLE(HMIXER);
+DECLARE_HANDLE(HMIXEROBJ);
+DECLARE_HANDLE(HMMIO);
+DECLARE_HANDLE(HPALETTE);
+DECLARE_HANDLE(HPEN);
+DECLARE_HANDLE(HQUEUE);
+DECLARE_HANDLE(HRGN);
+DECLARE_HANDLE(HRSRC);
+DECLARE_HANDLE(HTASK);
+DECLARE_HANDLE(HWAVE);
+DECLARE_HANDLE(HWAVEIN);
+DECLARE_HANDLE(HWAVEOUT);
+DECLARE_HANDLE(HWINSTA);
+DECLARE_HANDLE(HDESK);
+DECLARE_HANDLE(HWND);
+DECLARE_HANDLE(HKL);
+DECLARE_HANDLE(HIC);
+DECLARE_HANDLE(HRASCONN);
+
+/* Handle types that must remain interchangeable even with strict on */
+
+typedef HINSTANCE HMODULE;
+typedef HANDLE HGDIOBJ;
+typedef HANDLE HGLOBAL;
+typedef HANDLE HLOCAL;
+typedef HANDLE GLOBALHANDLE;
+typedef HANDLE LOCALHANDLE;
+
+/* Callback function pointers types */
+//WIN_BOOL CALLBACK DATEFMT_ENUMPROCA(LPSTR);
+
+typedef WIN_BOOL  CALLBACK  (* DATEFMT_ENUMPROCA)(LPSTR);
+typedef WIN_BOOL    CALLBACK (* DATEFMT_ENUMPROCW)(LPWSTR);
+DECL_WINELIB_TYPE_AW(DATEFMT_ENUMPROC)
+typedef WIN_BOOL    CALLBACK (*DLGPROC)(HWND,UINT,WPARAM,LPARAM);
+typedef LRESULT CALLBACK (*DRIVERPROC)(DWORD,HDRVR,UINT,LPARAM,LPARAM);
+typedef INT     CALLBACK (*EDITWORDBREAKPROCA)(LPSTR,INT,INT,INT);
+typedef INT     CALLBACK (*EDITWORDBREAKPROCW)(LPWSTR,INT,INT,INT);
+DECL_WINELIB_TYPE_AW(EDITWORDBREAKPROC)
+typedef LRESULT CALLBACK (*FARPROC)();
+typedef INT     CALLBACK (*PROC)();
+typedef WIN_BOOL    CALLBACK (*GRAYSTRINGPROC)(HDC,LPARAM,INT);
+typedef LRESULT CALLBACK (*HOOKPROC)(INT,WPARAM,LPARAM);
+typedef WIN_BOOL    CALLBACK (*PROPENUMPROCA)(HWND,LPCSTR,HANDLE);
+typedef WIN_BOOL    CALLBACK (*PROPENUMPROCW)(HWND,LPCWSTR,HANDLE);
+DECL_WINELIB_TYPE_AW(PROPENUMPROC)
+typedef WIN_BOOL    CALLBACK (*PROPENUMPROCEXA)(HWND,LPCSTR,HANDLE,LPARAM);
+typedef WIN_BOOL    CALLBACK (*PROPENUMPROCEXW)(HWND,LPCWSTR,HANDLE,LPARAM);
+DECL_WINELIB_TYPE_AW(PROPENUMPROCEX)
+typedef WIN_BOOL    CALLBACK (* TIMEFMT_ENUMPROCA)(LPSTR);
+typedef WIN_BOOL    CALLBACK (* TIMEFMT_ENUMPROCW)(LPWSTR);
+DECL_WINELIB_TYPE_AW(TIMEFMT_ENUMPROC)
+typedef VOID    CALLBACK (*TIMERPROC)(HWND,UINT,UINT,DWORD);
+typedef WIN_BOOL CALLBACK (*WNDENUMPROC)(HWND,LPARAM);
+typedef LRESULT CALLBACK (*WNDPROC)(HWND,UINT,WPARAM,LPARAM);
+
+/*----------------------------------------------------------------------------
+** FIXME:  Better isolate Wine's reliance on the xxx16 type definitions.
+**         For now, we just isolate them to make the situation clear.
+**--------------------------------------------------------------------------*/
+/*
+ * Basic type definitions for 16 bit variations on Windows types.
+ * These types are provided mostly to insure compatibility with
+ * 16 bit windows code.
+ */
+
+#ifndef __WINE_WINDEF16_H
+#define __WINE_WINDEF16_H
+
+#include "windef.h"
+
+/* Standard data types */
+
+typedef short           INT16;
+typedef unsigned short  UINT16;
+typedef unsigned short  WIN_BOOL16;
+
+typedef UINT16          HANDLE16;
+typedef HANDLE16       *LPHANDLE16;
+
+typedef UINT16          WPARAM16;
+typedef INT16          *LPINT16;
+typedef UINT16         *LPUINT16;
+
+#define DECLARE_HANDLE16(a) \
+	typedef HANDLE16 a##16; \
+	typedef a##16 *P##a##16; \
+	typedef a##16 *NP##a##16; \
+	typedef a##16 *LP##a##16 
+
+DECLARE_HANDLE16(HACMDRIVERID);
+DECLARE_HANDLE16(HACMDRIVER);
+DECLARE_HANDLE16(HACMOBJ);
+DECLARE_HANDLE16(HACMSTREAM);
+DECLARE_HANDLE16(HMETAFILEPICT);
+
+DECLARE_HANDLE16(HACCEL);
+DECLARE_HANDLE16(HBITMAP);
+DECLARE_HANDLE16(HBRUSH);
+DECLARE_HANDLE16(HCOLORSPACE);
+DECLARE_HANDLE16(HCURSOR);
+DECLARE_HANDLE16(HDC);
+DECLARE_HANDLE16(HDROP);
+DECLARE_HANDLE16(HDRVR);
+DECLARE_HANDLE16(HDWP);
+DECLARE_HANDLE16(HENHMETAFILE);
+DECLARE_HANDLE16(HFILE);
+DECLARE_HANDLE16(HFONT);
+DECLARE_HANDLE16(HICON);
+DECLARE_HANDLE16(HINSTANCE);
+DECLARE_HANDLE16(HKEY);
+DECLARE_HANDLE16(HMENU);
+DECLARE_HANDLE16(HMETAFILE);
+DECLARE_HANDLE16(HMIDI);
+DECLARE_HANDLE16(HMIDIIN);
+DECLARE_HANDLE16(HMIDIOUT);
+DECLARE_HANDLE16(HMIDISTRM);
+DECLARE_HANDLE16(HMIXER);
+DECLARE_HANDLE16(HMIXEROBJ);
+DECLARE_HANDLE16(HMMIO);
+DECLARE_HANDLE16(HPALETTE);
+DECLARE_HANDLE16(HPEN);
+DECLARE_HANDLE16(HQUEUE);
+DECLARE_HANDLE16(HRGN);
+DECLARE_HANDLE16(HRSRC);
+DECLARE_HANDLE16(HTASK);
+DECLARE_HANDLE16(HWAVE);
+DECLARE_HANDLE16(HWAVEIN);
+DECLARE_HANDLE16(HWAVEOUT);
+DECLARE_HANDLE16(HWINSTA);
+DECLARE_HANDLE16(HDESK);
+DECLARE_HANDLE16(HWND);
+DECLARE_HANDLE16(HKL);
+DECLARE_HANDLE16(HIC);
+DECLARE_HANDLE16(HRASCONN);
+#undef DECLARE_HANDLE16
+
+typedef HINSTANCE16 HMODULE16;
+typedef HANDLE16 HGDIOBJ16;
+typedef HANDLE16 HGLOBAL16;
+typedef HANDLE16 HLOCAL16;
+
+/* The SIZE structure */
+typedef struct
+{
+    INT16  cx;
+    INT16  cy;
+} SIZE16, *PSIZE16, *LPSIZE16;
+
+/* The POINT structure */
+
+typedef struct
+{
+    INT16  x;
+    INT16  y;
+} POINT16, *PPOINT16, *LPPOINT16;
+
+/* The RECT structure */
+
+typedef struct
+{
+    INT16  left;
+    INT16  top;
+    INT16  right;
+    INT16  bottom;
+} RECT16, *LPRECT16;
+
+/* Callback function pointers types */
+
+typedef LRESULT CALLBACK (*DRIVERPROC16)(DWORD,HDRVR16,UINT16,LPARAM,LPARAM);
+typedef WIN_BOOL16  CALLBACK (*DLGPROC16)(HWND16,UINT16,WPARAM16,LPARAM);
+typedef INT16   CALLBACK (*EDITWORDBREAKPROC16)(LPSTR,INT16,INT16,INT16);
+typedef LRESULT CALLBACK (*FARPROC16)();
+typedef INT16   CALLBACK (*PROC16)();
+typedef WIN_BOOL16  CALLBACK (*GRAYSTRINGPROC16)(HDC16,LPARAM,INT16);
+typedef LRESULT CALLBACK (*HOOKPROC16)(INT16,WPARAM16,LPARAM);
+typedef WIN_BOOL16  CALLBACK (*PROPENUMPROC16)(HWND16,SEGPTR,HANDLE16);
+typedef VOID    CALLBACK (*TIMERPROC16)(HWND16,UINT16,UINT16,DWORD);
+typedef LRESULT CALLBACK (*WNDENUMPROC16)(HWND16,LPARAM);
+typedef LRESULT CALLBACK (*WNDPROC16)(HWND16,UINT16,WPARAM16,LPARAM);
+
+#endif /* __WINE_WINDEF16_H */
+
+/* Define some empty macros for compatibility with Windows code. */
+
+#ifndef __WINE__
+#define NEAR
+#define FAR
+#define near
+#define far
+#define _near
+#define _far
+#define IN
+#define OUT
+#define OPTIONAL
+#endif  /* __WINE__ */
+
+/* Macro for structure packing. */
+
+#ifdef __GNUC__
+#ifndef _EGCS_
+#define WINE_PACKED   __attribute__((packed))
+#define WINE_UNUSED   __attribute__((unused))
+#define WINE_NORETURN __attribute__((noreturn))
+#endif
+#else
+#define WINE_PACKED    /* nothing */
+#define WINE_UNUSED    /* nothing */
+#define WINE_NORETURN  /* nothing */
+#endif
+
+/* Macros to split words and longs. */
+
+#define LOBYTE(w)              ((BYTE)(WORD)(w))
+#define HIBYTE(w)              ((BYTE)((WORD)(w) >> 8))
+
+#define LOWORD(l)              ((WORD)(DWORD)(l))
+#define HIWORD(l)              ((WORD)((DWORD)(l) >> 16))
+
+#define SLOWORD(l)             ((INT16)(LONG)(l))
+#define SHIWORD(l)             ((INT16)((LONG)(l) >> 16))
+
+#define MAKEWORD(low,high)     ((WORD)(((BYTE)(low)) | ((WORD)((BYTE)(high))) << 8))
+#define MAKELONG(low,high)     ((LONG)(((WORD)(low)) | (((DWORD)((WORD)(high))) << 16)))
+#define MAKELPARAM(low,high)   ((LPARAM)MAKELONG(low,high))
+#define MAKEWPARAM(low,high)   ((WPARAM)MAKELONG(low,high))
+#define MAKELRESULT(low,high)  ((LRESULT)MAKELONG(low,high))
+#define MAKEINTATOM(atom)      ((LPCSTR)MAKELONG((atom),0))
+
+#define SELECTOROF(ptr)     (HIWORD(ptr))
+#define OFFSETOF(ptr)       (LOWORD(ptr))
+
+#ifdef __WINE__
+/* macros to set parts of a DWORD (not in the Windows API) */
+#define SET_LOWORD(dw,val)  ((dw) = ((dw) & 0xffff0000) | LOWORD(val))
+#define SET_LOBYTE(dw,val)  ((dw) = ((dw) & 0xffffff00) | LOBYTE(val))
+#define SET_HIBYTE(dw,val)  ((dw) = ((dw) & 0xffff00ff) | (LOWORD(val) & 0xff00))
+#define ADD_LOWORD(dw,val)  ((dw) = ((dw) & 0xffff0000) | LOWORD((DWORD)(dw)+(val)))
+#endif
+
+/* Macros to access unaligned or wrong-endian WORDs and DWORDs. */
+/* Note: These macros are semantically broken, at least for wrc.  wrc
+   spits out data in the platform's current binary format, *not* in 
+   little-endian format.  These macros are used throughout the resource
+   code to load and store data to the resources.  Since it is unlikely 
+   that we'll ever be dealing with little-endian resource data, the 
+   byte-swapping nature of these macros has been disabled.  Rather than 
+   remove the use of these macros from the resource loading code, the
+   macros have simply been disabled.  In the future, someone may want 
+   to reactivate these macros for other purposes.  In that case, the
+   resource code will have to be modified to use different macros. */ 
+
+#if 1
+#define PUT_WORD(ptr,w)   (*(WORD *)(ptr) = (w))
+#define GET_WORD(ptr)     (*(WORD *)(ptr))
+#define PUT_DWORD(ptr,dw) (*(DWORD *)(ptr) = (dw))
+#define GET_DWORD(ptr)    (*(DWORD *)(ptr))
+#else
+#define PUT_WORD(ptr,w)   (*(BYTE *)(ptr) = LOBYTE(w), \
+                           *((BYTE *)(ptr) + 1) = HIBYTE(w))
+#define GET_WORD(ptr)     ((WORD)(*(BYTE *)(ptr) | \
+                                  (WORD)(*((BYTE *)(ptr)+1) << 8)))
+#define PUT_DWORD(ptr,dw) (PUT_WORD((ptr),LOWORD(dw)), \
+                           PUT_WORD((WORD *)(ptr)+1,HIWORD(dw)))
+#define GET_DWORD(ptr)    ((DWORD)(GET_WORD(ptr) | \
+                                   ((DWORD)GET_WORD((WORD *)(ptr)+1) << 16)))
+#endif  /* 1 */
+
+/* min and max macros */
+#define __max(a,b) (((a) > (b)) ? (a) : (b))
+#define __min(a,b) (((a) < (b)) ? (a) : (b))
+#ifndef max
+#define max(a,b)   (((a) > (b)) ? (a) : (b))
+#endif
+#ifndef min
+#define min(a,b)   (((a) < (b)) ? (a) : (b))
+#endif
+
+#define _MAX_PATH  260
+#define MAX_PATH   260
+#define _MAX_DRIVE 3
+#define _MAX_DIR   256
+#define _MAX_FNAME 255
+#define _MAX_EXT   256
+
+#define HFILE_ERROR16   ((HFILE16)-1)
+#define HFILE_ERROR     ((HFILE)-1)
+
+/* The SIZE structure */
+typedef struct tagSIZE
+{
+    INT  cx;
+    INT  cy;
+} SIZE, *PSIZE, *LPSIZE;
+
+
+typedef SIZE SIZEL, *PSIZEL, *LPSIZEL;
+
+#define CONV_SIZE16TO32(s16,s32) \
+            ((s32)->cx = (INT)(s16)->cx, (s32)->cy = (INT)(s16)->cy)
+#define CONV_SIZE32TO16(s32,s16) \
+            ((s16)->cx = (INT16)(s32)->cx, (s16)->cy = (INT16)(s32)->cy)
+
+/* The POINT structure */
+typedef struct tagPOINT
+{
+    LONG  x;
+    LONG  y;
+} POINT, *PPOINT, *LPPOINT;
+
+typedef struct _POINTL
+{
+    LONG x;
+    LONG y;
+} POINTL;
+
+#define CONV_POINT16TO32(p16,p32) \
+            ((p32)->x = (INT)(p16)->x, (p32)->y = (INT)(p16)->y)
+#define CONV_POINT32TO16(p32,p16) \
+            ((p16)->x = (INT16)(p32)->x, (p16)->y = (INT16)(p32)->y)
+
+#define MAKEPOINT16(l) (*((POINT16 *)&(l)))
+
+/* The POINTS structure */
+
+typedef struct tagPOINTS
+{
+	SHORT x;
+	SHORT y;
+} POINTS, *PPOINTS, *LPPOINTS;
+
+
+#define MAKEPOINTS(l)  (*((POINTS *)&(l)))
+
+
+/* The RECT structure */
+typedef struct tagRECT
+{
+    short  left;
+    short  top;
+    short  right;
+    short  bottom;
+} RECT, *PRECT, *LPRECT;
+typedef const RECT *LPCRECT;
+
+
+typedef struct tagRECTL
+{
+    LONG left;
+    LONG top;  
+    LONG right;
+    LONG bottom;
+} RECTL, *PRECTL, *LPRECTL;
+
+typedef const RECTL *LPCRECTL;
+
+#define CONV_RECT16TO32(r16,r32) \
+    ((r32)->left  = (INT)(r16)->left,  (r32)->top    = (INT)(r16)->top, \
+     (r32)->right = (INT)(r16)->right, (r32)->bottom = (INT)(r16)->bottom)
+#define CONV_RECT32TO16(r32,r16) \
+    ((r16)->left  = (INT16)(r32)->left,  (r16)->top    = (INT16)(r32)->top, \
+     (r16)->right = (INT16)(r32)->right, (r16)->bottom = (INT16)(r32)->bottom)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __WINE_WINDEF_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/windows.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,38 @@
+#ifndef __WINE_WINDOWS_H
+#define __WINE_WINDOWS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "windef.h"
+#include "winbase.h"
+#include "winuser.h"
+#include "shell.h"
+#include "winreg.h"
+#include "winnetwk.h"
+#include "winver.h"
+#include "lzexpand.h"
+#include "shellapi.h"
+#include "ole2.h"
+#include "winnls.h"
+#include "objbase.h"
+#include "winspool.h"
+
+#if 0
+  Where does this belong? Nobody uses this stuff anyway.
+typedef struct {
+	BYTE i;  /* much more .... */
+} KANJISTRUCT;
+typedef KANJISTRUCT *LPKANJISTRUCT;
+typedef KANJISTRUCT *NPKANJISTRUCT;
+typedef KANJISTRUCT *PKANJISTRUCT;
+
+
+#endif /* 0 */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* __WINE_WINDOWS_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/winerror.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,1658 @@
+#ifndef __WINE_WINERROR_H
+#define __WINE_WINERROR_H
+
+
+extern int WIN32_LastError;
+
+#define FACILITY_NULL      0
+#define FACILITY_RPC       1
+#define FACILITY_DISPATCH  2
+#define FACILITY_STORAGE   3
+#define FACILITY_ITF		4
+#define FACILITY_WIN32		7
+#define FACILITY_WINDOWS   8
+#define FACILITY_SSPI      9
+#define FACILITY_CONTROL   10
+#define FACILITY_CERT      11
+#define FACILITY_INTERNET  12
+
+#define SEVERITY_ERROR		1
+
+
+#define MAKE_HRESULT(sev,fac,code) \
+    ((HRESULT) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))) )
+#define MAKE_SCODE(sev,fac,code) \
+        ((SCODE) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))) )
+#define SUCCEEDED(stat) ((HRESULT)(stat)>=0)
+#define FAILED(stat) ((HRESULT)(stat)<0)
+
+#define HRESULT_CODE(hr) ((hr) & 0xFFFF)
+#define SCODE_CODE(sc)   ((sc) & 0xFFFF)
+
+#define HRESULT_FACILITY(hr)  (((hr) >> 16) & 0x1FFF)
+#define SCODE_FACILITY(sc)  (((sc) >> 16) & 0x1FFF)
+
+/* ERROR_UNKNOWN is a placeholder for error conditions which haven't
+ * been tested yet so we're not exactly sure what will be returned.
+ * All instances of ERROR_UNKNOWN should be tested under Win95/NT
+ * and replaced.
+ */
+#define ERROR_UNKNOWN               99999
+
+#define SEVERITY_SUCCESS    0
+#define SEVERITY_ERROR      1
+
+#define NO_ERROR                                           0
+#define ERROR_SUCCESS                                      0
+#define ERROR_INVALID_FUNCTION                             1
+#define ERROR_FILE_NOT_FOUND                               2
+#define ERROR_PATH_NOT_FOUND                               3
+#define ERROR_TOO_MANY_OPEN_FILES                          4
+#define ERROR_ACCESS_DENIED                                5
+#define ERROR_INVALID_HANDLE                               6
+#define ERROR_ARENA_TRASHED                                7
+#define ERROR_NOT_ENOUGH_MEMORY                            8
+#define ERROR_INVALID_BLOCK                                9
+#define ERROR_BAD_ENVIRONMENT                              10
+#define ERROR_BAD_FORMAT                                   11
+#define ERROR_INVALID_ACCESS                               12
+#define ERROR_INVALID_DATA                                 13
+#define ERROR_OUTOFMEMORY                                  14
+#define ERROR_INVALID_DRIVE                                15
+#define ERROR_CURRENT_DIRECTORY                            16
+#define ERROR_NOT_SAME_DEVICE                              17
+#define ERROR_NO_MORE_FILES                                18
+#define ERROR_WRITE_PROTECT                                19
+#define ERROR_BAD_UNIT                                     20
+#define ERROR_NOT_READY                                    21
+#define ERROR_BAD_COMMAND                                  22
+#define ERROR_CRC                                          23
+#define ERROR_BAD_LENGTH                                   24
+#define ERROR_SEEK                                         25
+#define ERROR_NOT_DOS_DISK                                 26
+#define ERROR_SECTOR_NOT_FOUND                             27
+#define ERROR_OUT_OF_PAPER                                 28
+#define ERROR_WRITE_FAULT                                  29
+#define ERROR_READ_FAULT                                   30
+#define ERROR_GEN_FAILURE                                  31
+#define ERROR_SHARING_VIOLATION                            32
+#define ERROR_LOCK_VIOLATION                               33
+#define ERROR_WRONG_DISK                                   34
+#define ERROR_SHARING_BUFFER_EXCEEDED                      36
+#define ERROR_HANDLE_EOF                                   38
+#define ERROR_HANDLE_DISK_FULL                             39
+#define ERROR_NOT_SUPPORTED                                50
+#define ERROR_REM_NOT_LIST                                 51
+#define ERROR_DUP_NAME                                     52
+#define ERROR_BAD_NETPATH                                  53
+#define ERROR_NETWORK_BUSY                                 54
+#define ERROR_DEV_NOT_EXIST                                55
+#define ERROR_TOO_MANY_CMDS                                56
+#define ERROR_ADAP_HDW_ERR                                 57
+#define ERROR_BAD_NET_RESP                                 58
+#define ERROR_UNEXP_NET_ERR                                59
+#define ERROR_BAD_REM_ADAP                                 60
+#define ERROR_PRINTQ_FULL                                  61
+#define ERROR_NO_SPOOL_SPACE                               62
+#define ERROR_PRINT_CANCELLED                              63
+#define ERROR_NETNAME_DELETED                              64
+#define ERROR_NETWORK_ACCESS_DENIED                        65
+#define ERROR_BAD_DEV_TYPE                                 66
+#define ERROR_BAD_NET_NAME                                 67
+#define ERROR_TOO_MANY_NAMES                               68
+#define ERROR_TOO_MANY_SESS                                69
+#define ERROR_SHARING_PAUSED                               70
+#define ERROR_REQ_NOT_ACCEP                                71
+#define ERROR_REDIR_PAUSED                                 72
+#define ERROR_FILE_EXISTS                                  80
+#define ERROR_CANNOT_MAKE                                  82
+#define ERROR_FAIL_I24                                     83
+#define ERROR_OUT_OF_STRUCTURES                            84
+#define ERROR_ALREADY_ASSIGNED                             85
+#define ERROR_INVALID_PASSWORD                             86
+#define ERROR_INVALID_PARAMETER                            87
+#define ERROR_NET_WRITE_FAULT                              88
+#define ERROR_NO_PROC_SLOTS                                89
+#define ERROR_TOO_MANY_SEMAPHORES                          100
+#define ERROR_EXCL_SEM_ALREADY_OWNED                       101
+#define ERROR_SEM_IS_SET                                   102
+#define ERROR_TOO_MANY_SEM_REQUESTS                        103
+#define ERROR_INVALID_AT_INTERRUPT_TIME                    104
+#define ERROR_SEM_OWNER_DIED                               105
+#define ERROR_SEM_USER_LIMIT                               106
+#define ERROR_DISK_CHANGE                                  107
+#define ERROR_DRIVE_LOCKED                                 108
+#define ERROR_BROKEN_PIPE                                  109
+#define ERROR_OPEN_FAILED                                  110
+#define ERROR_BUFFER_OVERFLOW                              111
+#define ERROR_DISK_FULL                                    112
+#define ERROR_NO_MORE_SEARCH_HANDLES                       113
+#define ERROR_INVALID_TARGET_HANDLE                        114
+#define ERROR_INVALID_CATEGORY                             117
+#define ERROR_INVALID_VERIFY_SWITCH                        118
+#define ERROR_BAD_DRIVER_LEVEL                             119
+#define ERROR_CALL_NOT_IMPLEMENTED                         120
+#define ERROR_SEM_TIMEOUT                                  121
+#define ERROR_INSUFFICIENT_BUFFER                          122
+#define ERROR_INVALID_NAME                                 123
+#define ERROR_INVALID_LEVEL                                124
+#define ERROR_NO_VOLUME_LABEL                              125
+#define ERROR_MOD_NOT_FOUND                                126
+#define ERROR_PROC_NOT_FOUND                               127
+#define ERROR_WAIT_NO_CHILDREN                             128
+#define ERROR_CHILD_NOT_COMPLETE                           129
+#define ERROR_DIRECT_ACCESS_HANDLE                         130
+#define ERROR_NEGATIVE_SEEK                                131
+#define ERROR_SEEK_ON_DEVICE                               132
+#define ERROR_IS_JOIN_TARGET                               133
+#define ERROR_IS_JOINED                                    134
+#define ERROR_IS_SUBSTED                                   135
+#define ERROR_NOT_JOINED                                   136
+#define ERROR_NOT_SUBSTED                                  137
+#define ERROR_JOIN_TO_JOIN                                 138
+#define ERROR_SUBST_TO_SUBST                               139
+#define ERROR_JOIN_TO_SUBST                                140
+#define ERROR_SUBST_TO_JOIN                                141
+#define ERROR_BUSY_DRIVE                                   142
+#define ERROR_SAME_DRIVE                                   143
+#define ERROR_DIR_NOT_ROOT                                 144
+#define ERROR_DIR_NOT_EMPTY                                145
+#define ERROR_IS_SUBST_PATH                                146
+#define ERROR_IS_JOIN_PATH                                 147
+#define ERROR_PATH_BUSY                                    148
+#define ERROR_IS_SUBST_TARGET                              149
+#define ERROR_SYSTEM_TRACE                                 150
+#define ERROR_INVALID_EVENT_COUNT                          151
+#define ERROR_TOO_MANY_MUXWAITERS                          152
+#define ERROR_INVALID_LIST_FORMAT                          153
+#define ERROR_LABEL_TOO_LONG                               154
+#define ERROR_TOO_MANY_TCBS                                155
+#define ERROR_SIGNAL_REFUSED                               156
+#define ERROR_DISCARDED                                    157
+#define ERROR_NOT_LOCKED                                   158
+#define ERROR_BAD_THREADID_ADDR                            159
+#define ERROR_BAD_ARGUMENTS                                160
+#define ERROR_BAD_PATHNAME                                 161
+#define ERROR_SIGNAL_PENDING                               162
+#define ERROR_MAX_THRDS_REACHED                            164
+#define ERROR_LOCK_FAILED                                  167
+#define ERROR_BUSY                                         170
+#define ERROR_CANCEL_VIOLATION                             173
+#define ERROR_ATOMIC_LOCKS_NOT_SUPPORTED                   174
+#define ERROR_INVALID_SEGMENT_NUMBER                       180
+#define ERROR_INVALID_ORDINAL                              182
+#define ERROR_ALREADY_EXISTS                               183
+#define ERROR_INVALID_FLAG_NUMBER                          186
+#define ERROR_SEM_NOT_FOUND                                187
+#define ERROR_INVALID_STARTING_CODESEG                     188
+#define ERROR_INVALID_STACKSEG                             189
+#define ERROR_INVALID_MODULETYPE                           190
+#define ERROR_INVALID_EXE_SIGNATURE                        191
+#define ERROR_EXE_MARKED_INVALID                           192
+#define ERROR_BAD_EXE_FORMAT                               193
+#define ERROR_ITERATED_DATA_EXCEEDS_64k                    194
+#define ERROR_INVALID_MINALLOCSIZE                         195
+#define ERROR_DYNLINK_FROM_INVALID_RING                    196
+#define ERROR_IOPL_NOT_ENABLED                             197
+#define ERROR_INVALID_SEGDPL                               198
+#define ERROR_AUTODATASEG_EXCEEDS_64k                      199
+#define ERROR_RING2SEG_MUST_BE_MOVABLE                     200
+#define ERROR_RELOC_CHAIN_XEEDS_SEGLIM                     201
+#define ERROR_INFLOOP_IN_RELOC_CHAIN                       202
+#define ERROR_ENVVAR_NOT_FOUND                             203
+#define ERROR_NO_SIGNAL_SENT                               205
+#define ERROR_FILENAME_EXCED_RANGE                         206
+#define ERROR_RING2_STACK_IN_USE                           207
+#define ERROR_META_EXPANSION_TOO_LONG                      208
+#define ERROR_INVALID_SIGNAL_NUMBER                        209
+#define ERROR_THREAD_1_INACTIVE                            210
+#define ERROR_LOCKED                                       212
+#define ERROR_TOO_MANY_MODULES                             214
+#define ERROR_NESTING_NOT_ALLOWED                          215
+#define ERROR_EXE_MACHINE_TYPE_MISMATCH                    216
+#define ERROR_BAD_PIPE                                     230
+#define ERROR_PIPE_BUSY                                    231
+#define ERROR_NO_DATA                                      232
+#define ERROR_PIPE_NOT_CONNECTED                           233
+#define ERROR_MORE_DATA                                    234
+#define ERROR_VC_DISCONNECTED                              240
+#define ERROR_INVALID_EA_NAME                              254
+#define ERROR_EA_LIST_INCONSISTENT                         255
+#define ERROR_NO_MORE_ITEMS                                259
+#define ERROR_CANNOT_COPY                                  266
+#define ERROR_DIRECTORY                                    267
+#define ERROR_EAS_DIDNT_FIT                                275
+#define ERROR_EA_FILE_CORRUPT                              276
+#define ERROR_EA_TABLE_FULL                                277
+#define ERROR_INVALID_EA_HANDLE                            278
+#define ERROR_EAS_NOT_SUPPORTED                            282
+#define ERROR_NOT_OWNER                                    288
+#define ERROR_TOO_MANY_POSTS                               298
+#define ERROR_PARTIAL_COPY                                 299
+#define ERROR_OPLOCK_NOT_GRANTED                           300
+#define ERROR_INVALID_OPLOCK_PROTOCOL                      301
+#define ERROR_MR_MID_NOT_FOUND                             317
+#define ERROR_INVALID_ADDRESS                              487
+#define ERROR_ARITHMETIC_OVERFLOW                          534
+#define ERROR_PIPE_CONNECTED                               535
+#define ERROR_PIPE_LISTENING                               536
+#define ERROR_EA_ACCESS_DENIED                             994
+#define ERROR_OPERATION_ABORTED                            995
+#define ERROR_IO_INCOMPLETE                                996
+#define ERROR_IO_PENDING                                   997
+#define ERROR_NOACCESS                                     998
+#define ERROR_SWAPERROR                                    999
+#define ERROR_STACK_OVERFLOW                               1001
+#define ERROR_INVALID_MESSAGE                              1002
+#define ERROR_CAN_NOT_COMPLETE                             1003
+#define ERROR_INVALID_FLAGS                                1004
+#define ERROR_UNRECOGNIZED_VOLUME                          1005
+#define ERROR_FILE_INVALID                                 1006
+#define ERROR_FULLSCREEN_MODE                              1007
+#define ERROR_NO_TOKEN                                     1008
+#define ERROR_BADDB                                        1009
+#define ERROR_BADKEY                                       1010
+#define ERROR_CANTOPEN                                     1011
+#define ERROR_CANTREAD                                     1012
+#define ERROR_CANTWRITE                                    1013
+#define ERROR_REGISTRY_RECOVERED                           1014
+#define ERROR_REGISTRY_CORRUPT                             1015
+#define ERROR_REGISTRY_IO_FAILED                           1016
+#define ERROR_NOT_REGISTRY_FILE                            1017
+#define ERROR_KEY_DELETED                                  1018
+#define ERROR_NO_LOG_SPACE                                 1019
+#define ERROR_KEY_HAS_CHILDREN                             1020
+#define ERROR_CHILD_MUST_BE_VOLATILE                       1021
+#define ERROR_NOTIFY_ENUM_DIR                              1022
+#define ERROR_DEPENDENT_SERVICES_RUNNING                   1051
+#define ERROR_INVALID_SERVICE_CONTROL                      1052
+#define ERROR_SERVICE_REQUEST_TIMEOUT                      1053
+#define ERROR_SERVICE_NO_THREAD                            1054
+#define ERROR_SERVICE_DATABASE_LOCKED                      1055
+#define ERROR_SERVICE_ALREADY_RUNNING                      1056
+#define ERROR_INVALID_SERVICE_ACCOUNT                      1057
+#define ERROR_SERVICE_DISABLED                             1058
+#define ERROR_CIRCULAR_DEPENDENCY                          1059
+#define ERROR_SERVICE_DOES_NOT_EXIST                       1060
+#define ERROR_SERVICE_CANNOT_ACCEPT_CTRL                   1061
+#define ERROR_SERVICE_NOT_ACTIVE                           1062
+#define ERROR_FAILED_SERVICE_CONTROLLER_CONNECT            1063
+#define ERROR_EXCEPTION_IN_SERVICE                         1064
+#define ERROR_DATABASE_DOES_NOT_EXIST                      1065
+#define ERROR_SERVICE_SPECIFIC_ERROR                       1066
+#define ERROR_PROCESS_ABORTED                              1067
+#define ERROR_SERVICE_DEPENDENCY_FAIL                      1068
+#define ERROR_SERVICE_LOGON_FAILED                         1069
+#define ERROR_SERVICE_START_HANG                           1070
+#define ERROR_INVALID_SERVICE_LOCK                         1071
+#define ERROR_SERVICE_MARKED_FOR_DELETE                    1072
+#define ERROR_SERVICE_EXISTS                               1073
+#define ERROR_ALREADY_RUNNING_LKG                          1074
+#define ERROR_SERVICE_DEPENDENCY_DELETED                   1075
+#define ERROR_BOOT_ALREADY_ACCEPTED                        1076
+#define ERROR_SERVICE_NEVER_STARTED                        1077
+#define ERROR_DUPLICATE_SERVICE_NAME                       1078
+#define ERROR_DIFFERENT_SERVICE_ACCOUNT                    1079
+#define ERROR_CANNOT_DETECT_DRIVER_FAILURE                 1080
+#define ERROR_CANNOT_DETECT_PROCESS_ABORT                  1081
+#define ERROR_NO_RECOVERY_PROGRAM                          1082
+#define ERROR_SERVICE_NOT_IN_EXE                           1083
+#define ERROR_END_OF_MEDIA                                 1100
+#define ERROR_FILEMARK_DETECTED                            1101
+#define ERROR_BEGINNING_OF_MEDIA                           1102
+#define ERROR_SETMARK_DETECTED                             1103
+#define ERROR_NO_DATA_DETECTED                             1104
+#define ERROR_PARTITION_FAILURE                            1105
+#define ERROR_INVALID_BLOCK_LENGTH                         1106
+#define ERROR_DEVICE_NOT_PARTITIONED                       1107
+#define ERROR_UNABLE_TO_LOCK_MEDIA                         1108
+#define ERROR_UNABLE_TO_UNLOAD_MEDIA                       1109
+#define ERROR_MEDIA_CHANGED                                1110
+#define ERROR_BUS_RESET                                    1111
+#define ERROR_NO_MEDIA_IN_DRIVE                            1112
+#define ERROR_NO_UNICODE_TRANSLATION                       1113
+#define ERROR_DLL_INIT_FAILED                              1114
+#define ERROR_SHUTDOWN_IN_PROGRESS                         1115
+#define ERROR_NO_SHUTDOWN_IN_PROGRESS                      1116
+#define ERROR_IO_DEVICE                                    1117
+#define ERROR_SERIAL_NO_DEVICE                             1118
+#define ERROR_IRQ_BUSY                                     1119
+#define ERROR_MORE_WRITES                                  1120
+#define ERROR_COUNTER_TIMEOUT                              1121
+#define ERROR_FLOPPY_ID_MARK_NOT_FOUND                     1122
+#define ERROR_FLOPPY_WRONG_CYLINDER                        1123
+#define ERROR_FLOPPY_UNKNOWN_ERROR                         1124
+#define ERROR_FLOPPY_BAD_REGISTERS                         1125
+#define ERROR_DISK_RECALIBRATE_FAILED                      1126
+#define ERROR_DISK_OPERATION_FAILED                        1127
+#define ERROR_DISK_RESET_FAILED                            1128
+#define ERROR_EOM_OVERFLOW                                 1129
+#define ERROR_NOT_ENOUGH_SERVER_MEMORY                     1130
+#define ERROR_POSSIBLE_DEADLOCK                            1131
+#define ERROR_MAPPED_ALIGNMENT                             1132
+#define ERROR_SET_POWER_STATE_VETOED                       1140
+#define ERROR_SET_POWER_STATE_FAILED                       1141
+#define ERROR_TOO_MANY_LINKS                               1142
+#define ERROR_OLD_WIN_VERSION                              1150
+#define ERROR_APP_WRONG_OS                                 1151
+#define ERROR_SINGLE_INSTANCE_APP                          1152
+#define ERROR_RMODE_APP                                    1153
+#define ERROR_INVALID_DLL                                  1154
+#define ERROR_NO_ASSOCIATION                               1155
+#define ERROR_DDE_FAIL                                     1156
+#define ERROR_DLL_NOT_FOUND                                1157
+#define ERROR_NO_MORE_USER_HANDLES                         1158
+#define ERROR_MESSAGE_SYNC_ONLY                            1159
+#define ERROR_SOURCE_ELEMENT_EMPTY                         1160
+#define ERROR_DESTINATION_ELEMENT_FULL                     1161
+#define ERROR_ILLEGAL_ELEMENT_ADDRESS                      1162
+#define ERROR_MAGAZINE_NOT_PRESENT                         1163
+#define ERROR_DEVICE_REINITIALIZATION_NEEDED               1164
+#define ERROR_DEVICE_REQUIRES_CLEANING                     1165
+#define ERROR_DEVICE_DOOR_OPEN                             1166
+#define ERROR_DEVICE_NOT_CONNECTED                         1167
+#define ERROR_NOT_FOUND                                    1168
+#define ERROR_NO_MATCH                                     1169
+#define ERROR_SET_NOT_FOUND                                1170
+#define ERROR_POINT_NOT_FOUND                              1171
+#define ERROR_NO_TRACKING_SERVICE                          1172
+#define ERROR_NO_VOLUME_ID                                 1173
+#define ERROR_UNABLE_TO_REMOVE_REPLACED                    1175
+#define ERROR_UNABLE_TO_MOVE_REPLACEMENT                   1176
+#define ERROR_UNABLE_TO_MOVE_REPLACEMENT_2                 1177
+#define ERROR_JOURNAL_DELETE_IN_PROGRESS                   1178
+#define ERROR_JOURNAL_NOT_ACTIVE                           1179
+#define ERROR_POTENTIAL_FILE_FOUND                         1180
+#define ERROR_JOURNAL_ENTRY_DELETED                        1181
+#define ERROR_BAD_DEVICE                                   1200
+#define ERROR_CONNECTION_UNAVAIL                           1201
+#define ERROR_DEVICE_ALREADY_REMEMBERED                    1202
+#define ERROR_NO_NET_OR_BAD_PATH                           1203
+#define ERROR_BAD_PROVIDER                                 1204
+#define ERROR_CANNOT_OPEN_PROFILE                          1205
+#define ERROR_BAD_PROFILE                                  1206
+#define ERROR_NOT_CONTAINER                                1207
+#define ERROR_EXTENDED_ERROR                               1208
+#define ERROR_INVALID_GROUPNAME                            1209
+#define ERROR_INVALID_COMPUTERNAME                         1210
+#define ERROR_INVALID_EVENTNAME                            1211
+#define ERROR_INVALID_DOMAINNAME                           1212
+#define ERROR_INVALID_SERVICENAME                          1213
+#define ERROR_INVALID_NETNAME                              1214
+#define ERROR_INVALID_SHARENAME                            1215
+#define ERROR_INVALID_PASSWORDNAME                         1216
+#define ERROR_INVALID_MESSAGENAME                          1217
+#define ERROR_INVALID_MESSAGEDEST                          1218
+#define ERROR_SESSION_CREDENTIAL_CONFLICT                  1219
+#define ERROR_REMOTE_SESSION_LIMIT_EXCEEDED                1220
+#define ERROR_DUP_DOMAINNAME                               1221
+#define ERROR_NO_NETWORK                                   1222
+#define ERROR_CANCELLED                                    1223
+#define ERROR_USER_MAPPED_FILE                             1224
+#define ERROR_CONNECTION_REFUSED                           1225
+#define ERROR_GRACEFUL_DISCONNECT                          1226
+#define ERROR_ADDRESS_ALREADY_ASSOCIATED                   1227
+#define ERROR_ADDRESS_NOT_ASSOCIATED                       1228
+#define ERROR_CONNECTION_INVALID                           1229
+#define ERROR_CONNECTION_ACTIVE                            1230
+#define ERROR_NETWORK_UNREACHABLE                          1231
+#define ERROR_HOST_UNREACHABLE                             1232
+#define ERROR_PROTOCOL_UNREACHABLE                         1233
+#define ERROR_PORT_UNREACHABLE                             1234
+#define ERROR_REQUEST_ABORTED                              1235
+#define ERROR_CONNECTION_ABORTED                           1236
+#define ERROR_RETRY                                        1237
+#define ERROR_CONNECTION_COUNT_LIMIT                       1238
+#define ERROR_LOGIN_TIME_RESTRICTION                       1239
+#define ERROR_LOGIN_WKSTA_RESTRICTION                      1240
+#define ERROR_INCORRECT_ADDRESS                            1241
+#define ERROR_ALREADY_REGISTERED                           1242
+#define ERROR_SERVICE_NOT_FOUND                            1243
+#define ERROR_NOT_AUTHENTICATED                            1244
+#define ERROR_NOT_LOGGED_ON                                1245
+#define ERROR_CONTINUE                                     1246
+#define ERROR_ALREADY_INITIALIZED                          1247
+#define ERROR_NO_MORE_DEVICES                              1248
+#define ERROR_NO_SUCH_SITE                                 1249
+#define ERROR_DOMAIN_CONTROLLER_EXISTS                     1250
+#define ERROR_ONLY_IF_CONNECTED                            1251
+#define ERROR_OVERRIDE_NOCHANGES                           1252
+#define ERROR_BAD_USER_PROFILE                             1253
+#define ERROR_NOT_SUPPORTED_ON_SBS                         1254
+#define ERROR_NOT_ALL_ASSIGNED                             1300
+#define ERROR_SOME_NOT_MAPPED                              1301
+#define ERROR_NO_QUOTAS_FOR_ACCOUNT                        1302
+#define ERROR_LOCAL_USER_SESSION_KEY                       1303
+#define ERROR_NULL_LM_PASSWORD                             1304
+#define ERROR_UNKNOWN_REVISION                             1305
+#define ERROR_REVISION_MISMATCH                            1306
+#define ERROR_INVALID_OWNER                                1307
+#define ERROR_INVALID_PRIMARY_GROUP                        1308
+#define ERROR_NO_IMPERSONATION_TOKEN                       1309
+#define ERROR_CANT_DISABLE_MANDATORY                       1310
+#define ERROR_NO_LOGON_SERVERS                             1311
+#define ERROR_NO_SUCH_LOGON_SESSION                        1312
+#define ERROR_NO_SUCH_PRIVILEGE                            1313
+#define ERROR_PRIVILEGE_NOT_HELD                           1314
+#define ERROR_INVALID_ACCOUNT_NAME                         1315
+#define ERROR_USER_EXISTS                                  1316
+#define ERROR_NO_SUCH_USER                                 1317
+#define ERROR_GROUP_EXISTS                                 1318
+#define ERROR_NO_SUCH_GROUP                                1319
+#define ERROR_MEMBER_IN_GROUP                              1320
+#define ERROR_MEMBER_NOT_IN_GROUP                          1321
+#define ERROR_LAST_ADMIN                                   1322
+#define ERROR_WRONG_PASSWORD                               1323
+#define ERROR_ILL_FORMED_PASSWORD                          1324
+#define ERROR_PASSWORD_RESTRICTION                         1325
+#define ERROR_LOGON_FAILURE                                1326
+#define ERROR_ACCOUNT_RESTRICTION                          1327
+#define ERROR_INVALID_LOGON_HOURS                          1328
+#define ERROR_INVALID_WORKSTATION                          1329
+#define ERROR_PASSWORD_EXPIRED                             1330
+#define ERROR_ACCOUNT_DISABLED                             1331
+#define ERROR_NONE_MAPPED                                  1332
+#define ERROR_TOO_MANY_LUIDS_REQUESTED                     1333
+#define ERROR_LUIDS_EXHAUSTED                              1334
+#define ERROR_INVALID_SUB_AUTHORITY                        1335
+#define ERROR_INVALID_ACL                                  1336
+#define ERROR_INVALID_SID                                  1337
+#define ERROR_INVALID_SECURITY_DESCR                       1338
+#define ERROR_BAD_INHERITANCE_ACL                          1340
+#define ERROR_SERVER_DISABLED                              1341
+#define ERROR_SERVER_NOT_DISABLED                          1342
+#define ERROR_INVALID_ID_AUTHORITY                         1343
+#define ERROR_ALLOTTED_SPACE_EXCEEDED                      1344
+#define ERROR_INVALID_GROUP_ATTRIBUTES                     1345
+#define ERROR_BAD_IMPERSONATION_LEVEL                      1346
+#define ERROR_CANT_OPEN_ANONYMOUS                          1347
+#define ERROR_BAD_VALIDATION_CLASS                         1348
+#define ERROR_BAD_TOKEN_TYPE                               1349
+#define ERROR_NO_SECURITY_ON_OBJECT                        1350
+#define ERROR_CANT_ACCESS_DOMAIN_INFO                      1351
+#define ERROR_INVALID_SERVER_STATE                         1352
+#define ERROR_INVALID_DOMAIN_STATE                         1353
+#define ERROR_INVALID_DOMAIN_ROLE                          1354
+#define ERROR_NO_SUCH_DOMAIN                               1355
+#define ERROR_DOMAIN_EXISTS                                1356
+#define ERROR_DOMAIN_LIMIT_EXCEEDED                        1357
+#define ERROR_INTERNAL_DB_CORRUPTION                       1358
+#define ERROR_INTERNAL_ERROR                               1359
+#define ERROR_GENERIC_NOT_MAPPED                           1360
+#define ERROR_BAD_DESCRIPTOR_FORMAT                        1361
+#define ERROR_NOT_LOGON_PROCESS                            1362
+#define ERROR_LOGON_SESSION_EXISTS                         1363
+#define ERROR_NO_SUCH_PACKAGE                              1364
+#define ERROR_BAD_LOGON_SESSION_STATE                      1365
+#define ERROR_LOGON_SESSION_COLLISION                      1366
+#define ERROR_INVALID_LOGON_TYPE                           1367
+#define ERROR_CANNOT_IMPERSONATE                           1368
+#define ERROR_RXACT_INVALID_STATE                          1369
+#define ERROR_RXACT_COMMIT_FAILURE                         1370
+#define ERROR_SPECIAL_ACCOUNT                              1371
+#define ERROR_SPECIAL_GROUP                                1372
+#define ERROR_SPECIAL_USER                                 1373
+#define ERROR_MEMBERS_PRIMARY_GROUP                        1374
+#define ERROR_TOKEN_ALREADY_IN_USE                         1375
+#define ERROR_NO_SUCH_ALIAS                                1376
+#define ERROR_MEMBER_NOT_IN_ALIAS                          1377
+#define ERROR_MEMBER_IN_ALIAS                              1378
+#define ERROR_ALIAS_EXISTS                                 1379
+#define ERROR_LOGON_NOT_GRANTED                            1380
+#define ERROR_TOO_MANY_SECRETS                             1381
+#define ERROR_SECRET_TOO_LONG                              1382
+#define ERROR_INTERNAL_DB_ERROR                            1383
+#define ERROR_TOO_MANY_CONTEXT_IDS                         1384
+#define ERROR_LOGON_TYPE_NOT_GRANTED                       1385
+#define ERROR_NT_CROSS_ENCRYPTION_REQUIRED                 1386
+#define ERROR_NO_SUCH_MEMBER                               1387
+#define ERROR_INVALID_MEMBER                               1388
+#define ERROR_TOO_MANY_SIDS                                1389
+#define ERROR_LM_CROSS_ENCRYPTION_REQUIRED                 1390
+#define ERROR_NO_INHERITANCE                               1391
+#define ERROR_FILE_CORRUPT                                 1392
+#define ERROR_DISK_CORRUPT                                 1393
+#define ERROR_NO_USER_SESSION_KEY                          1394
+#define ERROR_LICENSE_QUOTA_EXCEEDED                       1395
+#define ERROR_WRONG_TARGET_NAME                            1396
+#define ERROR_MUTUAL_AUTH_FAILED                           1397
+#define ERROR_TIME_SKEW                                    1398
+#define ERROR_INVALID_WINDOW_HANDLE                        1400
+#define ERROR_INVALID_MENU_HANDLE                          1401
+#define ERROR_INVALID_CURSOR_HANDLE                        1402
+#define ERROR_INVALID_ACCEL_HANDLE                         1403
+#define ERROR_INVALID_HOOK_HANDLE                          1404
+#define ERROR_INVALID_DWP_HANDLE                           1405
+#define ERROR_TLW_WITH_WSCHILD                             1406
+#define ERROR_CANNOT_FIND_WND_CLASS                        1407
+#define ERROR_WINDOW_OF_OTHER_THREAD                       1408
+#define ERROR_HOTKEY_ALREADY_REGISTERED                    1409
+#define ERROR_CLASS_ALREADY_EXISTS                         1410
+#define ERROR_CLASS_DOES_NOT_EXIST                         1411
+#define ERROR_CLASS_HAS_WINDOWS                            1412
+#define ERROR_INVALID_INDEX                                1413
+#define ERROR_INVALID_ICON_HANDLE                          1414
+#define ERROR_PRIVATE_DIALOG_INDEX                         1415
+#define ERROR_LISTBOX_ID_NOT_FOUND                         1416
+#define ERROR_NO_WILDCARD_CHARACTERS                       1417
+#define ERROR_CLIPBOARD_NOT_OPEN                           1418
+#define ERROR_HOTKEY_NOT_REGISTERED                        1419
+#define ERROR_WINDOW_NOT_DIALOG                            1420
+#define ERROR_CONTROL_ID_NOT_FOUND                         1421
+#define ERROR_INVALID_COMBOBOX_MESSAGE                     1422
+#define ERROR_WINDOW_NOT_COMBOBOX                          1423
+#define ERROR_INVALID_EDIT_HEIGHT                          1424
+#define ERROR_DC_NOT_FOUND                                 1425
+#define ERROR_INVALID_HOOK_FILTER                          1426
+#define ERROR_INVALID_FILTER_PROC                          1427
+#define ERROR_HOOK_NEEDS_HMOD                              1428
+#define ERROR_GLOBAL_ONLY_HOOK                             1429
+#define ERROR_JOURNAL_HOOK_SET                             1430
+#define ERROR_HOOK_NOT_INSTALLED                           1431
+#define ERROR_INVALID_LB_MESSAGE                           1432
+#define ERROR_SETCOUNT_ON_BAD_LB                           1433
+#define ERROR_LB_WITHOUT_TABSTOPS                          1434
+#define ERROR_DESTROY_OBJECT_OF_OTHER_THREAD               1435
+#define ERROR_CHILD_WINDOW_MENU                            1436
+#define ERROR_NO_SYSTEM_MENU                               1437
+#define ERROR_INVALID_MSGBOX_STYLE                         1438
+#define ERROR_INVALID_SPI_VALUE                            1439
+#define ERROR_SCREEN_ALREADY_LOCKED                        1440
+#define ERROR_HWNDS_HAVE_DIFF_PARENT                       1441
+#define ERROR_NOT_CHILD_WINDOW                             1442
+#define ERROR_INVALID_GW_COMMAND                           1443
+#define ERROR_INVALID_THREAD_ID                            1444
+#define ERROR_NON_MDICHILD_WINDOW                          1445
+#define ERROR_POPUP_ALREADY_ACTIVE                         1446
+#define ERROR_NO_SCROLLBARS                                1447
+#define ERROR_INVALID_SCROLLBAR_RANGE                      1448
+#define ERROR_INVALID_SHOWWIN_COMMAND                      1449
+#define ERROR_NO_SYSTEM_RESOURCES                          1450
+#define ERROR_NONPAGED_SYSTEM_RESOURCES                    1451
+#define ERROR_PAGED_SYSTEM_RESOURCES                       1452
+#define ERROR_WORKING_SET_QUOTA                            1453
+#define ERROR_PAGEFILE_QUOTA                               1454
+#define ERROR_COMMITMENT_LIMIT                             1455
+#define ERROR_MENU_ITEM_NOT_FOUND                          1456
+#define ERROR_INVALID_KEYBOARD_HANDLE                      1457
+#define ERROR_HOOK_TYPE_NOT_ALLOWED                        1458
+#define ERROR_REQUIRES_INTERACTIVE_WINDOWSTATION           1459
+#define ERROR_TIMEOUT                                      1460
+#define ERROR_INVALID_MONITOR_HANDLE                       1461
+#define ERROR_EVENTLOG_FILE_CORRUPT                        1500
+#define ERROR_EVENTLOG_CANT_START                          1501
+#define ERROR_LOG_FILE_FULL                                1502
+#define ERROR_EVENTLOG_FILE_CHANGED                        1503
+#define ERROR_INSTALL_SERVICE_FAILURE                      1601
+#define ERROR_INSTALL_USEREXIT                             1602
+#define ERROR_INSTALL_FAILURE                              1603
+#define ERROR_INSTALL_SUSPEND                              1604
+#define ERROR_UNKNOWN_PRODUCT                              1605
+#define ERROR_UNKNOWN_FEATURE                              1606
+#define ERROR_UNKNOWN_COMPONENT                            1607
+#define ERROR_UNKNOWN_PROPERTY                             1608
+#define ERROR_INVALID_HANDLE_STATE                         1609
+#define ERROR_BAD_CONFIGURATION                            1610
+#define ERROR_INDEX_ABSENT                                 1611
+#define ERROR_INSTALL_SOURCE_ABSENT                        1612
+#define ERROR_INSTALL_PACKAGE_VERSION                      1613
+#define ERROR_PRODUCT_UNINSTALLED                          1614
+#define ERROR_BAD_QUERY_SYNTAX                             1615
+#define ERROR_INVALID_FIELD                                1616
+#define ERROR_DEVICE_REMOVED                               1617
+#define ERROR_INSTALL_ALREADY_RUNNING                      1618
+#define ERROR_INSTALL_PACKAGE_OPEN_FAILED                  1619
+#define ERROR_INSTALL_PACKAGE_INVALID                      1620
+#define ERROR_INSTALL_UI_FAILURE                           1621
+#define ERROR_INSTALL_LOG_FAILURE                          1622
+#define ERROR_INSTALL_LANGUAGE_UNSUPPORTED                 1623
+#define ERROR_INSTALL_TRANSFORM_FAILURE                    1624
+#define ERROR_INSTALL_PACKAGE_REJECTED                     1625
+#define ERROR_FUNCTION_NOT_CALLED                          1626
+#define ERROR_FUNCTION_FAILED                              1627
+#define ERROR_INVALID_TABLE                                1628
+#define ERROR_DATATYPE_MISMATCH                            1629
+#define ERROR_UNSUPPORTED_TYPE                             1630
+#define ERROR_CREATE_FAILED                                1631
+#define ERROR_INSTALL_TEMP_UNWRITABLE                      1632
+#define ERROR_INSTALL_PLATFORM_UNSUPPORTED                 1633
+#define ERROR_INSTALL_NOTUSED                              1634
+#define ERROR_PATCH_PACKAGE_OPEN_FAILED                    1635
+#define ERROR_PATCH_PACKAGE_INVALID                        1636
+#define ERROR_PATCH_PACKAGE_UNSUPPORTED                    1637
+#define ERROR_PRODUCT_VERSION                              1638
+#define ERROR_INVALID_COMMAND_LINE                         1639
+#define ERROR_INSTALL_REMOTE_DISALLOWED                    1640
+#define ERROR_SUCCESS_REBOOT_INITIATED                     1641
+#define RPC_S_INVALID_STRING_BINDING                       1700
+#define RPC_S_WRONG_KIND_OF_BINDING                        1701
+#define RPC_S_INVALID_BINDING                              1702
+#define RPC_S_PROTSEQ_NOT_SUPPORTED                        1703
+#define RPC_S_INVALID_RPC_PROTSEQ                          1704
+#define RPC_S_INVALID_STRING_UUID                          1705
+#define RPC_S_INVALID_ENDPOINT_FORMAT                      1706
+#define RPC_S_INVALID_NET_ADDR                             1707
+#define RPC_S_NO_ENDPOINT_FOUND                            1708
+#define RPC_S_INVALID_TIMEOUT                              1709
+#define RPC_S_OBJECT_NOT_FOUND                             1710
+#define RPC_S_ALREADY_REGISTERED                           1711
+#define RPC_S_TYPE_ALREADY_REGISTERED                      1712
+#define RPC_S_ALREADY_LISTENING                            1713
+#define RPC_S_NO_PROTSEQS_REGISTERED                       1714
+#define RPC_S_NOT_LISTENING                                1715
+#define RPC_S_UNKNOWN_MGR_TYPE                             1716
+#define RPC_S_UNKNOWN_IF                                   1717
+#define RPC_S_NO_BINDINGS                                  1718
+#define RPC_S_NO_PROTSEQS                                  1719
+#define RPC_S_CANT_CREATE_ENDPOINT                         1720
+#define RPC_S_OUT_OF_RESOURCES                             1721
+#define RPC_S_SERVER_UNAVAILABLE                           1722
+#define RPC_S_SERVER_TOO_BUSY                              1723
+#define RPC_S_INVALID_NETWORK_OPTIONS                      1724
+#define RPC_S_NO_CALL_ACTIVE                               1725
+#define RPC_S_CALL_FAILED                                  1726
+#define RPC_S_CALL_FAILED_DNE                              1727
+#define RPC_S_PROTOCOL_ERROR                               1728
+#define RPC_S_UNSUPPORTED_TRANS_SYN                        1730
+#define RPC_S_UNSUPPORTED_TYPE                             1732
+#define RPC_S_INVALID_TAG                                  1733
+#define RPC_S_INVALID_BOUND                                1734
+#define RPC_S_NO_ENTRY_NAME                                1735
+#define RPC_S_INVALID_NAME_SYNTAX                          1736
+#define RPC_S_UNSUPPORTED_NAME_SYNTAX                      1737
+#define RPC_S_UUID_NO_ADDRESS                              1739
+#define RPC_S_DUPLICATE_ENDPOINT                           1740
+#define RPC_S_UNKNOWN_AUTHN_TYPE                           1741
+#define RPC_S_MAX_CALLS_TOO_SMALL                          1742
+#define RPC_S_STRING_TOO_LONG                              1743
+#define RPC_S_PROTSEQ_NOT_FOUND                            1744
+#define RPC_S_PROCNUM_OUT_OF_RANGE                         1745
+#define RPC_S_BINDING_HAS_NO_AUTH                          1746
+#define RPC_S_UNKNOWN_AUTHN_SERVICE                        1747
+#define RPC_S_UNKNOWN_AUTHN_LEVEL                          1748
+#define RPC_S_INVALID_AUTH_IDENTITY                        1749
+#define RPC_S_UNKNOWN_AUTHZ_SERVICE                        1750
+#define EPT_S_INVALID_ENTRY                                1751
+#define EPT_S_CANT_PERFORM_OP                              1752
+#define EPT_S_NOT_REGISTERED                               1753
+#define RPC_S_NOTHING_TO_EXPORT                            1754
+#define RPC_S_INCOMPLETE_NAME                              1755
+#define RPC_S_INVALID_VERS_OPTION                          1756
+#define RPC_S_NO_MORE_MEMBERS                              1757
+#define RPC_S_NOT_ALL_OBJS_UNEXPORTED                      1758
+#define RPC_S_INTERFACE_NOT_FOUND                          1759
+#define RPC_S_ENTRY_ALREADY_EXISTS                         1760
+#define RPC_S_ENTRY_NOT_FOUND                              1761
+#define RPC_S_NAME_SERVICE_UNAVAILABLE                     1762
+#define RPC_S_INVALID_NAF_ID                               1763
+#define RPC_S_CANNOT_SUPPORT                               1764
+#define RPC_S_NO_CONTEXT_AVAILABLE                         1765
+#define RPC_S_INTERNAL_ERROR                               1766
+#define RPC_S_ZERO_DIVIDE                                  1767
+#define RPC_S_ADDRESS_ERROR                                1768
+#define RPC_S_FP_DIV_ZERO                                  1769
+#define RPC_S_FP_UNDERFLOW                                 1770
+#define RPC_S_FP_OVERFLOW                                  1771
+#define RPC_X_NO_MORE_ENTRIES                              1772
+#define RPC_X_SS_CHAR_TRANS_OPEN_FAIL                      1773
+#define RPC_X_SS_CHAR_TRANS_SHORT_FILE                     1774
+#define RPC_X_SS_IN_NULL_CONTEXT                           1775
+#define RPC_X_SS_CONTEXT_DAMAGED                           1777
+#define RPC_X_SS_HANDLES_MISMATCH                          1778
+#define RPC_X_SS_CANNOT_GET_CALL_HANDLE                    1779
+#define RPC_X_NULL_REF_POINTER                             1780
+#define RPC_X_ENUM_VALUE_OUT_OF_RANGE                      1781
+#define RPC_X_BYTE_COUNT_TOO_SMALL                         1782
+#define RPC_X_BAD_STUB_DATA                                1783
+#define ERROR_INVALID_USER_BUFFER                          1784
+#define ERROR_UNRECOGNIZED_MEDIA                           1785
+#define ERROR_NO_TRUST_LSA_SECRET                          1786
+#define ERROR_NO_TRUST_SAM_ACCOUNT                         1787
+#define ERROR_TRUSTED_DOMAIN_FAILURE                       1788
+#define ERROR_TRUSTED_RELATIONSHIP_FAILURE                 1789
+#define ERROR_TRUST_FAILURE                                1790
+#define RPC_S_CALL_IN_PROGRESS                             1791
+#define ERROR_NETLOGON_NOT_STARTED                         1792
+#define ERROR_ACCOUNT_EXPIRED                              1793
+#define ERROR_REDIRECTOR_HAS_OPEN_HANDLES                  1794
+#define ERROR_PRINTER_DRIVER_ALREADY_INSTALLED             1795
+#define ERROR_UNKNOWN_PORT                                 1796
+#define ERROR_UNKNOWN_PRINTER_DRIVER                       1797
+#define ERROR_UNKNOWN_PRINTPROCESSOR                       1798
+#define ERROR_INVALID_SEPARATOR_FILE                       1799
+#define ERROR_INVALID_PRIORITY                             1800
+#define ERROR_INVALID_PRINTER_NAME                         1801
+#define ERROR_PRINTER_ALREADY_EXISTS                       1802
+#define ERROR_INVALID_PRINTER_COMMAND                      1803
+#define ERROR_INVALID_DATATYPE                             1804
+#define ERROR_INVALID_ENVIRONMENT                          1805
+#define RPC_S_NO_MORE_BINDINGS                             1806
+#define ERROR_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT            1807
+#define ERROR_NOLOGON_WORKSTATION_TRUST_ACCOUNT            1808
+#define ERROR_NOLOGON_SERVER_TRUST_ACCOUNT                 1809
+#define ERROR_DOMAIN_TRUST_INCONSISTENT                    1810
+#define ERROR_SERVER_HAS_OPEN_HANDLES                      1811
+#define ERROR_RESOURCE_DATA_NOT_FOUND                      1812
+#define ERROR_RESOURCE_TYPE_NOT_FOUND                      1813
+#define ERROR_RESOURCE_NAME_NOT_FOUND                      1814
+#define ERROR_RESOURCE_LANG_NOT_FOUND                      1815
+#define ERROR_NOT_ENOUGH_QUOTA                             1816
+#define RPC_S_NO_INTERFACES                                1817
+#define RPC_S_CALL_CANCELLED                               1818
+#define RPC_S_BINDING_INCOMPLETE                           1819
+#define RPC_S_COMM_FAILURE                                 1820
+#define RPC_S_UNSUPPORTED_AUTHN_LEVEL                      1821
+#define RPC_S_NO_PRINC_NAME                                1822
+#define RPC_S_NOT_RPC_ERROR                                1823
+#define RPC_S_UUID_LOCAL_ONLY                              1824
+#define RPC_S_SEC_PKG_ERROR                                1825
+#define RPC_S_NOT_CANCELLED                                1826
+#define RPC_X_INVALID_ES_ACTION                            1827
+#define RPC_X_WRONG_ES_VERSION                             1828
+#define RPC_X_WRONG_STUB_VERSION                           1829
+#define RPC_X_INVALID_PIPE_OBJECT                          1830
+#define RPC_X_WRONG_PIPE_ORDER                             1831
+#define RPC_X_WRONG_PIPE_VERSION                           1832
+#define RPC_S_GROUP_MEMBER_NOT_FOUND                       1898
+#define EPT_S_CANT_CREATE                                  1899
+#define RPC_S_INVALID_OBJECT                               1900
+#define ERROR_INVALID_TIME                                 1901
+#define ERROR_INVALID_FORM_NAME                            1902
+#define ERROR_INVALID_FORM_SIZE                            1903
+#define ERROR_ALREADY_WAITING                              1904
+#define ERROR_PRINTER_DELETED                              1905
+#define ERROR_INVALID_PRINTER_STATE                        1906
+#define ERROR_PASSWORD_MUST_CHANGE                         1907
+#define ERROR_DOMAIN_CONTROLLER_NOT_FOUND                  1908
+#define ERROR_ACCOUNT_LOCKED_OUT                           1909
+#define OR_INVALID_OXID                                    1910
+#define OR_INVALID_OID                                     1911
+#define OR_INVALID_SET                                     1912
+#define RPC_S_SEND_INCOMPLETE                              1913
+#define RPC_S_INVALID_ASYNC_HANDLE                         1914
+#define RPC_S_INVALID_ASYNC_CALL                           1915
+#define RPC_X_PIPE_CLOSED                                  1916
+#define RPC_X_PIPE_DISCIPLINE_ERROR                        1917
+#define RPC_X_PIPE_EMPTY                                   1918
+#define ERROR_NO_SITENAME                                  1919
+#define ERROR_CANT_ACCESS_FILE                             1920
+#define ERROR_CANT_RESOLVE_FILENAME                        1921
+#define RPC_S_ENTRY_TYPE_MISMATCH                          1922
+#define RPC_S_NOT_ALL_OBJS_EXPORTED                        1923
+#define RPC_S_INTERFACE_NOT_EXPORTED                       1924
+#define RPC_S_PROFILE_NOT_ADDED                            1925
+#define RPC_S_PRF_ELT_NOT_ADDED                            1926
+#define RPC_S_PRF_ELT_NOT_REMOVED                          1927
+#define RPC_S_GRP_ELT_NOT_ADDED                            1928
+#define RPC_S_GRP_ELT_NOT_REMOVED                          1929
+#define ERROR_INVALID_PIXEL_FORMAT                         2000
+#define ERROR_BAD_DRIVER                                   2001
+#define ERROR_INVALID_WINDOW_STYLE                         2002
+#define ERROR_METAFILE_NOT_SUPPORTED                       2003
+#define ERROR_TRANSFORM_NOT_SUPPORTED                      2004
+#define ERROR_CLIPPING_NOT_SUPPORTED                       2005
+#define ERROR_INVALID_CMM                                  2010
+#define ERROR_INVALID_PROFILE                              2011
+#define ERROR_TAG_NOT_FOUND                                2012
+#define ERROR_TAG_NOT_PRESENT                              2013
+#define ERROR_DUPLICATE_TAG                                2014
+#define ERROR_PROFILE_NOT_ASSOCIATED_WITH_DEVICE           2015
+#define ERROR_PROFILE_NOT_FOUND                            2016
+#define ERROR_INVALID_COLORSPACE                           2017
+#define ERROR_ICM_NOT_ENABLED                              2018
+#define ERROR_DELETING_ICM_XFORM                           2019
+#define ERROR_INVALID_TRANSFORM                            2020
+#define ERROR_COLORSPACE_MISMATCH                          2021
+#define ERROR_INVALID_COLORINDEX                           2022
+#define ERROR_CONNECTED_OTHER_PASSWORD                     2108
+#define ERROR_BAD_USERNAME                                 2202
+#define ERROR_NOT_CONNECTED                                2250
+#define ERROR_OPEN_FILES                                   2401
+#define ERROR_ACTIVE_CONNECTIONS                           2402
+#define ERROR_DEVICE_IN_USE                                2404
+#define ERROR_UNKNOWN_PRINT_MONITOR                        3000
+#define ERROR_PRINTER_DRIVER_IN_USE                        3001
+#define ERROR_SPOOL_FILE_NOT_FOUND                         3002
+#define ERROR_SPL_NO_STARTDOC                              3003
+#define ERROR_SPL_NO_ADDJOB                                3004
+#define ERROR_PRINT_PROCESSOR_ALREADY_INSTALLED            3005
+#define ERROR_PRINT_MONITOR_ALREADY_INSTALLED              3006
+#define ERROR_INVALID_PRINT_MONITOR                        3007
+#define ERROR_PRINT_MONITOR_IN_USE                         3008
+#define ERROR_PRINTER_HAS_JOBS_QUEUED                      3009
+#define ERROR_SUCCESS_REBOOT_REQUIRED                      3010
+#define ERROR_SUCCESS_RESTART_REQUIRED                     3011
+#define ERROR_PRINTER_NOT_FOUND                            3012
+#define ERROR_WINS_INTERNAL                                4000
+#define ERROR_CAN_NOT_DEL_LOCAL_WINS                       4001
+#define ERROR_STATIC_INIT                                  4002
+#define ERROR_INC_BACKUP                                   4003
+#define ERROR_FULL_BACKUP                                  4004
+#define ERROR_REC_NON_EXISTENT                             4005
+#define ERROR_RPL_NOT_ALLOWED                              4006
+#define ERROR_DHCP_ADDRESS_CONFLICT                        4100
+#define ERROR_WMI_GUID_NOT_FOUND                           4200
+#define ERROR_WMI_INSTANCE_NOT_FOUND                       4201
+#define ERROR_WMI_ITEMID_NOT_FOUND                         4202
+#define ERROR_WMI_TRY_AGAIN                                4203
+#define ERROR_WMI_DP_NOT_FOUND                             4204
+#define ERROR_WMI_UNRESOLVED_INSTANCE_REF                  4205
+#define ERROR_WMI_ALREADY_ENABLED                          4206
+#define ERROR_WMI_GUID_DISCONNECTED                        4207
+#define ERROR_WMI_SERVER_UNAVAILABLE                       4208
+#define ERROR_WMI_DP_FAILED                                4209
+#define ERROR_WMI_INVALID_MOF                              4210
+#define ERROR_WMI_INVALID_REGINFO                          4211
+#define ERROR_WMI_ALREADY_DISABLED                         4212
+#define ERROR_WMI_READ_ONLY                                4213
+#define ERROR_WMI_SET_FAILURE                              4214
+#define ERROR_INVALID_MEDIA                                4300
+#define ERROR_INVALID_LIBRARY                              4301
+#define ERROR_INVALID_MEDIA_POOL                           4302
+#define ERROR_DRIVE_MEDIA_MISMATCH                         4303
+#define ERROR_MEDIA_OFFLINE                                4304
+#define ERROR_LIBRARY_OFFLINE                              4305
+#define ERROR_EMPTY                                        4306
+#define ERROR_NOT_EMPTY                                    4307
+#define ERROR_MEDIA_UNAVAILABLE                            4308
+#define ERROR_RESOURCE_DISABLED                            4309
+#define ERROR_INVALID_CLEANER                              4310
+#define ERROR_UNABLE_TO_CLEAN                              4311
+#define ERROR_OBJECT_NOT_FOUND                             4312
+#define ERROR_DATABASE_FAILURE                             4313
+#define ERROR_DATABASE_FULL                                4314
+#define ERROR_MEDIA_INCOMPATIBLE                           4315
+#define ERROR_RESOURCE_NOT_PRESENT                         4316
+#define ERROR_INVALID_OPERATION                            4317
+#define ERROR_MEDIA_NOT_AVAILABLE                          4318
+#define ERROR_DEVICE_NOT_AVAILABLE                         4319
+#define ERROR_REQUEST_REFUSED                              4320
+#define ERROR_INVALID_DRIVE_OBJECT                         4321
+#define ERROR_LIBRARY_FULL                                 4322
+#define ERROR_MEDIUM_NOT_ACCESSIBLE                        4323
+#define ERROR_UNABLE_TO_LOAD_MEDIUM                        4324
+#define ERROR_UNABLE_TO_INVENTORY_DRIVE                    4325
+#define ERROR_UNABLE_TO_INVENTORY_SLOT                     4326
+#define ERROR_UNABLE_TO_INVENTORY_TRANSPORT                4327
+#define ERROR_TRANSPORT_FULL                               4328
+#define ERROR_CONTROLLING_IEPORT                           4329
+#define ERROR_UNABLE_TO_EJECT_MOUNTED_MEDIA                4330
+#define ERROR_CLEANER_SLOT_SET                             4331
+#define ERROR_CLEANER_SLOT_NOT_SET                         4332
+#define ERROR_CLEANER_CARTRIDGE_SPENT                      4333
+#define ERROR_UNEXPECTED_OMID                              4334
+#define ERROR_CANT_DELETE_LAST_ITEM                        4335
+#define ERROR_MESSAGE_EXCEEDS_MAX_SIZE                     4336
+#define ERROR_VOLUME_CONTAINS_SYS_FILES                    4337
+#define ERROR_INDIGENOUS_TYPE                              4338
+#define ERROR_NO_SUPPORTING_DRIVES                         4339
+#define ERROR_FILE_OFFLINE                                 4350
+#define ERROR_REMOTE_STORAGE_NOT_ACTIVE                    4351
+#define ERROR_REMOTE_STORAGE_MEDIA_ERROR                   4352
+#define ERROR_NOT_A_REPARSE_POINT                          4390
+#define ERROR_REPARSE_ATTRIBUTE_CONFLICT                   4391
+#define ERROR_INVALID_REPARSE_DATA                         4392
+#define ERROR_REPARSE_TAG_INVALID                          4393
+#define ERROR_REPARSE_TAG_MISMATCH                         4394
+#define ERROR_VOLUME_NOT_SIS_ENABLED                       4500
+#define ERROR_DEPENDENT_RESOURCE_EXISTS                    5001
+#define ERROR_DEPENDENCY_NOT_FOUND                         5002
+#define ERROR_DEPENDENCY_ALREADY_EXISTS                    5003
+#define ERROR_RESOURCE_NOT_ONLINE                          5004
+#define ERROR_HOST_NODE_NOT_AVAILABLE                      5005
+#define ERROR_RESOURCE_NOT_AVAILABLE                       5006
+#define ERROR_RESOURCE_NOT_FOUND                           5007
+#define ERROR_SHUTDOWN_CLUSTER                             5008
+#define ERROR_CANT_EVICT_ACTIVE_NODE                       5009
+#define ERROR_OBJECT_ALREADY_EXISTS                        5010
+#define ERROR_OBJECT_IN_LIST                               5011
+#define ERROR_GROUP_NOT_AVAILABLE                          5012
+#define ERROR_GROUP_NOT_FOUND                              5013
+#define ERROR_GROUP_NOT_ONLINE                             5014
+#define ERROR_HOST_NODE_NOT_RESOURCE_OWNER                 5015
+#define ERROR_HOST_NODE_NOT_GROUP_OWNER                    5016
+#define ERROR_RESMON_CREATE_FAILED                         5017
+#define ERROR_RESMON_ONLINE_FAILED                         5018
+#define ERROR_RESOURCE_ONLINE                              5019
+#define ERROR_QUORUM_RESOURCE                              5020
+#define ERROR_NOT_QUORUM_CAPABLE                           5021
+#define ERROR_CLUSTER_SHUTTING_DOWN                        5022
+#define ERROR_INVALID_STATE                                5023
+#define ERROR_RESOURCE_PROPERTIES_STORED                   5024
+#define ERROR_NOT_QUORUM_CLASS                             5025
+#define ERROR_CORE_RESOURCE                                5026
+#define ERROR_QUORUM_RESOURCE_ONLINE_FAILED                5027
+#define ERROR_QUORUMLOG_OPEN_FAILED                        5028
+#define ERROR_CLUSTERLOG_CORRUPT                           5029
+#define ERROR_CLUSTERLOG_RECORD_EXCEEDS_MAXSIZE            5030
+#define ERROR_CLUSTERLOG_EXCEEDS_MAXSIZE                   5031
+#define ERROR_CLUSTERLOG_CHKPOINT_NOT_FOUND                5032
+#define ERROR_CLUSTERLOG_NOT_ENOUGH_SPACE                  5033
+#define ERROR_QUORUM_OWNER_ALIVE                           5034
+#define ERROR_NETWORK_NOT_AVAILABLE                        5035
+#define ERROR_NODE_NOT_AVAILABLE                           5036
+#define ERROR_ALL_NODES_NOT_AVAILABLE                      5037
+#define ERROR_RESOURCE_FAILED                              5038
+#define ERROR_CLUSTER_INVALID_NODE                         5039
+#define ERROR_CLUSTER_NODE_EXISTS                          5040
+#define ERROR_CLUSTER_JOIN_IN_PROGRESS                     5041
+#define ERROR_CLUSTER_NODE_NOT_FOUND                       5042
+#define ERROR_CLUSTER_LOCAL_NODE_NOT_FOUND                 5043
+#define ERROR_CLUSTER_NETWORK_EXISTS                       5044
+#define ERROR_CLUSTER_NETWORK_NOT_FOUND                    5045
+#define ERROR_CLUSTER_NETINTERFACE_EXISTS                  5046
+#define ERROR_CLUSTER_NETINTERFACE_NOT_FOUND               5047
+#define ERROR_CLUSTER_INVALID_REQUEST                      5048
+#define ERROR_CLUSTER_INVALID_NETWORK_PROVIDER             5049
+#define ERROR_CLUSTER_NODE_DOWN                            5050
+#define ERROR_CLUSTER_NODE_UNREACHABLE                     5051
+#define ERROR_CLUSTER_NODE_NOT_MEMBER                      5052
+#define ERROR_CLUSTER_JOIN_NOT_IN_PROGRESS                 5053
+#define ERROR_CLUSTER_INVALID_NETWORK                      5054
+#define ERROR_CLUSTER_NODE_UP                              5056
+#define ERROR_CLUSTER_IPADDR_IN_USE                        5057
+#define ERROR_CLUSTER_NODE_NOT_PAUSED                      5058
+#define ERROR_CLUSTER_NO_SECURITY_CONTEXT                  5059
+#define ERROR_CLUSTER_NETWORK_NOT_INTERNAL                 5060
+#define ERROR_CLUSTER_NODE_ALREADY_UP                      5061
+#define ERROR_CLUSTER_NODE_ALREADY_DOWN                    5062
+#define ERROR_CLUSTER_NETWORK_ALREADY_ONLINE               5063
+#define ERROR_CLUSTER_NETWORK_ALREADY_OFFLINE              5064
+#define ERROR_CLUSTER_NODE_ALREADY_MEMBER                  5065
+#define ERROR_CLUSTER_LAST_INTERNAL_NETWORK                5066
+#define ERROR_CLUSTER_NETWORK_HAS_DEPENDENTS               5067
+#define ERROR_INVALID_OPERATION_ON_QUORUM                  5068
+#define ERROR_DEPENDENCY_NOT_ALLOWED                       5069
+#define ERROR_CLUSTER_NODE_PAUSED                          5070
+#define ERROR_NODE_CANT_HOST_RESOURCE                      5071
+#define ERROR_CLUSTER_NODE_NOT_READY                       5072
+#define ERROR_CLUSTER_NODE_SHUTTING_DOWN                   5073
+#define ERROR_CLUSTER_JOIN_ABORTED                         5074
+#define ERROR_CLUSTER_INCOMPATIBLE_VERSIONS                5075
+#define ERROR_CLUSTER_MAXNUM_OF_RESOURCES_EXCEEDED         5076
+#define ERROR_CLUSTER_SYSTEM_CONFIG_CHANGED                5077
+#define ERROR_CLUSTER_RESOURCE_TYPE_NOT_FOUND              5078
+#define ERROR_CLUSTER_RESTYPE_NOT_SUPPORTED                5079
+#define ERROR_CLUSTER_RESNAME_NOT_FOUND                    5080
+#define ERROR_CLUSTER_NO_RPC_PACKAGES_REGISTERED           5081
+#define ERROR_CLUSTER_OWNER_NOT_IN_PREFLIST                5082
+#define ERROR_CLUSTER_DATABASE_SEQMISMATCH                 5083
+#define ERROR_RESMON_INVALID_STATE                         5084
+#define ERROR_CLUSTER_GUM_NOT_LOCKER                       5085
+#define ERROR_QUORUM_DISK_NOT_FOUND                        5086
+#define ERROR_DATABASE_BACKUP_CORRUPT                      5087
+#define ERROR_CLUSTER_NODE_ALREADY_HAS_DFS_ROOT            5088
+#define ERROR_RESOURCE_PROPERTY_UNCHANGEABLE               5089
+#define ERROR_ENCRYPTION_FAILED                            6000
+#define ERROR_DECRYPTION_FAILED                            6001
+#define ERROR_FILE_ENCRYPTED                               6002
+#define ERROR_NO_RECOVERY_POLICY                           6003
+#define ERROR_NO_EFS                                       6004
+#define ERROR_WRONG_EFS                                    6005
+#define ERROR_NO_USER_KEYS                                 6006
+#define ERROR_FILE_NOT_ENCRYPTED                           6007
+#define ERROR_NOT_EXPORT_FORMAT                            6008
+#define ERROR_FILE_READ_ONLY                               6009
+#define ERROR_DIR_EFS_DISALLOWED                           6010
+#define ERROR_EFS_SERVER_NOT_TRUSTED                       6011
+#define ERROR_NO_BROWSER_SERVERS_FOUND                     6118
+#define SCHED_E_SERVICE_NOT_LOCALSYSTEM                    6200
+#define ERROR_CTX_WINSTATION_NAME_INVALID                  7001
+#define ERROR_CTX_INVALID_PD                               7002
+#define ERROR_CTX_PD_NOT_FOUND                             7003
+#define ERROR_CTX_WD_NOT_FOUND                             7004
+#define ERROR_CTX_CANNOT_MAKE_EVENTLOG_ENTRY               7005
+#define ERROR_CTX_SERVICE_NAME_COLLISION                   7006
+#define ERROR_CTX_CLOSE_PENDING                            7007
+#define ERROR_CTX_NO_OUTBUF                                7008
+#define ERROR_CTX_MODEM_INF_NOT_FOUND                      7009
+#define ERROR_CTX_INVALID_MODEMNAME                        7010
+#define ERROR_CTX_MODEM_RESPONSE_ERROR                     7011
+#define ERROR_CTX_MODEM_RESPONSE_TIMEOUT                   7012
+#define ERROR_CTX_MODEM_RESPONSE_NO_CARRIER                7013
+#define ERROR_CTX_MODEM_RESPONSE_NO_DIALTONE               7014
+#define ERROR_CTX_MODEM_RESPONSE_BUSY                      7015
+#define ERROR_CTX_MODEM_RESPONSE_VOICE                     7016
+#define ERROR_CTX_TD_ERROR                                 7017
+#define ERROR_CTX_WINSTATION_NOT_FOUND                     7022
+#define ERROR_CTX_WINSTATION_ALREADY_EXISTS                7023
+#define ERROR_CTX_WINSTATION_BUSY                          7024
+#define ERROR_CTX_BAD_VIDEO_MODE                           7025
+#define ERROR_CTX_GRAPHICS_INVALID                         7035
+#define ERROR_CTX_LOGON_DISABLED                           7037
+#define ERROR_CTX_NOT_CONSOLE                              7038
+#define ERROR_CTX_CLIENT_QUERY_TIMEOUT                     7040
+#define ERROR_CTX_CONSOLE_DISCONNECT                       7041
+#define ERROR_CTX_CONSOLE_CONNECT                          7042
+#define ERROR_CTX_SHADOW_DENIED                            7044
+#define ERROR_CTX_WINSTATION_ACCESS_DENIED                 7045
+#define ERROR_CTX_INVALID_WD                               7049
+#define ERROR_CTX_SHADOW_INVALID                           7050
+#define ERROR_CTX_SHADOW_DISABLED                          7051
+#define ERROR_CTX_CLIENT_LICENSE_IN_USE                    7052
+#define ERROR_CTX_CLIENT_LICENSE_NOT_SET                   7053
+#define ERROR_CTX_LICENSE_NOT_AVAILABLE                    7054
+#define ERROR_CTX_LICENSE_CLIENT_INVALID                   7055
+#define ERROR_CTX_LICENSE_EXPIRED                          7056
+#define FRS_ERR_INVALID_API_SEQUENCE                       8001
+#define FRS_ERR_STARTING_SERVICE                           8002
+#define FRS_ERR_STOPPING_SERVICE                           8003
+#define FRS_ERR_INTERNAL_API                               8004
+#define FRS_ERR_INTERNAL                                   8005
+#define FRS_ERR_SERVICE_COMM                               8006
+#define FRS_ERR_INSUFFICIENT_PRIV                          8007
+#define FRS_ERR_AUTHENTICATION                             8008
+#define FRS_ERR_PARENT_INSUFFICIENT_PRIV                   8009
+#define FRS_ERR_PARENT_AUTHENTICATION                      8010
+#define FRS_ERR_CHILD_TO_PARENT_COMM                       8011
+#define FRS_ERR_PARENT_TO_CHILD_COMM                       8012
+#define FRS_ERR_SYSVOL_POPULATE                            8013
+#define FRS_ERR_SYSVOL_POPULATE_TIMEOUT                    8014
+#define FRS_ERR_SYSVOL_IS_BUSY                             8015
+#define FRS_ERR_SYSVOL_DEMOTE                              8016
+#define FRS_ERR_INVALID_SERVICE_PARAMETER                  8017
+#define ERROR_DS_NOT_INSTALLED                             8200
+#define ERROR_DS_MEMBERSHIP_EVALUATED_LOCALLY              8201
+#define ERROR_DS_NO_ATTRIBUTE_OR_VALUE                     8202
+#define ERROR_DS_INVALID_ATTRIBUTE_SYNTAX                  8203
+#define ERROR_DS_ATTRIBUTE_TYPE_UNDEFINED                  8204
+#define ERROR_DS_ATTRIBUTE_OR_VALUE_EXISTS                 8205
+#define ERROR_DS_BUSY                                      8206
+#define ERROR_DS_UNAVAILABLE                               8207
+#define ERROR_DS_NO_RIDS_ALLOCATED                         8208
+#define ERROR_DS_NO_MORE_RIDS                              8209
+#define ERROR_DS_INCORRECT_ROLE_OWNER                      8210
+#define ERROR_DS_RIDMGR_INIT_ERROR                         8211
+#define ERROR_DS_OBJ_CLASS_VIOLATION                       8212
+#define ERROR_DS_CANT_ON_NON_LEAF                          8213
+#define ERROR_DS_CANT_ON_RDN                               8214
+#define ERROR_DS_CANT_MOD_OBJ_CLASS                        8215
+#define ERROR_DS_CROSS_DOM_MOVE_ERROR                      8216
+#define ERROR_DS_GC_NOT_AVAILABLE                          8217
+#define ERROR_SHARED_POLICY                                8218
+#define ERROR_POLICY_OBJECT_NOT_FOUND                      8219
+#define ERROR_POLICY_ONLY_IN_DS                            8220
+#define ERROR_PROMOTION_ACTIVE                             8221
+#define ERROR_NO_PROMOTION_ACTIVE                          8222
+#define ERROR_DS_OPERATIONS_ERROR                          8224
+#define ERROR_DS_PROTOCOL_ERROR                            8225
+#define ERROR_DS_TIMELIMIT_EXCEEDED                        8226
+#define ERROR_DS_SIZELIMIT_EXCEEDED                        8227
+#define ERROR_DS_ADMIN_LIMIT_EXCEEDED                      8228
+#define ERROR_DS_COMPARE_FALSE                             8229
+#define ERROR_DS_COMPARE_TRUE                              8230
+#define ERROR_DS_AUTH_METHOD_NOT_SUPPORTED                 8231
+#define ERROR_DS_STRONG_AUTH_REQUIRED                      8232
+#define ERROR_DS_INAPPROPRIATE_AUTH                        8233
+#define ERROR_DS_AUTH_UNKNOWN                              8234
+#define ERROR_DS_REFERRAL                                  8235
+#define ERROR_DS_UNAVAILABLE_CRIT_EXTENSION                8236
+#define ERROR_DS_CONFIDENTIALITY_REQUIRED                  8237
+#define ERROR_DS_INAPPROPRIATE_MATCHING                    8238
+#define ERROR_DS_CONSTRAINT_VIOLATION                      8239
+#define ERROR_DS_NO_SUCH_OBJECT                            8240
+#define ERROR_DS_ALIAS_PROBLEM                             8241
+#define ERROR_DS_INVALID_DN_SYNTAX                         8242
+#define ERROR_DS_IS_LEAF                                   8243
+#define ERROR_DS_ALIAS_DEREF_PROBLEM                       8244
+#define ERROR_DS_UNWILLING_TO_PERFORM                      8245
+#define ERROR_DS_LOOP_DETECT                               8246
+#define ERROR_DS_NAMING_VIOLATION                          8247
+#define ERROR_DS_OBJECT_RESULTS_TOO_LARGE                  8248
+#define ERROR_DS_AFFECTS_MULTIPLE_DSAS                     8249
+#define ERROR_DS_SERVER_DOWN                               8250
+#define ERROR_DS_LOCAL_ERROR                               8251
+#define ERROR_DS_ENCODING_ERROR                            8252
+#define ERROR_DS_DECODING_ERROR                            8253
+#define ERROR_DS_FILTER_UNKNOWN                            8254
+#define ERROR_DS_PARAM_ERROR                               8255
+#define ERROR_DS_NOT_SUPPORTED                             8256
+#define ERROR_DS_NO_RESULTS_RETURNED                       8257
+#define ERROR_DS_CONTROL_NOT_FOUND                         8258
+#define ERROR_DS_CLIENT_LOOP                               8259
+#define ERROR_DS_REFERRAL_LIMIT_EXCEEDED                   8260
+#define ERROR_DS_ROOT_MUST_BE_NC                           8301
+#define ERROR_DS_ADD_REPLICA_INHIBITED                     8302
+#define ERROR_DS_ATT_NOT_DEF_IN_SCHEMA                     8303
+#define ERROR_DS_MAX_OBJ_SIZE_EXCEEDED                     8304
+#define ERROR_DS_OBJ_STRING_NAME_EXISTS                    8305
+#define ERROR_DS_NO_RDN_DEFINED_IN_SCHEMA                  8306
+#define ERROR_DS_RDN_DOESNT_MATCH_SCHEMA                   8307
+#define ERROR_DS_NO_REQUESTED_ATTS_FOUND                   8308
+#define ERROR_DS_USER_BUFFER_TO_SMALL                      8309
+#define ERROR_DS_ATT_IS_NOT_ON_OBJ                         8310
+#define ERROR_DS_ILLEGAL_MOD_OPERATION                     8311
+#define ERROR_DS_OBJ_TOO_LARGE                             8312
+#define ERROR_DS_BAD_INSTANCE_TYPE                         8313
+#define ERROR_DS_MASTERDSA_REQUIRED                        8314
+#define ERROR_DS_OBJECT_CLASS_REQUIRED                     8315
+#define ERROR_DS_MISSING_REQUIRED_ATT                      8316
+#define ERROR_DS_ATT_NOT_DEF_FOR_CLASS                     8317
+#define ERROR_DS_ATT_ALREADY_EXISTS                        8318
+#define ERROR_DS_CANT_ADD_ATT_VALUES                       8320
+#define ERROR_DS_SINGLE_VALUE_CONSTRAINT                   8321
+#define ERROR_DS_RANGE_CONSTRAINT                          8322
+#define ERROR_DS_ATT_VAL_ALREADY_EXISTS                    8323
+#define ERROR_DS_CANT_REM_MISSING_ATT                      8324
+#define ERROR_DS_CANT_REM_MISSING_ATT_VAL                  8325
+#define ERROR_DS_ROOT_CANT_BE_SUBREF                       8326
+#define ERROR_DS_NO_CHAINING                               8327
+#define ERROR_DS_NO_CHAINED_EVAL                           8328
+#define ERROR_DS_NO_PARENT_OBJECT                          8329
+#define ERROR_DS_PARENT_IS_AN_ALIAS                        8330
+#define ERROR_DS_CANT_MIX_MASTER_AND_REPS                  8331
+#define ERROR_DS_CHILDREN_EXIST                            8332
+#define ERROR_DS_OBJ_NOT_FOUND                             8333
+#define ERROR_DS_ALIASED_OBJ_MISSING                       8334
+#define ERROR_DS_BAD_NAME_SYNTAX                           8335
+#define ERROR_DS_ALIAS_POINTS_TO_ALIAS                     8336
+#define ERROR_DS_CANT_DEREF_ALIAS                          8337
+#define ERROR_DS_OUT_OF_SCOPE                              8338
+#define ERROR_DS_CANT_DELETE_DSA_OBJ                       8340
+#define ERROR_DS_GENERIC_ERROR                             8341
+#define ERROR_DS_DSA_MUST_BE_INT_MASTER                    8342
+#define ERROR_DS_CLASS_NOT_DSA                             8343
+#define ERROR_DS_INSUFF_ACCESS_RIGHTS                      8344
+#define ERROR_DS_ILLEGAL_SUPERIOR                          8345
+#define ERROR_DS_ATTRIBUTE_OWNED_BY_SAM                    8346
+#define ERROR_DS_NAME_TOO_MANY_PARTS                       8347
+#define ERROR_DS_NAME_TOO_LONG                             8348
+#define ERROR_DS_NAME_VALUE_TOO_LONG                       8349
+#define ERROR_DS_NAME_UNPARSEABLE                          8350
+#define ERROR_DS_NAME_TYPE_UNKNOWN                         8351
+#define ERROR_DS_NOT_AN_OBJECT                             8352
+#define ERROR_DS_SEC_DESC_TOO_SHORT                        8353
+#define ERROR_DS_SEC_DESC_INVALID                          8354
+#define ERROR_DS_NO_DELETED_NAME                           8355
+#define ERROR_DS_SUBREF_MUST_HAVE_PARENT                   8356
+#define ERROR_DS_NCNAME_MUST_BE_NC                         8357
+#define ERROR_DS_CANT_ADD_SYSTEM_ONLY                      8358
+#define ERROR_DS_CLASS_MUST_BE_CONCRETE                    8359
+#define ERROR_DS_INVALID_DMD                               8360
+#define ERROR_DS_OBJ_GUID_EXISTS                           8361
+#define ERROR_DS_NOT_ON_BACKLINK                           8362
+#define ERROR_DS_NO_CROSSREF_FOR_NC                        8363
+#define ERROR_DS_SHUTTING_DOWN                             8364
+#define ERROR_DS_UNKNOWN_OPERATION                         8365
+#define ERROR_DS_INVALID_ROLE_OWNER                        8366
+#define ERROR_DS_COULDNT_CONTACT_FSMO                      8367
+#define ERROR_DS_CROSS_NC_DN_RENAME                        8368
+#define ERROR_DS_CANT_MOD_SYSTEM_ONLY                      8369
+#define ERROR_DS_REPLICATOR_ONLY                           8370
+#define ERROR_DS_OBJ_CLASS_NOT_DEFINED                     8371
+#define ERROR_DS_OBJ_CLASS_NOT_SUBCLASS                    8372
+#define ERROR_DS_NAME_REFERENCE_INVALID                    8373
+#define ERROR_DS_CROSS_REF_EXISTS                          8374
+#define ERROR_DS_CANT_DEL_MASTER_CROSSREF                  8375
+#define ERROR_DS_SUBTREE_NOTIFY_NOT_NC_HEAD                8376
+#define ERROR_DS_NOTIFY_FILTER_TOO_COMPLEX                 8377
+#define ERROR_DS_DUP_RDN                                   8378
+#define ERROR_DS_DUP_OID                                   8379
+#define ERROR_DS_DUP_MAPI_ID                               8380
+#define ERROR_DS_DUP_SCHEMA_ID_GUID                        8381
+#define ERROR_DS_DUP_LDAP_DISPLAY_NAME                     8382
+#define ERROR_DS_SEMANTIC_ATT_TEST                         8383
+#define ERROR_DS_SYNTAX_MISMATCH                           8384
+#define ERROR_DS_EXISTS_IN_MUST_HAVE                       8385
+#define ERROR_DS_EXISTS_IN_MAY_HAVE                        8386
+#define ERROR_DS_NONEXISTENT_MAY_HAVE                      8387
+#define ERROR_DS_NONEXISTENT_MUST_HAVE                     8388
+#define ERROR_DS_AUX_CLS_TEST_FAIL                         8389
+#define ERROR_DS_NONEXISTENT_POSS_SUP                      8390
+#define ERROR_DS_SUB_CLS_TEST_FAIL                         8391
+#define ERROR_DS_BAD_RDN_ATT_ID_SYNTAX                     8392
+#define ERROR_DS_EXISTS_IN_AUX_CLS                         8393
+#define ERROR_DS_EXISTS_IN_SUB_CLS                         8394
+#define ERROR_DS_EXISTS_IN_POSS_SUP                        8395
+#define ERROR_DS_RECALCSCHEMA_FAILED                       8396
+#define ERROR_DS_TREE_DELETE_NOT_FINISHED                  8397
+#define ERROR_DS_CANT_DELETE                               8398
+#define ERROR_DS_ATT_SCHEMA_REQ_ID                         8399
+#define ERROR_DS_BAD_ATT_SCHEMA_SYNTAX                     8400
+#define ERROR_DS_CANT_CACHE_ATT                            8401
+#define ERROR_DS_CANT_CACHE_CLASS                          8402
+#define ERROR_DS_CANT_REMOVE_ATT_CACHE                     8403
+#define ERROR_DS_CANT_REMOVE_CLASS_CACHE                   8404
+#define ERROR_DS_CANT_RETRIEVE_DN                          8405
+#define ERROR_DS_MISSING_SUPREF                            8406
+#define ERROR_DS_CANT_RETRIEVE_INSTANCE                    8407
+#define ERROR_DS_CODE_INCONSISTENCY                        8408
+#define ERROR_DS_DATABASE_ERROR                            8409
+#define ERROR_DS_GOVERNSID_MISSING                         8410
+#define ERROR_DS_MISSING_EXPECTED_ATT                      8411
+#define ERROR_DS_NCNAME_MISSING_CR_REF                     8412
+#define ERROR_DS_SECURITY_CHECKING_ERROR                   8413
+#define ERROR_DS_SCHEMA_NOT_LOADED                         8414
+#define ERROR_DS_SCHEMA_ALLOC_FAILED                       8415
+#define ERROR_DS_ATT_SCHEMA_REQ_SYNTAX                     8416
+#define ERROR_DS_GCVERIFY_ERROR                            8417
+#define ERROR_DS_DRA_SCHEMA_MISMATCH                       8418
+#define ERROR_DS_CANT_FIND_DSA_OBJ                         8419
+#define ERROR_DS_CANT_FIND_EXPECTED_NC                     8420
+#define ERROR_DS_CANT_FIND_NC_IN_CACHE                     8421
+#define ERROR_DS_CANT_RETRIEVE_CHILD                       8422
+#define ERROR_DS_SECURITY_ILLEGAL_MODIFY                   8423
+#define ERROR_DS_CANT_REPLACE_HIDDEN_REC                   8424
+#define ERROR_DS_BAD_HIERARCHY_FILE                        8425
+#define ERROR_DS_BUILD_HIERARCHY_TABLE_FAILED              8426
+#define ERROR_DS_CONFIG_PARAM_MISSING                      8427
+#define ERROR_DS_COUNTING_AB_INDICES_FAILED                8428
+#define ERROR_DS_HIERARCHY_TABLE_MALLOC_FAILED             8429
+#define ERROR_DS_INTERNAL_FAILURE                          8430
+#define ERROR_DS_UNKNOWN_ERROR                             8431
+#define ERROR_DS_ROOT_REQUIRES_CLASS_TOP                   8432
+#define ERROR_DS_REFUSING_FSMO_ROLES                       8433
+#define ERROR_DS_MISSING_FSMO_SETTINGS                     8434
+#define ERROR_DS_UNABLE_TO_SURRENDER_ROLES                 8435
+#define ERROR_DS_DRA_GENERIC                               8436
+#define ERROR_DS_DRA_INVALID_PARAMETER                     8437
+#define ERROR_DS_DRA_BUSY                                  8438
+#define ERROR_DS_DRA_BAD_DN                                8439
+#define ERROR_DS_DRA_BAD_NC                                8440
+#define ERROR_DS_DRA_DN_EXISTS                             8441
+#define ERROR_DS_DRA_INTERNAL_ERROR                        8442
+#define ERROR_DS_DRA_INCONSISTENT_DIT                      8443
+#define ERROR_DS_DRA_CONNECTION_FAILED                     8444
+#define ERROR_DS_DRA_BAD_INSTANCE_TYPE                     8445
+#define ERROR_DS_DRA_OUT_OF_MEM                            8446
+#define ERROR_DS_DRA_MAIL_PROBLEM                          8447
+#define ERROR_DS_DRA_REF_ALREADY_EXISTS                    8448
+#define ERROR_DS_DRA_REF_NOT_FOUND                         8449
+#define ERROR_DS_DRA_OBJ_IS_REP_SOURCE                     8450
+#define ERROR_DS_DRA_DB_ERROR                              8451
+#define ERROR_DS_DRA_NO_REPLICA                            8452
+#define ERROR_DS_DRA_ACCESS_DENIED                         8453
+#define ERROR_DS_DRA_NOT_SUPPORTED                         8454
+#define ERROR_DS_DRA_RPC_CANCELLED                         8455
+#define ERROR_DS_DRA_SOURCE_DISABLED                       8456
+#define ERROR_DS_DRA_SINK_DISABLED                         8457
+#define ERROR_DS_DRA_NAME_COLLISION                        8458
+#define ERROR_DS_DRA_SOURCE_REINSTALLED                    8459
+#define ERROR_DS_DRA_MISSING_PARENT                        8460
+#define ERROR_DS_DRA_PREEMPTED                             8461
+#define ERROR_DS_DRA_ABANDON_SYNC                          8462
+#define ERROR_DS_DRA_SHUTDOWN                              8463
+#define ERROR_DS_DRA_INCOMPATIBLE_PARTIAL_SET              8464
+#define ERROR_DS_DRA_SOURCE_IS_PARTIAL_REPLICA             8465
+#define ERROR_DS_DRA_EXTN_CONNECTION_FAILED                8466
+#define ERROR_DS_INSTALL_SCHEMA_MISMATCH                   8467
+#define ERROR_DS_DUP_LINK_ID                               8468
+#define ERROR_DS_NAME_ERROR_RESOLVING                      8469
+#define ERROR_DS_NAME_ERROR_NOT_FOUND                      8470
+#define ERROR_DS_NAME_ERROR_NOT_UNIQUE                     8471
+#define ERROR_DS_NAME_ERROR_NO_MAPPING                     8472
+#define ERROR_DS_NAME_ERROR_DOMAIN_ONLY                    8473
+#define ERROR_DS_NAME_ERROR_NO_SYNTACTICAL_MAPPING         8474
+#define ERROR_DS_CONSTRUCTED_ATT_MOD                       8475
+#define ERROR_DS_WRONG_OM_OBJ_CLASS                        8476
+#define ERROR_DS_DRA_REPL_PENDING                          8477
+#define ERROR_DS_DS_REQUIRED                               8478
+#define ERROR_DS_INVALID_LDAP_DISPLAY_NAME                 8479
+#define ERROR_DS_NON_BASE_SEARCH                           8480
+#define ERROR_DS_CANT_RETRIEVE_ATTS                        8481
+#define ERROR_DS_BACKLINK_WITHOUT_LINK                     8482
+#define ERROR_DS_EPOCH_MISMATCH                            8483
+#define ERROR_DS_SRC_NAME_MISMATCH                         8484
+#define ERROR_DS_SRC_AND_DST_NC_IDENTICAL                  8485
+#define ERROR_DS_DST_NC_MISMATCH                           8486
+#define ERROR_DS_NOT_AUTHORITIVE_FOR_DST_NC                8487
+#define ERROR_DS_SRC_GUID_MISMATCH                         8488
+#define ERROR_DS_CANT_MOVE_DELETED_OBJECT                  8489
+#define ERROR_DS_PDC_OPERATION_IN_PROGRESS                 8490
+#define ERROR_DS_CROSS_DOMAIN_CLEANUP_REQD                 8491
+#define ERROR_DS_ILLEGAL_XDOM_MOVE_OPERATION               8492
+#define ERROR_DS_CANT_WITH_ACCT_GROUP_MEMBERSHPS           8493
+#define ERROR_DS_NC_MUST_HAVE_NC_PARENT                    8494
+#define ERROR_DS_CR_IMPOSSIBLE_TO_VALIDATE                 8495
+#define ERROR_DS_DST_DOMAIN_NOT_NATIVE                     8496
+#define ERROR_DS_MISSING_INFRASTRUCTURE_CONTAINER          8497
+#define ERROR_DS_CANT_MOVE_ACCOUNT_GROUP                   8498
+#define ERROR_DS_CANT_MOVE_RESOURCE_GROUP                  8499
+#define ERROR_DS_INVALID_SEARCH_FLAG                       8500
+#define ERROR_DS_NO_TREE_DELETE_ABOVE_NC                   8501
+#define ERROR_DS_COULDNT_LOCK_TREE_FOR_DELETE              8502
+#define ERROR_DS_COULDNT_IDENTIFY_OBJECTS_FOR_TREE_DELETE  8503
+#define ERROR_DS_SAM_INIT_FAILURE                          8504
+#define ERROR_DS_SENSITIVE_GROUP_VIOLATION                 8505
+#define ERROR_DS_CANT_MOD_PRIMARYGROUPID                   8506
+#define ERROR_DS_ILLEGAL_BASE_SCHEMA_MOD                   8507
+#define ERROR_DS_NONSAFE_SCHEMA_CHANGE                     8508
+#define ERROR_DS_SCHEMA_UPDATE_DISALLOWED                  8509
+#define ERROR_DS_CANT_CREATE_UNDER_SCHEMA                  8510
+#define ERROR_DS_INSTALL_NO_SRC_SCH_VERSION                8511
+#define ERROR_DS_INSTALL_NO_SCH_VERSION_IN_INIFILE         8512
+#define ERROR_DS_INVALID_GROUP_TYPE                        8513
+#define ERROR_DS_NO_NEST_GLOBALGROUP_IN_MIXEDDOMAIN        8514
+#define ERROR_DS_NO_NEST_LOCALGROUP_IN_MIXEDDOMAIN         8515
+#define ERROR_DS_GLOBAL_CANT_HAVE_LOCAL_MEMBER             8516
+#define ERROR_DS_GLOBAL_CANT_HAVE_UNIVERSAL_MEMBER         8517
+#define ERROR_DS_UNIVERSAL_CANT_HAVE_LOCAL_MEMBER          8518
+#define ERROR_DS_GLOBAL_CANT_HAVE_CROSSDOMAIN_MEMBER       8519
+#define ERROR_DS_LOCAL_CANT_HAVE_CROSSDOMAIN_LOCAL_MEMBER  8520
+#define ERROR_DS_HAVE_PRIMARY_MEMBERS                      8521
+#define ERROR_DS_STRING_SD_CONVERSION_FAILED               8522
+#define ERROR_DS_NAMING_MASTER_GC                          8523
+#define ERROR_DS_LOOKUP_FAILURE                            8524
+#define ERROR_DS_COULDNT_UPDATE_SPNS                       8525
+#define ERROR_DS_CANT_RETRIEVE_SD                          8526
+#define ERROR_DS_KEY_NOT_UNIQUE                            8527
+#define ERROR_DS_WRONG_LINKED_ATT_SYNTAX                   8528
+#define ERROR_DS_SAM_NEED_BOOTKEY_PASSWORD                 8529
+#define ERROR_DS_SAM_NEED_BOOTKEY_FLOPPY                   8530
+#define ERROR_DS_CANT_START                                8531
+#define ERROR_DS_INIT_FAILURE                              8532
+#define ERROR_DS_NO_PKT_PRIVACY_ON_CONNECTION              8533
+#define ERROR_DS_SOURCE_DOMAIN_IN_FOREST                   8534
+#define ERROR_DS_DESTINATION_DOMAIN_NOT_IN_FOREST          8535
+#define ERROR_DS_DESTINATION_AUDITING_NOT_ENABLED          8536
+#define ERROR_DS_CANT_FIND_DC_FOR_SRC_DOMAIN               8537
+#define ERROR_DS_SRC_OBJ_NOT_GROUP_OR_USER                 8538
+#define ERROR_DS_SRC_SID_EXISTS_IN_FOREST                  8539
+#define ERROR_DS_SRC_AND_DST_OBJECT_CLASS_MISMATCH         8540
+#define ERROR_SAM_INIT_FAILURE                             8541
+#define ERROR_DS_DRA_SCHEMA_INFO_SHIP                      8542
+#define ERROR_DS_DRA_SCHEMA_CONFLICT                       8543
+#define ERROR_DS_DRA_EARLIER_SCHEMA_CONLICT                8544
+#define ERROR_DS_DRA_OBJ_NC_MISMATCH                       8545
+#define ERROR_DS_NC_STILL_HAS_DSAS                         8546
+#define ERROR_DS_GC_REQUIRED                               8547
+#define ERROR_DS_LOCAL_MEMBER_OF_LOCAL_ONLY                8548
+#define ERROR_DS_NO_FPO_IN_UNIVERSAL_GROUPS                8549
+#define ERROR_DS_CANT_ADD_TO_GC                            8550
+#define ERROR_DS_NO_CHECKPOINT_WITH_PDC                    8551
+#define ERROR_DS_SOURCE_AUDITING_NOT_ENABLED               8552
+#define ERROR_DS_CANT_CREATE_IN_NONDOMAIN_NC               8553
+#define ERROR_DS_INVALID_NAME_FOR_SPN                      8554
+#define ERROR_DS_FILTER_USES_CONTRUCTED_ATTRS              8555
+#define ERROR_DS_UNICODEPWD_NOT_IN_QUOTES                  8556
+#define ERROR_DS_MACHINE_ACCOUNT_QUOTA_EXCEEDED            8557
+#define ERROR_DS_MUST_BE_RUN_ON_DST_DC                     8558
+#define ERROR_DS_SRC_DC_MUST_BE_SP4_OR_GREATER             8559
+#define ERROR_DS_CANT_TREE_DELETE_CRITICAL_OBJ             8560
+#define DNS_ERROR_RCODE_FORMAT_ERROR                       9001
+#define DNS_ERROR_RCODE_SERVER_FAILURE                     9002
+#define DNS_ERROR_RCODE_NAME_ERROR                         9003
+#define DNS_ERROR_RCODE_NOT_IMPLEMENTED                    9004
+#define DNS_ERROR_RCODE_REFUSED                            9005
+#define DNS_ERROR_RCODE_YXDOMAIN                           9006
+#define DNS_ERROR_RCODE_YXRRSET                            9007
+#define DNS_ERROR_RCODE_NXRRSET                            9008
+#define DNS_ERROR_RCODE_NOTAUTH                            9009
+#define DNS_ERROR_RCODE_NOTZONE                            9010
+#define DNS_ERROR_RCODE_BADSIG                             9016
+#define DNS_ERROR_RCODE_BADKEY                             9017
+#define DNS_ERROR_RCODE_BADTIME                            9018
+#define DNS_INFO_NO_RECORDS                                9501
+#define DNS_ERROR_BAD_PACKET                               9502
+#define DNS_ERROR_NO_PACKET                                9503
+#define DNS_ERROR_RCODE                                    9504
+#define DNS_ERROR_UNSECURE_PACKET                          9505
+#define DNS_ERROR_INVALID_TYPE                             9551
+#define DNS_ERROR_INVALID_IP_ADDRESS                       9552
+#define DNS_ERROR_INVALID_PROPERTY                         9553
+#define DNS_ERROR_TRY_AGAIN_LATER                          9554
+#define DNS_ERROR_NOT_UNIQUE                               9555
+#define DNS_ERROR_NON_RFC_NAME                             9556
+#define DNS_STATUS_FQDN                                    9557
+#define DNS_STATUS_DOTTED_NAME                             9558
+#define DNS_STATUS_SINGLE_PART_NAME                        9559
+#define DNS_ERROR_INVALID_NAME_CHAR                        9560
+#define DNS_ERROR_NUMERIC_NAME                             9561
+#define DNS_ERROR_ZONE_DOES_NOT_EXIST                      9601
+#define DNS_ERROR_NO_ZONE_INFO                             9602
+#define DNS_ERROR_INVALID_ZONE_OPERATION                   9603
+#define DNS_ERROR_ZONE_CONFIGURATION_ERROR                 9604
+#define DNS_ERROR_ZONE_HAS_NO_SOA_RECORD                   9605
+#define DNS_ERROR_ZONE_HAS_NO_NS_RECORDS                   9606
+#define DNS_ERROR_ZONE_LOCKED                              9607
+#define DNS_ERROR_ZONE_CREATION_FAILED                     9608
+#define DNS_ERROR_ZONE_ALREADY_EXISTS                      9609
+#define DNS_ERROR_AUTOZONE_ALREADY_EXISTS                  9610
+#define DNS_ERROR_INVALID_ZONE_TYPE                        9611
+#define DNS_ERROR_SECONDARY_REQUIRES_MASTER_IP             9612
+#define DNS_ERROR_ZONE_NOT_SECONDARY                       9613
+#define DNS_ERROR_NEED_SECONDARY_ADDRESSES                 9614
+#define DNS_ERROR_WINS_INIT_FAILED                         9615
+#define DNS_ERROR_NEED_WINS_SERVERS                        9616
+#define DNS_ERROR_NBSTAT_INIT_FAILED                       9617
+#define DNS_ERROR_SOA_DELETE_INVALID                       9618
+#define DNS_ERROR_PRIMARY_REQUIRES_DATAFILE                9651
+#define DNS_ERROR_INVALID_DATAFILE_NAME                    9652
+#define DNS_ERROR_DATAFILE_OPEN_FAILURE                    9653
+#define DNS_ERROR_FILE_WRITEBACK_FAILED                    9654
+#define DNS_ERROR_DATAFILE_PARSING                         9655
+#define DNS_ERROR_RECORD_DOES_NOT_EXIST                    9701
+#define DNS_ERROR_RECORD_FORMAT                            9702
+#define DNS_ERROR_NODE_CREATION_FAILED                     9703
+#define DNS_ERROR_UNKNOWN_RECORD_TYPE                      9704
+#define DNS_ERROR_RECORD_TIMED_OUT                         9705
+#define DNS_ERROR_NAME_NOT_IN_ZONE                         9706
+#define DNS_ERROR_CNAME_LOOP                               9707
+#define DNS_ERROR_NODE_IS_CNAME                            9708
+#define DNS_ERROR_CNAME_COLLISION                          9709
+#define DNS_ERROR_RECORD_ONLY_AT_ZONE_ROOT                 9710
+#define DNS_ERROR_RECORD_ALREADY_EXISTS                    9711
+#define DNS_ERROR_SECONDARY_DATA                           9712
+#define DNS_ERROR_NO_CREATE_CACHE_DATA                     9713
+#define DNS_ERROR_NAME_DOES_NOT_EXIST                      9714
+#define DNS_WARNING_PTR_CREATE_FAILED                      9715
+#define DNS_WARNING_DOMAIN_UNDELETED                       9716
+#define DNS_ERROR_DS_UNAVAILABLE                           9717
+#define DNS_ERROR_DS_ZONE_ALREADY_EXISTS                   9718
+#define DNS_ERROR_NO_BOOTFILE_IF_DS_ZONE                   9719
+#define DNS_INFO_AXFR_COMPLETE                             9751
+#define DNS_ERROR_AXFR                                     9752
+#define DNS_INFO_ADDED_LOCAL_WINS                          9753
+#define DNS_STATUS_CONTINUE_NEEDED                         9801
+#define DNS_ERROR_NO_TCPIP                                 9851
+#define DNS_ERROR_NO_DNS_SERVERS                           9852
+
+/* HRESULT values for OLE, SHELL and other Interface stuff */
+/* the codes 4000-40ff are reserved for OLE */
+#define NOERROR                                0L
+#define S_OK                                   ((HRESULT)0L)
+#define S_FALSE                                ((HRESULT)1L)
+
+#define DISP_E_UNKNOWNINTERFACE 0x80020001L
+#define DISP_E_MEMBERNOTFOUND   0x80020003L
+#define DISP_E_PARAMNOTFOUND    0x80020004L
+#define DISP_E_TYPEMISMATCH     0x80020005L
+#define DISP_E_UNKNOWNNAME      0x80020006L
+#define DISP_E_NONAMEDARGS      0x80020007L
+#define DISP_E_BADVARTYPE   0x80020008L
+#define DISP_E_EXCEPTION        0x80020009L
+#define DISP_E_OVERFLOW     0x8002000AL
+#define DISP_E_BADINDEX         0x8002000BL
+#define DISP_E_UNKNOWNLCID      0x8002000CL
+#define DISP_E_ARRAYISLOCKED    0x8002000DL
+#define DISP_E_BADPARAMCOUNT    0x8002000EL
+#define DISP_E_PARAMNOTOPTIONAL 0x8002000FL
+
+#define TYPE_E_ELEMENTNOTFOUND           0x8002802BL
+#define TYPE_E_CANTLOADLIBRARY  0x80029C4AL
+
+/* OLE Clipboard */
+#define CLIPBRD_E_FIRST         0x800401D0L
+#define CLIPBRD_E_LAST          0x800401DFL
+#define CLIPBRD_S_FIRST         0x000401D0L
+#define CLIPBRD_S_LAST          0x000401DFL
+#define CLIPBRD_E_CANT_OPEN     0x800401D0L
+#define CLIPBRD_E_CANT_EMPTY    0x800401D1L
+#define CLIPBRD_E_CANT_SET      0x800401D2L
+#define CLIPBRD_E_BAD_DATA      0x800401D3L
+#define CLIPBRD_E_CANT_CLOSE    0x800401D4L
+
+/* Drag and Drop */
+#define DRAGDROP_S_DROP   0x00040100L
+#define DRAGDROP_S_CANCEL 0x00040101L
+#define DRAGDROP_E_NOTREGISTERED      0x80040100L
+#define DRAGDROP_E_ALREADYREGISTERED  0x80040101L
+#define DRAGDROP_S_USEDEFAULTCURSORS  0x00040102L
+
+#define	E_UNEXPECTED			0x8000FFFF
+
+#define E_NOTIMPL			0x80004001
+#define E_NOINTERFACE			0x80004002
+#define E_POINTER			0x80004003
+#define E_ABORT				0x80004004
+#define E_FAIL				0x80004005
+#define E_UNSPEC E_FAIL /* must to be defined (used by FileMoniker, IOleLink and DoDragDrop as a return value) */
+
+/*#define CO_E_INIT_TLS			0x80004006
+#define CO_E_INIT_SHARED_ALLOCATOR	0x80004007
+#define CO_E_INIT_MEMORY_ALLOCATOR	0x80004008
+#define CO_E_INIT_CLASS_CACHE		0x80004009
+#define CO_E_INIT_RPC_CHANNEL		0x8000400A
+#define CO_E_INIT_TLS_SET_CHANNEL_CONTROL	0x8000400B
+#define CO_E_INIT_TLS_CHANNEL_CONTROL	0x8000400C
+#define CO_E_INIT_UNACCEPTED_USER_ALLOCATOR	0x8000400D
+#define CO_E_INIT_SCM_MUTEX_EXISTS	0x8000400E
+#define CO_E_INIT_SCM_FILE_MAPPING_EXISTS	0x8000400F
+#define CO_E_INIT_SCM_MAP_VIEW_OF_FILE	0x80004010
+#define CO_E_INIT_SCM_EXEC_FAILURE	0x80004011
+#define CO_E_INIT_ONLY_SINGLE_THREADED	0x80004012 */
+
+#define CO_S_NOTALLINTERFACES           0x00080012
+#define CO_E_NOTINITIALIZED             0x800401F0
+#define CO_E_ERRORINDLL                 0x800401F9
+#define CO_E_OBJISREG                   0x800401FB
+
+#define OLE_E_FIRST 0x80040000L
+#define OLE_E_LAST  0x800400FFL
+#define OLE_S_FIRST 0x00040000L
+#define OLE_S_LAST  0x000400FFL
+
+#define	OLE_E_ENUM_NOMORE		      0x80040002
+#define	OLE_E_ADVISENOTSUPPORTED  0x80040003
+#define	OLE_E_NOCONNECTION        0x80040004
+#define	OLE_E_NOTRUNNING          0x80040005
+#define	OLE_E_NOCACHE             0x80040006
+#define	OLE_E_BLANK		            0x80040007
+#define	OLE_E_NOT_INPLACEACTIVE		0x80040010
+#define	OLE_E_STATIC              0x8004000B
+#define	OLE_E_PROMPTSAVECANCELLED 0x8004000C
+#define OLE_S_USEREG                            0x00040000
+#define OLE_S_STATIC              0x00040001
+
+#define DV_E_FORMATETC            0x80040064
+#define DV_E_DVASPECT             0x8004006B
+#define DV_E_LINDEX               0x80040068
+#define DV_E_TYMED                0x80040069
+
+#define CLASS_E_NOAGGREGATION     0x80040110
+#define	CLASS_E_CLASSNOTAVAILABLE 0x80040111
+
+#define DATA_S_SAMEFORMATETC      0x80040130
+
+#define E_ACCESSDENIED			      0x80070005
+#define E_HANDLE            			0x80070006
+#define	E_OUTOFMEMORY			        0x8007000E
+#define	E_INVALIDARG			        0x80070057
+
+/*#define OLE_E_FIRST 0x80040000L */
+/*#define OLE_E_LAST  0x800400FFL */
+/*#define OLE_S_FIRST 0x00040000L */
+/*#define OLE_S_LAST  0x000400FFL */
+
+#define MK_S_REDUCED_TO_SELF            0x000401E2
+#define MK_S_ME                         0x000401E4
+#define MK_S_HIM                        0x000401E5
+#define MK_S_US                         0x000401E6
+#define MK_S_MONIKERALREADYREGISTERED   0x000401E7
+
+#define MK_E_EXCEEDEDDEADLINE                     0x800401E1
+#define MK_E_NEEDGENERIC                          0x800401E2
+#define MK_E_UNAVAILABLE                          0x800401E3
+#define MK_E_SYNTAX                               0x800401E4
+#define MK_E_NOOBJECT                             0x800401E5
+#define MK_E_INVALIDEXTENSION                     0x800401E6
+#define MK_E_INTERMEDIATEINTERFACENOTSUPPORTED    0x800401E7
+#define MK_E_NOTBINDABLE                          0x800401E8
+#define MK_E_NOTBOUND                             0x800401E9
+#define MK_E_CANTOPENFILE                         0x800401EA
+#define MK_E_MIUSTBOTHERUSER                      0x800401EB
+#define MK_E_NOINVERSE                            0x800401EC
+#define MK_E_NOSTORAGE                            0x800401ED
+#define MK_E_NOPREFIX                             0x800401EE
+
+#define STG_E_INVALIDFUNCTION		0x80030001
+#define STG_E_FILENOTFOUND		0x80030002
+#define STG_E_PATHNOTFOUND		0x80030003
+#define STG_E_TOOMANYOPENFILES		0x80030004
+#define STG_E_ACCESSDENIED		0x80030005
+#define STG_E_INVALIDHANDLE		0x80030006
+#define STG_E_INSUFFICIENTMEMORY	0x80030008
+#define STG_E_INVALIDPOINTER		0x80030009
+#define STG_E_NOMOREFILES		0x80030012
+#define STG_E_DISKISWRITEPROTECTED	0x80030013
+#define STG_E_SEEKERROR			0x80030019
+#define STG_E_WRITEFAULT		0x8003001D
+#define STG_E_READFAULT			0x8003001E
+#define STG_E_SHAREVIOLATION		0x80030020
+#define STG_E_LOCKVIOLATION		0x80030021
+#define STG_E_FILEALREADYEXISTS		0x80030050
+#define STG_E_INVALIDPARAMETER		0x80030057
+#define STG_E_MEDIUMFULL		0x80030070
+#define STG_E_ABNORMALAPIEXIT		0x800300FA
+#define STG_E_INVALIDHEADER		0x800300FB
+#define STG_E_INVALIDNAME		0x800300FC
+#define STG_E_UNKNOWN			0x800300FD
+#define STG_E_UNIMPLEMENTEDFUNCTION	0x800300FE
+#define STG_E_INVALIDFLAG		0x800300FF
+#define STG_E_INUSE			0x80030100
+#define STG_E_NOTCURRENT		0x80030101
+#define STG_E_REVERTED			0x80030102
+#define STG_E_CANTSAVE			0x80030103
+#define STG_E_OLDFORMAT			0x80030104
+#define STG_E_OLDDLL			0x80030105
+#define STG_E_SHAREREQUIRED		0x80030106
+#define STG_E_NOTFILEBASEDSTORAGE	0x80030107
+#define STG_E_EXTANTMARSHALLINGS	0x80030108
+
+#define CONVERT10_E_OLESTREAM_GET       0x800401C0
+#define CONVERT10_E_OLESTREAM_PUT       0x800401C1
+#define CONVERT10_E_OLESTREAM_FMT       0x800401C2
+#define CONVERT10_E_OLESTREAM_BITMAP_TO_DIB 0x800401C3
+#define CONVERT10_E_STG_FMT             0x800401C4
+#define CONVERT10_E_STG_NO_STD_STREAM   0x800401C5
+#define CONVERT10_E_STG_DIB_TO_BITMAP   0x800401C6
+
+/* alten versionen
+#define E_NOTIMPL			0x80000001
+#define E_OUTOFMEMORY			0x80000002
+#define E_INVALIDARG			0x80000003
+#define E_NOINTERFACE			0x80000004
+#define E_POINTER			0x80000005
+#define E_HANDLE			0x80000006
+#define E_ABORT				0x80000007
+#define	E_FAIL				0x80000008
+#define E_ACCESSDENIED			0x80000009 */
+
+/* Obtained from lcc-win32 include files */
+#define GDI_ERROR			0xffffffff
+
+
+/* registry errors */
+#define REGDB_E_READREGDB               0x80040150
+#define REGDB_E_CLASSNOTREG             0x80040154
+
+#define INPLACE_E_NOTUNDOABLE           0x800401A0
+#define INPLACE_E_NOTOOLSPACE           0x800401A1
+
+#define DATA_E_FORMATETC                DV_E_FORMATETC
+
+#define CLASSFACTORY_E_FIRST            0x80040110L
+#define CLASSFACTORY_E_LAST             0x8004011FL
+#define CLASSFACTORY_S_FIRST            0x80040110L
+#define CLASSFACTORY_S_LAST             0x8004011FL
+
+#define CLASS_E_NOTLICENSED             (CLASSFACTORY_E_FIRST+2)
+#define CLASS_E_NOAGGREGATION           0x80040110
+#define	CLASS_E_CLASSNOTAVAILABLE	      0x80040111
+
+
+#define OLEOBJ_E_NOVERBS                0x00040180L
+#define OLEOBJ_E_INVALIDVERB            0x00040181L
+#define OLEOBJ_S_INVALIDVERB            0x00040180L
+
+#endif  /* __WINE_WINERROR_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/winestring.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,13 @@
+#ifndef __WINE_WINE_WINESTRING_H
+#define __WINE_WINE_WINESTRING_H
+
+#include "windef.h"
+
+LPWSTR      WINAPI lstrcpyAtoW(LPWSTR,LPCSTR);
+LPSTR       WINAPI lstrcpyWtoA(LPSTR,LPCWSTR);
+LPWSTR      WINAPI lstrcpynAtoW(LPWSTR,LPCSTR,INT);
+LPSTR       WINAPI lstrcpynWtoA(LPSTR,LPCWSTR,INT);
+
+#define lstrncmpiA strncasecmp
+
+#endif /* __WINE_WINE_WINESTRING_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/winnt.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,2665 @@
+/*
+ * Win32 definitions for Windows NT
+ *
+ * Copyright 1996 Alexandre Julliard
+ */
+
+#ifndef __WINE_WINNT_H
+#define __WINE_WINNT_H
+
+#include "windef.h"
+
+#ifndef RC_INVOKED
+#include <string.h>
+#endif
+
+#include "pshpack1.h"
+/* Defines */
+
+/* Argument 1 passed to the DllEntryProc. */
+#define	DLL_PROCESS_DETACH	0	/* detach process (unload library) */
+#define	DLL_PROCESS_ATTACH	1	/* attach process (load library) */
+#define	DLL_THREAD_ATTACH	2	/* attach new thread */
+#define	DLL_THREAD_DETACH	3	/* detach thread */
+
+
+/* u.x.wProcessorArchitecture (NT) */
+#define PROCESSOR_ARCHITECTURE_INTEL	0
+#define PROCESSOR_ARCHITECTURE_MIPS	1
+#define PROCESSOR_ARCHITECTURE_ALPHA	2
+#define PROCESSOR_ARCHITECTURE_PPC	3
+#define PROCESSOR_ARCHITECTURE_SHX	4
+#define PROCESSOR_ARCHITECTURE_ARM	5
+#define PROCESSOR_ARCHITECTURE_UNKNOWN	0xFFFF
+
+/* dwProcessorType */
+#define PROCESSOR_INTEL_386      386
+#define PROCESSOR_INTEL_486      486
+#define PROCESSOR_INTEL_PENTIUM  586
+#define PROCESSOR_INTEL_860      860
+#define PROCESSOR_MIPS_R2000     2000
+#define PROCESSOR_MIPS_R3000     3000
+#define PROCESSOR_MIPS_R4000     4000
+#define PROCESSOR_ALPHA_21064    21064
+#define PROCESSOR_PPC_601        601
+#define PROCESSOR_PPC_603        603
+#define PROCESSOR_PPC_604        604
+#define PROCESSOR_PPC_620        620
+#define PROCESSOR_HITACHI_SH3    10003
+#define PROCESSOR_HITACHI_SH3E   10004
+#define PROCESSOR_HITACHI_SH4    10005
+#define PROCESSOR_MOTOROLA_821   821
+#define PROCESSOR_SHx_SH3        103
+#define PROCESSOR_SHx_SH4        104
+#define PROCESSOR_STRONGARM      2577
+#define PROCESSOR_ARM720         1824    /* 0x720 */
+#define PROCESSOR_ARM820         2080    /* 0x820 */
+#define PROCESSOR_ARM920         2336    /* 0x920 */
+#define PROCESSOR_ARM_7TDMI      70001
+
+#define ANYSIZE_ARRAY 1
+
+#define MINCHAR       0x80
+#define MAXCHAR       0x7f
+#define MINSHORT      0x8000
+#define MAXSHORT      0x7fff
+#define MINLONG       0x80000000
+#define MAXLONG       0x7fffffff
+#define MAXBYTE       0xff
+#define MAXWORD       0xffff
+#define MAXDWORD      0xffffffff
+
+#define FIELD_OFFSET(type, field) \
+  ((LONG)(INT)&(((type *)0)->field))
+
+#define CONTAINING_RECORD(address, type, field) \
+  ((type *)((PCHAR)(address) - (PCHAR)(&((type *)0)->field)))
+
+/* Types */
+
+/* TCHAR data types definitions for Winelib. */
+/* These types are _not_ defined for the emulator, because they */
+/* depend on the UNICODE macro that only exists in user's code. */
+
+#ifndef __WINE__
+# ifdef UNICODE
+typedef WCHAR TCHAR, *PTCHAR;
+typedef LPWSTR PTSTR, LPTSTR;
+typedef LPCWSTR PCTSTR, LPCTSTR;
+#define __TEXT(string) L##string /*probably wrong */
+# else  /* UNICODE */
+typedef char TCHAR, *PTCHAR;
+typedef LPSTR PTSTR, LPTSTR;
+typedef LPCSTR PCTSTR, LPCTSTR;
+#define __TEXT(string) string
+# endif /* UNICODE */
+#endif   /* __WINE__ */
+#define TEXT(quote) __TEXT(quote)
+
+typedef BYTE     BOOLEAN;
+typedef BOOLEAN *PBOOLEAN;
+
+typedef struct _LIST_ENTRY {
+  struct _LIST_ENTRY *Flink;
+  struct _LIST_ENTRY *Blink;
+} LIST_ENTRY, *PLIST_ENTRY;
+
+typedef struct _SINGLE_LIST_ENTRY {
+  struct _SINGLE_LIST_ENTRY *Next;
+} SINGLE_LIST_ENTRY, *PSINGLE_LIST_ENTRY;
+
+/* Heap flags */
+
+#define HEAP_NO_SERIALIZE               0x00000001
+#define HEAP_GROWABLE                   0x00000002
+#define HEAP_GENERATE_EXCEPTIONS        0x00000004
+#define HEAP_ZERO_MEMORY                0x00000008
+#define HEAP_REALLOC_IN_PLACE_ONLY      0x00000010
+#define HEAP_TAIL_CHECKING_ENABLED      0x00000020
+#define HEAP_FREE_CHECKING_ENABLED      0x00000040
+#define HEAP_DISABLE_COALESCE_ON_FREE   0x00000080
+#define HEAP_CREATE_ALIGN_16            0x00010000
+#define HEAP_CREATE_ENABLE_TRACING      0x00020000
+#define HEAP_WINE_SEGPTR                0x01000000  /* Not a Win32 flag */
+#define HEAP_WINE_CODESEG               0x02000000  /* Not a Win32 flag */
+#define HEAP_WINE_CODE16SEG             0x04000000  /* Not a Win32 flag */
+#define HEAP_WINE_SHARED                0x08000000  /* Not a Win32 flag */
+
+/* Processor feature flags.  */
+#define PF_FLOATING_POINT_PRECISION_ERRATA	0
+#define PF_FLOATING_POINT_EMULATED		1
+#define PF_COMPARE_EXCHANGE_DOUBLE		2
+#define PF_MMX_INSTRUCTIONS_AVAILABLE		3
+#define PF_PPC_MOVEMEM_64BIT_OK			4
+#define PF_ALPHA_BYTE_INSTRUCTIONS		5
+
+
+/* The Win32 register context */
+
+/* CONTEXT is the CPU-dependent context; it should be used        */
+/* wherever a platform-specific context is needed (e.g. exception */
+/* handling, Win32 register functions). */
+
+/* CONTEXT86 is the i386-specific context; it should be used     */
+/* wherever only a 386 context makes sense (e.g. DOS interrupts, */
+/* Win16 register functions), so that this code can be compiled  */
+/* on all platforms. */
+
+#define SIZE_OF_80387_REGISTERS      80
+
+typedef struct _FLOATING_SAVE_AREA
+{
+    DWORD   ControlWord;
+    DWORD   StatusWord;
+    DWORD   TagWord;    
+    DWORD   ErrorOffset;
+    DWORD   ErrorSelector;
+    DWORD   DataOffset;
+    DWORD   DataSelector;    
+    BYTE    RegisterArea[SIZE_OF_80387_REGISTERS];
+    DWORD   Cr0NpxState;
+} FLOATING_SAVE_AREA, *PFLOATING_SAVE_AREA;
+
+typedef struct _CONTEXT86
+{
+    DWORD   ContextFlags;
+
+    /* These are selected by CONTEXT_DEBUG_REGISTERS */
+    DWORD   Dr0;
+    DWORD   Dr1;
+    DWORD   Dr2;
+    DWORD   Dr3;
+    DWORD   Dr6;
+    DWORD   Dr7;
+
+    /* These are selected by CONTEXT_FLOATING_POINT */
+    FLOATING_SAVE_AREA FloatSave;
+
+    /* These are selected by CONTEXT_SEGMENTS */
+    DWORD   SegGs;
+    DWORD   SegFs;
+    DWORD   SegEs;
+    DWORD   SegDs;    
+
+    /* These are selected by CONTEXT_INTEGER */
+    DWORD   Edi;
+    DWORD   Esi;
+    DWORD   Ebx;
+    DWORD   Edx;    
+    DWORD   Ecx;
+    DWORD   Eax;
+
+    /* These are selected by CONTEXT_CONTROL */
+    DWORD   Ebp;    
+    DWORD   Eip;
+    DWORD   SegCs;
+    DWORD   EFlags;
+    DWORD   Esp;
+    DWORD   SegSs;
+} CONTEXT86;
+
+#define CONTEXT_X86       0x00010000
+#define CONTEXT_i386      CONTEXT_X86
+#define CONTEXT_i486      CONTEXT_X86
+
+#define CONTEXT86_CONTROL   (CONTEXT_i386 | 0x0001) /* SS:SP, CS:IP, FLAGS, BP */
+#define CONTEXT86_INTEGER   (CONTEXT_i386 | 0x0002) /* AX, BX, CX, DX, SI, DI */
+#define CONTEXT86_SEGMENTS  (CONTEXT_i386 | 0x0004) /* DS, ES, FS, GS */
+#define CONTEXT86_FLOATING_POINT  (CONTEXT_i386 | 0x0008L) /* 387 state */
+#define CONTEXT86_DEBUG_REGISTERS (CONTEXT_i386 | 0x0010L) /* DB 0-3,6,7 */
+#define CONTEXT86_FULL (CONTEXT86_CONTROL | CONTEXT86_INTEGER | CONTEXT86_SEGMENTS)
+
+/* i386 context definitions */
+#ifdef __i386__
+
+#define CONTEXT_CONTROL         CONTEXT86_CONTROL
+#define CONTEXT_INTEGER         CONTEXT86_INTEGER
+#define CONTEXT_SEGMENTS        CONTEXT86_SEGMENTS
+#define CONTEXT_FLOATING_POINT  CONTEXT86_FLOATING_POINT
+#define CONTEXT_DEBUG_REGISTERS CONTEXT86_DEBUG_REGISTERS
+#define CONTEXT_FULL            CONTEXT86_FULL
+
+typedef CONTEXT86 CONTEXT;
+
+#endif  /* __i386__ */
+
+/* Alpha context definitions */
+#ifdef _ALPHA_
+
+#define CONTEXT_ALPHA   0x00020000
+ 
+#define CONTEXT_CONTROL		(CONTEXT_ALPHA | 0x00000001L)
+#define CONTEXT_FLOATING_POINT	(CONTEXT_ALPHA | 0x00000002L)
+#define CONTEXT_INTEGER		(CONTEXT_ALPHA | 0x00000004L)
+#define CONTEXT_FULL  (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
+
+typedef struct _CONTEXT
+{
+    /* selected by CONTEXT_FLOATING_POINT */
+    ULONGLONG FltF0;
+    ULONGLONG FltF1;
+    ULONGLONG FltF2;
+    ULONGLONG FltF3;
+    ULONGLONG FltF4;
+    ULONGLONG FltF5;
+    ULONGLONG FltF6;
+    ULONGLONG FltF7;
+    ULONGLONG FltF8;
+    ULONGLONG FltF9;
+    ULONGLONG FltF10;
+    ULONGLONG FltF11;
+    ULONGLONG FltF12;
+    ULONGLONG FltF13;
+    ULONGLONG FltF14;
+    ULONGLONG FltF15;
+    ULONGLONG FltF16;
+    ULONGLONG FltF17;
+    ULONGLONG FltF18;
+    ULONGLONG FltF19;
+    ULONGLONG FltF20;
+    ULONGLONG FltF21;
+    ULONGLONG FltF22;
+    ULONGLONG FltF23;
+    ULONGLONG FltF24;
+    ULONGLONG FltF25;
+    ULONGLONG FltF26;
+    ULONGLONG FltF27;
+    ULONGLONG FltF28;
+    ULONGLONG FltF29;
+    ULONGLONG FltF30;
+    ULONGLONG FltF31;
+
+    /* selected by CONTEXT_INTEGER */
+    ULONGLONG IntV0;
+    ULONGLONG IntT0;
+    ULONGLONG IntT1;
+    ULONGLONG IntT2;
+    ULONGLONG IntT3;
+    ULONGLONG IntT4;
+    ULONGLONG IntT5;
+    ULONGLONG IntT6;
+    ULONGLONG IntT7;
+    ULONGLONG IntS0;
+    ULONGLONG IntS1;
+    ULONGLONG IntS2;
+    ULONGLONG IntS3;
+    ULONGLONG IntS4;
+    ULONGLONG IntS5;
+    ULONGLONG IntFp;
+    ULONGLONG IntA0;
+    ULONGLONG IntA1;
+    ULONGLONG IntA2;
+    ULONGLONG IntA3;
+    ULONGLONG IntA4;
+    ULONGLONG IntA5;
+    ULONGLONG IntT8;
+    ULONGLONG IntT9;
+    ULONGLONG IntT10;
+    ULONGLONG IntT11;
+    ULONGLONG IntRa;
+    ULONGLONG IntT12;
+    ULONGLONG IntAt;
+    ULONGLONG IntGp;
+    ULONGLONG IntSp;
+    ULONGLONG IntZero;
+
+    /* selected by CONTEXT_FLOATING_POINT */
+    ULONGLONG Fpcr;
+    ULONGLONG SoftFpcr;
+
+    /* selected by CONTEXT_CONTROL */
+    ULONGLONG Fir;
+    DWORD Psr;
+    DWORD ContextFlags;
+    DWORD Fill[4];
+} CONTEXT;
+
+#define _QUAD_PSR_OFFSET   HighSoftFpcr
+#define _QUAD_FLAGS_OFFSET HighFir
+
+#endif  /* _ALPHA_ */
+
+/* Mips context definitions */
+#ifdef _MIPS_
+
+#define CONTEXT_R4000   0x00010000
+
+#define CONTEXT_CONTROL         (CONTEXT_R4000 | 0x00000001)
+#define CONTEXT_FLOATING_POINT  (CONTEXT_R4000 | 0x00000002)
+#define CONTEXT_INTEGER         (CONTEXT_R4000 | 0x00000004)
+
+#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
+
+typedef struct _CONTEXT
+{
+    DWORD Argument[4];
+    /* These are selected by CONTEXT_FLOATING_POINT */
+    DWORD FltF0;
+    DWORD FltF1;
+    DWORD FltF2;
+    DWORD FltF3;
+    DWORD FltF4;
+    DWORD FltF5;
+    DWORD FltF6;
+    DWORD FltF7;
+    DWORD FltF8;
+    DWORD FltF9;
+    DWORD FltF10;
+    DWORD FltF11;
+    DWORD FltF12;
+    DWORD FltF13;
+    DWORD FltF14;
+    DWORD FltF15;
+    DWORD FltF16;
+    DWORD FltF17;
+    DWORD FltF18;
+    DWORD FltF19;
+    DWORD FltF20;
+    DWORD FltF21;
+    DWORD FltF22;
+    DWORD FltF23;
+    DWORD FltF24;
+    DWORD FltF25;
+    DWORD FltF26;
+    DWORD FltF27;
+    DWORD FltF28;
+    DWORD FltF29;
+    DWORD FltF30;
+    DWORD FltF31;
+
+    /* These are selected by CONTEXT_INTEGER */
+    DWORD IntZero;
+    DWORD IntAt;
+    DWORD IntV0;
+    DWORD IntV1;
+    DWORD IntA0;
+    DWORD IntA1;
+    DWORD IntA2;
+    DWORD IntA3;
+    DWORD IntT0;
+    DWORD IntT1;
+    DWORD IntT2;
+    DWORD IntT3;
+    DWORD IntT4;
+    DWORD IntT5;
+    DWORD IntT6;
+    DWORD IntT7;
+    DWORD IntS0;
+    DWORD IntS1;
+    DWORD IntS2;
+    DWORD IntS3;
+    DWORD IntS4;
+    DWORD IntS5;
+    DWORD IntS6;
+    DWORD IntS7;
+    DWORD IntT8;
+    DWORD IntT9;
+    DWORD IntK0;
+    DWORD IntK1;
+    DWORD IntGp;
+    DWORD IntSp;
+    DWORD IntS8;
+    DWORD IntRa;
+    DWORD IntLo;
+    DWORD IntHi;
+
+    /* These are selected by CONTEXT_FLOATING_POINT */
+    DWORD Fsr;
+
+    /* These are selected by CONTEXT_CONTROL */
+    DWORD Fir;
+    DWORD Psr;
+
+    DWORD ContextFlags;
+    DWORD Fill[2];
+} CONTEXT;
+
+#endif  /* _MIPS_ */
+
+/* PowerPC context definitions */
+#ifdef __PPC__
+
+#define CONTEXT_CONTROL         0x0001
+#define CONTEXT_FLOATING_POINT  0x0002
+#define CONTEXT_INTEGER         0x0004
+#define CONTEXT_DEBUG_REGISTERS 0x0008
+#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
+
+typedef struct
+{
+    /* These are selected by CONTEXT_FLOATING_POINT */
+    double Fpr0;
+    double Fpr1;
+    double Fpr2;
+    double Fpr3;
+    double Fpr4;
+    double Fpr5;
+    double Fpr6;
+    double Fpr7;
+    double Fpr8;
+    double Fpr9;
+    double Fpr10;
+    double Fpr11;
+    double Fpr12;
+    double Fpr13;
+    double Fpr14;
+    double Fpr15;
+    double Fpr16;
+    double Fpr17;
+    double Fpr18;
+    double Fpr19;
+    double Fpr20;
+    double Fpr21;
+    double Fpr22;
+    double Fpr23;
+    double Fpr24;
+    double Fpr25;
+    double Fpr26;
+    double Fpr27;
+    double Fpr28;
+    double Fpr29;
+    double Fpr30;
+    double Fpr31;
+    double Fpscr;
+
+    /* These are selected by CONTEXT_INTEGER */
+    DWORD Gpr0;
+    DWORD Gpr1;
+    DWORD Gpr2;
+    DWORD Gpr3;
+    DWORD Gpr4;
+    DWORD Gpr5;
+    DWORD Gpr6;
+    DWORD Gpr7;
+    DWORD Gpr8;
+    DWORD Gpr9;
+    DWORD Gpr10;
+    DWORD Gpr11;
+    DWORD Gpr12;
+    DWORD Gpr13;
+    DWORD Gpr14;
+    DWORD Gpr15;
+    DWORD Gpr16;
+    DWORD Gpr17;
+    DWORD Gpr18;
+    DWORD Gpr19;
+    DWORD Gpr20;
+    DWORD Gpr21;
+    DWORD Gpr22;
+    DWORD Gpr23;
+    DWORD Gpr24;
+    DWORD Gpr25;
+    DWORD Gpr26;
+    DWORD Gpr27;
+    DWORD Gpr28;
+    DWORD Gpr29;
+    DWORD Gpr30;
+    DWORD Gpr31;
+
+    DWORD Cr;
+    DWORD Xer;
+
+    /* These are selected by CONTEXT_CONTROL */
+    DWORD Msr;
+    DWORD Iar;
+    DWORD Lr;
+    DWORD Ctr;
+
+    DWORD ContextFlags;
+    DWORD Fill[3];
+
+    /* These are selected by CONTEXT_DEBUG_REGISTERS */
+    DWORD Dr0;
+    DWORD Dr1;
+    DWORD Dr2;
+    DWORD Dr3;
+    DWORD Dr4;
+    DWORD Dr5;
+    DWORD Dr6;
+    DWORD Dr7;
+} CONTEXT;
+
+typedef struct _STACK_FRAME_HEADER
+{
+    DWORD BackChain;
+    DWORD GlueSaved1;
+    DWORD GlueSaved2;
+    DWORD Reserved1;
+    DWORD Spare1;
+    DWORD Spare2;
+
+    DWORD Parameter0;
+    DWORD Parameter1;
+    DWORD Parameter2;
+    DWORD Parameter3;
+    DWORD Parameter4;
+    DWORD Parameter5;
+    DWORD Parameter6;
+    DWORD Parameter7;
+} STACK_FRAME_HEADER,*PSTACK_FRAME_HEADER;
+
+#endif  /* __PPC__ */
+
+#ifdef __sparc__
+
+/* 
+ * FIXME:  
+ *
+ * There is no official CONTEXT structure defined for the SPARC 
+ * architecture, so I just made one up.
+ *
+ * This structure is valid only for 32-bit SPARC architectures,
+ * not for 64-bit SPARC.
+ *
+ * Note that this structure contains only the 'top-level' registers;
+ * the rest of the register window chain is not visible.
+ *
+ * The layout follows the Solaris 'prgregset_t' structure.
+ * 
+ */ 
+
+#define CONTEXT_SPARC            0x10000000
+
+#define CONTEXT_CONTROL         (CONTEXT_SPARC | 0x00000001)
+#define CONTEXT_FLOATING_POINT  (CONTEXT_SPARC | 0x00000002)
+#define CONTEXT_INTEGER         (CONTEXT_SPARC | 0x00000004)
+
+#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
+
+typedef struct _CONTEXT
+{
+    DWORD ContextFlags;
+
+    /* These are selected by CONTEXT_INTEGER */
+    DWORD g0;
+    DWORD g1;
+    DWORD g2;
+    DWORD g3;
+    DWORD g4;
+    DWORD g5;
+    DWORD g6;
+    DWORD g7;
+    DWORD o0;
+    DWORD o1;
+    DWORD o2;
+    DWORD o3;
+    DWORD o4;
+    DWORD o5;
+    DWORD o6;
+    DWORD o7;
+    DWORD l0;
+    DWORD l1;
+    DWORD l2;
+    DWORD l3;
+    DWORD l4;
+    DWORD l5;
+    DWORD l6;
+    DWORD l7;
+    DWORD i0;
+    DWORD i1;
+    DWORD i2;
+    DWORD i3;
+    DWORD i4;
+    DWORD i5;
+    DWORD i6;
+    DWORD i7;
+
+    /* These are selected by CONTEXT_CONTROL */
+    DWORD psr;
+    DWORD pc;
+    DWORD npc;
+    DWORD y;
+    DWORD wim;
+    DWORD tbr;
+
+    /* FIXME: floating point registers missing */
+
+} CONTEXT;
+
+#endif  /* __sparc__ */
+
+#if !defined(CONTEXT_FULL) && !defined(RC_INVOKED)
+#error You need to define a CONTEXT for your CPU
+#endif
+
+typedef CONTEXT *PCONTEXT;
+typedef HANDLE *PHANDLE;
+
+#ifdef __WINE__
+
+/* Macros for easier access to i386 context registers */
+
+#define EAX_reg(context)     ((context)->Eax)
+#define EBX_reg(context)     ((context)->Ebx)
+#define ECX_reg(context)     ((context)->Ecx)
+#define EDX_reg(context)     ((context)->Edx)
+#define ESI_reg(context)     ((context)->Esi)
+#define EDI_reg(context)     ((context)->Edi)
+#define EBP_reg(context)     ((context)->Ebp)
+
+#define CS_reg(context)      ((context)->SegCs)
+#define DS_reg(context)      ((context)->SegDs)
+#define ES_reg(context)      ((context)->SegEs)
+#define FS_reg(context)      ((context)->SegFs)
+#define GS_reg(context)      ((context)->SegGs)
+#define SS_reg(context)      ((context)->SegSs)
+
+#define EFL_reg(context)     ((context)->EFlags)
+#define EIP_reg(context)     ((context)->Eip)
+#define ESP_reg(context)     ((context)->Esp)
+
+#define AX_reg(context)      (*(WORD*)&EAX_reg(context))
+#define BX_reg(context)      (*(WORD*)&EBX_reg(context))
+#define CX_reg(context)      (*(WORD*)&ECX_reg(context))
+#define DX_reg(context)      (*(WORD*)&EDX_reg(context))
+#define SI_reg(context)      (*(WORD*)&ESI_reg(context))
+#define DI_reg(context)      (*(WORD*)&EDI_reg(context))
+#define BP_reg(context)      (*(WORD*)&EBP_reg(context))
+
+#define AL_reg(context)      (*(BYTE*)&EAX_reg(context))
+#define AH_reg(context)      (*((BYTE*)&EAX_reg(context)+1))
+#define BL_reg(context)      (*(BYTE*)&EBX_reg(context))
+#define BH_reg(context)      (*((BYTE*)&EBX_reg(context)+1))
+#define CL_reg(context)      (*(BYTE*)&ECX_reg(context))
+#define CH_reg(context)      (*((BYTE*)&ECX_reg(context)+1))
+#define DL_reg(context)      (*(BYTE*)&EDX_reg(context))
+#define DH_reg(context)      (*((BYTE*)&EDX_reg(context)+1))
+                            
+#define SET_CFLAG(context)   (EFL_reg(context) |= 0x0001)
+#define RESET_CFLAG(context) (EFL_reg(context) &= ~0x0001)
+#define SET_ZFLAG(context)   (EFL_reg(context) |= 0x0040)
+#define RESET_ZFLAG(context) (EFL_reg(context) &= ~0x0040)
+
+#define ISV86(context)       (EFL_reg(context) & 0x00020000)
+#define V86BASE(context)     ((context)->Dr7) /* ugly */
+
+
+/* Macros to retrieve the current context */
+
+#ifdef __i386__
+
+#ifdef NEED_UNDERSCORE_PREFIX
+# define __ASM_NAME(name) "_" name
+#else
+# define __ASM_NAME(name) name
+#endif
+
+#ifdef __GNUC__
+# define __ASM_GLOBAL_FUNC(name,code) \
+      __asm__( ".align 4\n\t" \
+               ".globl " __ASM_NAME(#name) "\n\t" \
+               ".type " __ASM_NAME(#name) ",@function\n" \
+               __ASM_NAME(#name) ":\n\t" \
+               code );
+#else  /* __GNUC__ */
+# define __ASM_GLOBAL_FUNC(name,code) \
+      void __asm_dummy_##name(void) { \
+          asm( ".align 4\n\t" \
+               ".globl " __ASM_NAME(#name) "\n\t" \
+               ".type " __ASM_NAME(#name) ",@function\n" \
+               __ASM_NAME(#name) ":\n\t" \
+               code ); \
+      }
+#endif  /* __GNUC__ */
+
+#define _DEFINE_REGS_ENTRYPOINT( name, fn, args ) \
+    __ASM_GLOBAL_FUNC( name, \
+                       "call " __ASM_NAME("CALL32_Regs") "\n\t" \
+                       ".long " __ASM_NAME(#fn) "\n\t" \
+                       ".byte " #args ", " #args )
+#define DEFINE_REGS_ENTRYPOINT_0( name, fn ) \
+  _DEFINE_REGS_ENTRYPOINT( name, fn, 0 )
+#define DEFINE_REGS_ENTRYPOINT_1( name, fn, t1 ) \
+  _DEFINE_REGS_ENTRYPOINT( name, fn, 4 )
+#define DEFINE_REGS_ENTRYPOINT_2( name, fn, t1, t2 ) \
+  _DEFINE_REGS_ENTRYPOINT( name, fn, 8 )
+#define DEFINE_REGS_ENTRYPOINT_3( name, fn, t1, t2, t3 ) \
+  _DEFINE_REGS_ENTRYPOINT( name, fn, 12 )
+#define DEFINE_REGS_ENTRYPOINT_4( name, fn, t1, t2, t3, t4 ) \
+  _DEFINE_REGS_ENTRYPOINT( name, fn, 16 )
+
+#endif  /* __i386__ */
+
+#ifdef __sparc__
+/* FIXME: use getcontext() to retrieve full context */
+#define _GET_CONTEXT \
+    CONTEXT context;   \
+    do { memset(&context, 0, sizeof(CONTEXT));            \
+         context.ContextFlags = CONTEXT_CONTROL;          \
+         context.pc = (DWORD)__builtin_return_address(0); \
+       } while (0)
+
+#define DEFINE_REGS_ENTRYPOINT_0( name, fn ) \
+  void WINAPI name ( void ) \
+  { _GET_CONTEXT; fn( &context ); }
+#define DEFINE_REGS_ENTRYPOINT_1( name, fn, t1 ) \
+  void WINAPI name ( t1 a1 ) \
+  { _GET_CONTEXT; fn( a1, &context ); }
+#define DEFINE_REGS_ENTRYPOINT_2( name, fn, t1, t2 ) \
+  void WINAPI name ( t1 a1, t2 a2 ) \
+  { _GET_CONTEXT; fn( a1, a2, &context ); }
+#define DEFINE_REGS_ENTRYPOINT_3( name, fn, t1, t2, t3 ) \
+  void WINAPI name ( t1 a1, t2 a2, t3 a3 ) \
+  { _GET_CONTEXT; fn( a1, a2, a3, &context ); }
+#define DEFINE_REGS_ENTRYPOINT_4( name, fn, t1, t2, t3, t4 ) \
+  void WINAPI name ( t1 a1, t2 a2, t3 a3, t4 a4 ) \
+  { _GET_CONTEXT; fn( a1, a2, a3, a4, &context ); }
+
+#endif /* __sparc__ */
+
+#ifndef DEFINE_REGS_ENTRYPOINT_0
+#error You need to define DEFINE_REGS_ENTRYPOINT macros for your CPU
+#endif
+
+#ifdef __i386__
+# define GET_IP(context) ((LPVOID)(context)->Eip)
+#endif
+#ifdef __sparc__
+# define GET_IP(context) ((LPVOID)(context)->pc)
+#endif
+ 
+#if !defined(GET_IP) && !defined(RC_INVOKED)
+# error You must define GET_IP for this CPU
+#endif
+
+#endif  /* __WINE__ */
+
+/*
+ * Exception codes
+ */
+
+#define STATUS_SUCCESS                   0x00000000
+#define STATUS_WAIT_0                    0x00000000
+#define STATUS_ABANDONED_WAIT_0          0x00000080
+#define STATUS_USER_APC                  0x000000C0
+#define STATUS_TIMEOUT                   0x00000102
+#define STATUS_PENDING                   0x00000103
+
+#define STATUS_GUARD_PAGE_VIOLATION      0x80000001    
+#define STATUS_DATATYPE_MISALIGNMENT     0x80000002
+#define STATUS_BREAKPOINT                0x80000003
+#define STATUS_SINGLE_STEP               0x80000004
+#define	STATUS_BUFFER_OVERFLOW           0x80000005
+#define STATUS_NO_MORE_FILES             0x80000006
+#define STATUS_WAKE_SYSTEM_DEBUGGER      0x80000007
+
+#define STATUS_HANDLES_CLOSED            0x8000000A
+#define STATUS_NO_INHERITANCE            0x8000000B
+#define STATUS_GUID_SUBSTITUTION_MADE    0x8000000C
+#define STATUS_PARTIAL_COPY              0x8000000D
+#define STATUS_DEVICE_PAPER_EMPTY        0x8000000E
+#define STATUS_DEVICE_POWERED_OFF        0x8000000F
+#define STATUS_DEVICE_OFF_LINE           0x80000010
+#define STATUS_DEVICE_BUSY               0x80000011
+#define STATUS_NO_MORE_EAS               0x80000012
+#define STATUS_INVALID_EA_NAME           0x80000013
+#define STATUS_EA_LIST_INCONSISTENT      0x80000014
+#define STATUS_INVALID_EA_FLAG           0x80000015
+#define STATUS_VERIFY_REQUIRED           0x80000016
+#define STATUS_EXTRANEOUS_INFORMATION    0x80000017
+#define STATUS_RXACT_COMMIT_NECESSARY    0x80000018
+#define STATUS_NO_MORE_ENTRIES           0x8000001A
+#define STATUS_FILEMARK_DETECTED         0x8000001B
+#define STATUS_MEDIA_CHANGED             0x8000001C
+#define STATUS_BUS_RESET                 0x8000001D
+#define STATUS_END_OF_MEDIA              0x8000001E
+#define STATUS_BEGINNING_OF_MEDIA        0x8000001F
+#define STATUS_MEDIA_CHECK               0x80000020
+#define STATUS_SETMARK_DETECTED          0x80000021
+#define STATUS_NO_DATA_DETECTED          0x80000022
+#define STATUS_REDIRECTOR_HAS_OPEN_HANDLES 0x80000023
+#define STATUS_SERVER_HAS_OPEN_HANDLES   0x80000024
+#define STATUS_ALREADY_DISCONNECTED      0x80000025
+#define STATUS_LONGJUMP                  0x80000026
+
+#define STATUS_UNSUCCESSFUL              0xC0000001
+#define STATUS_NOT_IMPLEMENTED           0xC0000002
+#define STATUS_INVALID_INFO_CLASS        0xC0000003
+#define STATUS_INFO_LENGTH_MISMATCH      0xC0000004
+#define STATUS_ACCESS_VIOLATION          0xC0000005
+#define STATUS_IN_PAGE_ERROR             0xC0000006
+#define STATUS_PAGEFILE_QUOTA            0xC0000007
+#define STATUS_INVALID_HANDLE            0xC0000008
+#define STATUS_BAD_INITIAL_STACK         0xC0000009
+#define STATUS_BAD_INITIAL_PC            0xC000000A
+#define STATUS_INVALID_CID               0xC000000B
+#define STATUS_TIMER_NOT_CANCELED        0xC000000C
+#define STATUS_INVALID_PARAMETER         0xC000000D
+#define STATUS_NO_SUCH_DEVICE            0xC000000E
+#define STATUS_NO_SUCH_FILE              0xC000000F
+#define STATUS_INVALID_DEVICE_REQUEST    0xC0000010
+#define STATUS_END_OF_FILE               0xC0000011
+#define STATUS_WRONG_VOLUME              0xC0000012
+#define STATUS_NO_MEDIA_IN_DEVICE        0xC0000013
+#define STATUS_UNRECOGNIZED_MEDIA        0xC0000014
+#define STATUS_NONEXISTENT_SECTOR        0xC0000015
+#define STATUS_MORE_PROCESSING_REQUIRED  0xC0000016
+#define STATUS_NO_MEMORY                 0xC0000017
+#define STATUS_CONFLICTING_ADDRESSES     0xC0000018
+#define STATUS_NOT_MAPPED_VIEW           0xC0000019
+#define STATUS_UNABLE_TO_FREE_VM         0xC000001A
+#define STATUS_UNABLE_TO_DELETE_SECTION  0xC000001B
+#define STATUS_INVALID_SYSTEM_SERVICE    0xC000001C
+#define STATUS_ILLEGAL_INSTRUCTION       0xC000001D
+#define STATUS_INVALID_LOCK_SEQUENCE     0xC000001E
+#define STATUS_INVALID_VIEW_SIZE         0xC000001F
+#define STATUS_INVALID_FILE_FOR_SECTION  0xC0000020
+#define STATUS_ALREADY_COMMITTED         0xC0000021
+#define STATUS_ACCESS_DENIED             0xC0000022
+#define	STATUS_BUFFER_TOO_SMALL          0xC0000023
+#define STATUS_OBJECT_TYPE_MISMATCH      0xC0000024
+#define STATUS_NONCONTINUABLE_EXCEPTION  0xC0000025
+#define STATUS_INVALID_DISPOSITION       0xC0000026
+#define STATUS_UNWIND                    0xC0000027
+#define STATUS_BAD_STACK                 0xC0000028
+#define STATUS_INVALID_UNWIND_TARGET     0xC0000029
+#define STATUS_NOT_LOCKED                0xC000002A
+#define STATUS_PARITY_ERROR              0xC000002B
+#define STATUS_UNABLE_TO_DECOMMIT_VM     0xC000002C
+#define STATUS_NOT_COMMITTED             0xC000002D
+#define STATUS_INVALID_PORT_ATTRIBUTES   0xC000002E
+#define STATUS_PORT_MESSAGE_TOO_LONG     0xC000002F
+#define STATUS_INVALID_PARAMETER_MIX     0xC0000030
+#define STATUS_INVALID_QUOTA_LOWER       0xC0000031
+#define STATUS_DISK_CORRUPT_ERROR        0xC0000032
+#define STATUS_OBJECT_NAME_INVALID       0xC0000033
+#define STATUS_OBJECT_NAME_NOT_FOUND     0xC0000034
+#define STATUS_OBJECT_NAME_COLLISION     0xC0000035
+#define STATUS_PORT_DISCONNECTED         0xC0000037
+#define STATUS_DEVICE_ALREADY_ATTACHED   0xC0000038
+#define STATUS_OBJECT_PATH_INVALID       0xC0000039
+#define STATUS_OBJECT_PATH_NOT_FOUND     0xC000003A
+#define STATUS_PATH_SYNTAX_BAD           0xC000003B
+#define STATUS_DATA_OVERRUN              0xC000003C
+#define STATUS_DATA_LATE_ERROR           0xC000003D
+#define STATUS_DATA_ERROR                0xC000003E
+#define STATUS_CRC_ERROR                 0xC000003F
+#define STATUS_SECTION_TOO_BIG           0xC0000040
+#define STATUS_PORT_CONNECTION_REFUSED   0xC0000041
+#define STATUS_INVALID_PORT_HANDLE       0xC0000042
+#define STATUS_SHARING_VIOLATION         0xC0000043
+#define STATUS_QUOTA_EXCEEDED            0xC0000044
+#define STATUS_INVALID_PAGE_PROTECTION   0xC0000045
+#define STATUS_MUTANT_NOT_OWNED          0xC0000046
+#define STATUS_SEMAPHORE_LIMIT_EXCEEDED  0xC0000047
+#define STATUS_PORT_ALREADY_SET          0xC0000048
+#define STATUS_SUSPEND_COUNT_EXCEEDED    0xC000004A
+#define STATUS_LOCK_NOT_GRANTED          0xC0000054  /* FIXME: not sure */
+#define STATUS_FILE_LOCK_CONFLICT        0xC0000055  /* FIXME: not sure */
+#define	STATUS_UNKNOWN_REVISION          0xC0000058
+#define	STATUS_INVALID_SECURITY_DESCR    0xC0000079
+#define STATUS_DISK_FULL                 0xC000007F 
+#define STATUS_SECTION_NOT_EXTENDED      0xC0000087
+#define STATUS_ARRAY_BOUNDS_EXCEEDED     0xC000008C
+#define STATUS_FLOAT_DENORMAL_OPERAND    0xC000008D
+#define STATUS_FLOAT_DIVIDE_BY_ZERO      0xC000008E
+#define STATUS_FLOAT_INEXACT_RESULT      0xC000008F
+#define STATUS_FLOAT_INVALID_OPERATION   0xC0000090
+#define STATUS_FLOAT_OVERFLOW            0xC0000091
+#define STATUS_FLOAT_STACK_CHECK         0xC0000092
+#define STATUS_FLOAT_UNDERFLOW           0xC0000093
+#define STATUS_INTEGER_DIVIDE_BY_ZERO    0xC0000094
+#define STATUS_INTEGER_OVERFLOW          0xC0000095
+#define STATUS_PRIVILEGED_INSTRUCTION    0xC0000096
+#define STATUS_MEDIA_WRITE_PROTECTED     0XC00000A2
+#define	STATUS_INVALID_PARAMETER_2       0xC00000F0
+#define STATUS_STACK_OVERFLOW            0xC00000FD
+#define STATUS_DIRECTORY_NOT_EMPTY       0xC0000101
+#define STATUS_TOO_MANY_OPENED_FILES     0xC000011F
+#define STATUS_CONTROL_C_EXIT            0xC000013A
+#define STATUS_PIPE_BROKEN               0xC000014B
+#define STATUS_NOT_REGISTRY_FILE         0xC000015C
+#define STATUS_PARTITION_FAILURE         0xC0000172
+#define STATUS_INVALID_BLOCK_LENGTH      0xC0000173
+#define STATUS_DEVICE_NOT_PARTITIONED    0xC0000174
+#define STATUS_UNABLE_TO_LOCK_MEDIA      0xC0000175
+#define STATUS_UNABLE_TO_UNLOAD_MEDIA    0xC0000176
+#define STATUS_EOM_OVERFLOW              0xC0000177
+#define STATUS_NO_MEDIA                  0xC0000178
+#define STATUS_NO_SUCH_MEMBER            0xC000017A
+#define STATUS_INVALID_MEMBER            0xC000017B
+#define STATUS_KEY_DELETED               0xC000017C
+#define STATUS_NO_LOG_SPACE              0xC000017D
+#define STATUS_TOO_MANY_SIDS             0xC000017E
+#define STATUS_LM_CROSS_ENCRYPTION_REQUIRED 0xC000017F
+#define STATUS_KEY_HAS_CHILDREN          0xC0000180
+#define STATUS_CHILD_MUST_BE_VOLATILE    0xC0000181
+#define STATUS_DEVICE_CONFIGURATION_ERROR0xC0000182
+#define STATUS_DRIVER_INTERNAL_ERROR     0xC0000183
+#define STATUS_INVALID_DEVICE_STATE      0xC0000184
+#define STATUS_IO_DEVICE_ERROR           0xC0000185
+#define STATUS_DEVICE_PROTOCOL_ERROR     0xC0000186
+#define STATUS_BACKUP_CONTROLLER         0xC0000187
+#define STATUS_LOG_FILE_FULL             0xC0000188
+#define STATUS_TOO_LATE                  0xC0000189
+#define STATUS_NO_TRUST_LSA_SECRET       0xC000018A
+#define STATUS_NO_TRUST_SAM_ACCOUNT      0xC000018B
+#define STATUS_TRUSTED_DOMAIN_FAILURE    0xC000018C
+#define STATUS_TRUSTED_RELATIONSHIP_FAILURE 0xC000018D
+#define STATUS_EVENTLOG_FILE_CORRUPT     0xC000018E
+#define STATUS_EVENTLOG_CANT_START       0xC000018F
+#define STATUS_TRUST_FAILURE             0xC0000190
+#define STATUS_MUTANT_LIMIT_EXCEEDED     0xC0000191
+#define STATUS_NETLOGON_NOT_STARTED      0xC0000192
+#define STATUS_ACCOUNT_EXPIRED           0xC0000193
+#define STATUS_POSSIBLE_DEADLOCK         0xC0000194
+#define STATUS_NETWORK_CREDENTIAL_CONFLICT 0xC0000195
+#define STATUS_REMOTE_SESSION_LIMIT      0xC0000196
+#define STATUS_EVENTLOG_FILE_CHANGED     0xC0000197
+#define STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT 0xC0000198
+#define STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT 0xC0000199
+#define STATUS_NOLOGON_SERVER_TRUST_ACCOUNT 0xC000019A
+#define STATUS_DOMAIN_TRUST_INCONSISTENT 0xC000019B
+#define STATUS_FS_DRIVER_REQUIRED        0xC000019C
+
+#define STATUS_RESOURCE_LANG_NOT_FOUND   0xC0000204
+
+#define MAXIMUM_WAIT_OBJECTS 64
+#define MAXIMUM_SUSPEND_COUNT 127
+
+
+/*
+ * Return values from the actual exception handlers
+ */
+
+#define ExceptionContinueExecution 0
+#define ExceptionContinueSearch    1
+#define ExceptionNestedException   2
+#define ExceptionCollidedUnwind    3
+ 
+/*
+ * Return values from filters in except() and from UnhandledExceptionFilter
+ */
+ 
+#define EXCEPTION_EXECUTE_HANDLER        1
+#define EXCEPTION_CONTINUE_SEARCH        0
+#define EXCEPTION_CONTINUE_EXECUTION    -1
+
+/*
+ * From OS/2 2.0 exception handling
+ * Win32 seems to use the same flags as ExceptionFlags in an EXCEPTION_RECORD
+ */
+
+#define EH_NONCONTINUABLE   0x01
+#define EH_UNWINDING        0x02
+#define EH_EXIT_UNWIND      0x04
+#define EH_STACK_INVALID    0x08
+#define EH_NESTED_CALL      0x10
+
+#define EXCEPTION_CONTINUABLE        0
+#define EXCEPTION_NONCONTINUABLE     EH_NONCONTINUABLE
+ 
+/*
+ * The exception record used by Win32 to give additional information 
+ * about exception to exception handlers.
+ */
+
+#define EXCEPTION_MAXIMUM_PARAMETERS 15
+
+typedef struct __EXCEPTION_RECORD
+{
+    DWORD    ExceptionCode;
+    DWORD    ExceptionFlags;
+    struct __EXCEPTION_RECORD *ExceptionRecord;
+
+    LPVOID   ExceptionAddress;
+    DWORD    NumberParameters;
+    DWORD    ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
+} EXCEPTION_RECORD, *PEXCEPTION_RECORD;
+
+/*
+ * The exception pointers structure passed to exception filters
+ * in except() and the UnhandledExceptionFilter().
+ */
+ 
+typedef struct _EXCEPTION_POINTERS 
+{
+  PEXCEPTION_RECORD  ExceptionRecord;
+  PCONTEXT           ContextRecord;
+} EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
+
+
+/*
+ * The exception frame, used for registering exception handlers 
+ * Win32 cares only about this, but compilers generally emit 
+ * larger exception frames for their own use.
+ */
+
+struct __EXCEPTION_FRAME;
+
+typedef DWORD (*PEXCEPTION_HANDLER)(PEXCEPTION_RECORD,struct __EXCEPTION_FRAME*,
+                                    PCONTEXT,struct __EXCEPTION_FRAME **);
+
+typedef struct __EXCEPTION_FRAME
+{
+  struct __EXCEPTION_FRAME *Prev;
+  PEXCEPTION_HANDLER       Handler;
+} EXCEPTION_FRAME, *PEXCEPTION_FRAME;
+
+#include "poppack.h"
+
+/*
+ * function pointer to a exception filter
+ */
+
+typedef LONG CALLBACK (*PTOP_LEVEL_EXCEPTION_FILTER)(PEXCEPTION_POINTERS ExceptionInfo);
+typedef PTOP_LEVEL_EXCEPTION_FILTER LPTOP_LEVEL_EXCEPTION_FILTER;
+
+DWORD WINAPI UnhandledExceptionFilter( PEXCEPTION_POINTERS epointers );
+LPTOP_LEVEL_EXCEPTION_FILTER
+WINAPI SetUnhandledExceptionFilter( LPTOP_LEVEL_EXCEPTION_FILTER filter );
+
+/* status values for ContinueDebugEvent */
+#define DBG_CONTINUE                0x00010002
+#define DBG_TERMINATE_THREAD        0x40010003
+#define DBG_TERMINATE_PROCESS       0x40010004
+#define DBG_CONTROL_C               0x40010005
+#define DBG_CONTROL_BREAK           0x40010008
+#define DBG_EXCEPTION_NOT_HANDLED   0x80010001
+
+typedef struct _NT_TIB 
+{
+	struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
+	PVOID StackBase;
+	PVOID StackLimit;
+	PVOID SubSystemTib;
+	union {
+          PVOID FiberData;
+          DWORD Version;
+	} DUMMYUNIONNAME;
+	PVOID ArbitraryUserPointer;
+	struct _NT_TIB *Self;
+} NT_TIB, *PNT_TIB;
+
+struct _TEB;
+/*
+#if defined(__i386__) && defined(__GNUC__)
+extern inline struct _TEB * WINAPI NtCurrentTeb(void);
+extern inline struct _TEB * WINAPI NtCurrentTeb(void)
+{
+    struct _TEB *teb;
+    __asm__(".byte 0x64\n\tmovl (0x18),%0" : "=r" (teb));
+    return teb;
+}
+#else
+extern struct _TEB * WINAPI NtCurrentTeb(void);
+#endif
+*/
+
+/*
+ * File formats definitions
+ */
+
+typedef struct _IMAGE_DOS_HEADER {
+    WORD  e_magic;      /* 00: MZ Header signature */
+    WORD  e_cblp;       /* 02: Bytes on last page of file */
+    WORD  e_cp;         /* 04: Pages in file */
+    WORD  e_crlc;       /* 06: Relocations */
+    WORD  e_cparhdr;    /* 08: Size of header in paragraphs */
+    WORD  e_minalloc;   /* 0a: Minimum extra paragraphs needed */
+    WORD  e_maxalloc;   /* 0c: Maximum extra paragraphs needed */
+    WORD  e_ss;         /* 0e: Initial (relative) SS value */
+    WORD  e_sp;         /* 10: Initial SP value */
+    WORD  e_csum;       /* 12: Checksum */
+    WORD  e_ip;         /* 14: Initial IP value */
+    WORD  e_cs;         /* 16: Initial (relative) CS value */
+    WORD  e_lfarlc;     /* 18: File address of relocation table */
+    WORD  e_ovno;       /* 1a: Overlay number */
+    WORD  e_res[4];     /* 1c: Reserved words */
+    WORD  e_oemid;      /* 24: OEM identifier (for e_oeminfo) */
+    WORD  e_oeminfo;    /* 26: OEM information; e_oemid specific */
+    WORD  e_res2[10];   /* 28: Reserved words */
+    DWORD e_lfanew;     /* 3c: Offset to extended header */
+} IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;
+
+#define IMAGE_DOS_SIGNATURE    0x5A4D     /* MZ   */
+#define IMAGE_OS2_SIGNATURE    0x454E     /* NE   */
+#define IMAGE_OS2_SIGNATURE_LE 0x454C     /* LE   */
+#define IMAGE_OS2_SIGNATURE_LX 0x584C     /* LX */
+#define IMAGE_VXD_SIGNATURE    0x454C     /* LE   */
+#define IMAGE_NT_SIGNATURE     0x00004550 /* PE00 */
+
+/*
+ * This is the Windows executable (NE) header.
+ * the name IMAGE_OS2_HEADER is misleading, but in the SDK this way.
+ */
+typedef struct 
+{
+    WORD  ne_magic;             /* 00 NE signature 'NE' */
+    BYTE  ne_ver;               /* 02 Linker version number */
+    BYTE  ne_rev;               /* 03 Linker revision number */
+    WORD  ne_enttab;            /* 04 Offset to entry table relative to NE */
+    WORD  ne_cbenttab;          /* 06 Length of entry table in bytes */
+    LONG  ne_crc;               /* 08 Checksum */
+    WORD  ne_flags;             /* 0c Flags about segments in this file */
+    WORD  ne_autodata;          /* 0e Automatic data segment number */
+    WORD  ne_heap;              /* 10 Initial size of local heap */
+    WORD  ne_stack;             /* 12 Initial size of stack */
+    DWORD ne_csip;              /* 14 Initial CS:IP */
+    DWORD ne_sssp;              /* 18 Initial SS:SP */
+    WORD  ne_cseg;              /* 1c # of entries in segment table */
+    WORD  ne_cmod;              /* 1e # of entries in module reference tab. */
+    WORD  ne_cbnrestab;         /* 20 Length of nonresident-name table     */
+    WORD  ne_segtab;            /* 22 Offset to segment table */
+    WORD  ne_rsrctab;           /* 24 Offset to resource table */
+    WORD  ne_restab;            /* 26 Offset to resident-name table */
+    WORD  ne_modtab;            /* 28 Offset to module reference table */
+    WORD  ne_imptab;            /* 2a Offset to imported name table */
+    DWORD ne_nrestab;           /* 2c Offset to nonresident-name table */
+    WORD  ne_cmovent;           /* 30 # of movable entry points */
+    WORD  ne_align;             /* 32 Logical sector alignment shift count */
+    WORD  ne_cres;              /* 34 # of resource segments */
+    BYTE  ne_exetyp;            /* 36 Flags indicating target OS */
+    BYTE  ne_flagsothers;       /* 37 Additional information flags */
+    WORD  fastload_offset;      /* 38 Offset to fast load area (should be ne_pretthunks)*/
+    WORD  fastload_length;      /* 3a Length of fast load area (should be ne_psegrefbytes) */
+    WORD  ne_swaparea;          /* 3c Reserved by Microsoft */
+    WORD  ne_expver;            /* 3e Expected Windows version number */
+} IMAGE_OS2_HEADER,*PIMAGE_OS2_HEADER;
+
+typedef struct _IMAGE_VXD_HEADER {
+  WORD  e32_magic;
+  BYTE  e32_border;
+  BYTE  e32_worder;
+  DWORD e32_level;
+  WORD  e32_cpu;
+  WORD  e32_os;
+  DWORD e32_ver;
+  DWORD e32_mflags;
+  DWORD e32_mpages;
+  DWORD e32_startobj;
+  DWORD e32_eip;
+  DWORD e32_stackobj;
+  DWORD e32_esp;
+  DWORD e32_pagesize;
+  DWORD e32_lastpagesize;
+  DWORD e32_fixupsize;
+  DWORD e32_fixupsum;
+  DWORD e32_ldrsize;
+  DWORD e32_ldrsum;
+  DWORD e32_objtab;
+  DWORD e32_objcnt;
+  DWORD e32_objmap;
+  DWORD e32_itermap;
+  DWORD e32_rsrctab;
+  DWORD e32_rsrccnt;
+  DWORD e32_restab;
+  DWORD e32_enttab;
+  DWORD e32_dirtab;
+  DWORD e32_dircnt;
+  DWORD e32_fpagetab;
+  DWORD e32_frectab;
+  DWORD e32_impmod;
+  DWORD e32_impmodcnt;
+  DWORD e32_impproc;
+  DWORD e32_pagesum;
+  DWORD e32_datapage;
+  DWORD e32_preload;
+  DWORD e32_nrestab;
+  DWORD e32_cbnrestab;
+  DWORD e32_nressum;
+  DWORD e32_autodata;
+  DWORD e32_debuginfo;
+  DWORD e32_debuglen;
+  DWORD e32_instpreload;
+  DWORD e32_instdemand;
+  DWORD e32_heapsize;
+  BYTE   e32_res3[12];
+  DWORD e32_winresoff;
+  DWORD e32_winreslen;
+  WORD  e32_devid;
+  WORD  e32_ddkver;
+} IMAGE_VXD_HEADER, *PIMAGE_VXD_HEADER;
+
+
+/* These defines describe the meanings of the bits in the Characteristics
+   field */
+
+#define IMAGE_FILE_RELOCS_STRIPPED	0x0001 /* No relocation info */
+#define IMAGE_FILE_EXECUTABLE_IMAGE	0x0002
+#define IMAGE_FILE_LINE_NUMS_STRIPPED   0x0004
+#define IMAGE_FILE_LOCAL_SYMS_STRIPPED  0x0008
+#define IMAGE_FILE_16BIT_MACHINE	0x0040
+#define IMAGE_FILE_BYTES_REVERSED_LO	0x0080
+#define IMAGE_FILE_32BIT_MACHINE	0x0100
+#define IMAGE_FILE_DEBUG_STRIPPED	0x0200
+#define IMAGE_FILE_SYSTEM		0x1000
+#define IMAGE_FILE_DLL			0x2000
+#define IMAGE_FILE_BYTES_REVERSED_HI	0x8000
+
+/* These are the settings of the Machine field. */
+#define	IMAGE_FILE_MACHINE_UNKNOWN	0
+#define	IMAGE_FILE_MACHINE_I860		0x14d
+#define	IMAGE_FILE_MACHINE_I386		0x14c
+#define	IMAGE_FILE_MACHINE_R3000	0x162
+#define	IMAGE_FILE_MACHINE_R4000	0x166
+#define	IMAGE_FILE_MACHINE_R10000	0x168
+#define	IMAGE_FILE_MACHINE_ALPHA	0x184
+#define	IMAGE_FILE_MACHINE_POWERPC	0x1F0  
+
+#define	IMAGE_SIZEOF_FILE_HEADER	20
+
+/* Possible Magic values */
+#define IMAGE_NT_OPTIONAL_HDR_MAGIC        0x10b
+#define IMAGE_ROM_OPTIONAL_HDR_MAGIC       0x107
+
+/* These are indexes into the DataDirectory array */
+#define IMAGE_FILE_EXPORT_DIRECTORY		0
+#define IMAGE_FILE_IMPORT_DIRECTORY		1
+#define IMAGE_FILE_RESOURCE_DIRECTORY		2
+#define IMAGE_FILE_EXCEPTION_DIRECTORY		3
+#define IMAGE_FILE_SECURITY_DIRECTORY		4
+#define IMAGE_FILE_BASE_RELOCATION_TABLE	5
+#define IMAGE_FILE_DEBUG_DIRECTORY		6
+#define IMAGE_FILE_DESCRIPTION_STRING		7
+#define IMAGE_FILE_MACHINE_VALUE		8  /* Mips */
+#define IMAGE_FILE_THREAD_LOCAL_STORAGE		9
+#define IMAGE_FILE_CALLBACK_DIRECTORY		10
+
+/* Directory Entries, indices into the DataDirectory array */
+
+#define	IMAGE_DIRECTORY_ENTRY_EXPORT		0
+#define	IMAGE_DIRECTORY_ENTRY_IMPORT		1
+#define	IMAGE_DIRECTORY_ENTRY_RESOURCE		2
+#define	IMAGE_DIRECTORY_ENTRY_EXCEPTION		3
+#define	IMAGE_DIRECTORY_ENTRY_SECURITY		4
+#define	IMAGE_DIRECTORY_ENTRY_BASERELOC		5
+#define	IMAGE_DIRECTORY_ENTRY_DEBUG		6
+#define	IMAGE_DIRECTORY_ENTRY_COPYRIGHT		7
+#define	IMAGE_DIRECTORY_ENTRY_GLOBALPTR		8   /* (MIPS GP) */
+#define	IMAGE_DIRECTORY_ENTRY_TLS		9
+#define	IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG	10
+#define	IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT	11
+#define	IMAGE_DIRECTORY_ENTRY_IAT		12  /* Import Address Table */
+#define	IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT	13
+#define	IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR	14
+
+/* Subsystem Values */
+
+#define	IMAGE_SUBSYSTEM_UNKNOWN		0
+#define	IMAGE_SUBSYSTEM_NATIVE		1
+#define	IMAGE_SUBSYSTEM_WINDOWS_GUI	2	/* Windows GUI subsystem */
+#define	IMAGE_SUBSYSTEM_WINDOWS_CUI	3	/* Windows character subsystem*/
+#define	IMAGE_SUBSYSTEM_OS2_CUI		5
+#define	IMAGE_SUBSYSTEM_POSIX_CUI	7
+
+typedef struct _IMAGE_FILE_HEADER {
+  WORD  Machine;
+  WORD  NumberOfSections;
+  DWORD TimeDateStamp;
+  DWORD PointerToSymbolTable;
+  DWORD NumberOfSymbols;
+  WORD  SizeOfOptionalHeader;
+  WORD  Characteristics;
+} IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER;
+
+typedef struct _IMAGE_DATA_DIRECTORY {
+  DWORD VirtualAddress;
+  DWORD Size;
+} IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
+
+#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
+
+typedef struct _IMAGE_OPTIONAL_HEADER {
+
+  /* Standard fields */
+
+  WORD  Magic;
+  BYTE  MajorLinkerVersion;
+  BYTE  MinorLinkerVersion;
+  DWORD SizeOfCode;
+  DWORD SizeOfInitializedData;
+  DWORD SizeOfUninitializedData;
+  DWORD AddressOfEntryPoint;
+  DWORD BaseOfCode;
+  DWORD BaseOfData;
+
+  /* NT additional fields */
+
+  DWORD ImageBase;
+  DWORD SectionAlignment;
+  DWORD FileAlignment;
+  WORD  MajorOperatingSystemVersion;
+  WORD  MinorOperatingSystemVersion;
+  WORD  MajorImageVersion;
+  WORD  MinorImageVersion;
+  WORD  MajorSubsystemVersion;
+  WORD  MinorSubsystemVersion;
+  DWORD Win32VersionValue;
+  DWORD SizeOfImage;
+  DWORD SizeOfHeaders;
+  DWORD CheckSum;
+  WORD  Subsystem;
+  WORD  DllCharacteristics;
+  DWORD SizeOfStackReserve;
+  DWORD SizeOfStackCommit;
+  DWORD SizeOfHeapReserve;
+  DWORD SizeOfHeapCommit;
+  DWORD LoaderFlags;
+  DWORD NumberOfRvaAndSizes;
+  IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
+} IMAGE_OPTIONAL_HEADER, *PIMAGE_OPTIONAL_HEADER;
+
+typedef struct _IMAGE_NT_HEADERS {
+  DWORD Signature;
+  IMAGE_FILE_HEADER FileHeader;
+  IMAGE_OPTIONAL_HEADER OptionalHeader;
+} IMAGE_NT_HEADERS, *PIMAGE_NT_HEADERS;
+
+#define IMAGE_SIZEOF_SHORT_NAME 8
+
+typedef struct _IMAGE_SECTION_HEADER {
+  BYTE  Name[IMAGE_SIZEOF_SHORT_NAME];
+  union {
+    DWORD PhysicalAddress;
+    DWORD VirtualSize;
+  } Misc;
+  DWORD VirtualAddress;
+  DWORD SizeOfRawData;
+  DWORD PointerToRawData;
+  DWORD PointerToRelocations;
+  DWORD PointerToLinenumbers;
+  WORD  NumberOfRelocations;
+  WORD  NumberOfLinenumbers;
+  DWORD Characteristics;
+} IMAGE_SECTION_HEADER, *PIMAGE_SECTION_HEADER;
+
+#define	IMAGE_SIZEOF_SECTION_HEADER 40
+
+#define IMAGE_FIRST_SECTION(ntheader) \
+  ((PIMAGE_SECTION_HEADER)((LPBYTE)&((PIMAGE_NT_HEADERS)(ntheader))->OptionalHeader + \
+                           ((PIMAGE_NT_HEADERS)(ntheader))->FileHeader.SizeOfOptionalHeader))
+
+/* These defines are for the Characteristics bitfield. */
+/* #define IMAGE_SCN_TYPE_REG			0x00000000 - Reserved */
+/* #define IMAGE_SCN_TYPE_DSECT			0x00000001 - Reserved */
+/* #define IMAGE_SCN_TYPE_NOLOAD		0x00000002 - Reserved */
+/* #define IMAGE_SCN_TYPE_GROUP			0x00000004 - Reserved */
+/* #define IMAGE_SCN_TYPE_NO_PAD		0x00000008 - Reserved */
+/* #define IMAGE_SCN_TYPE_COPY			0x00000010 - Reserved */
+
+#define IMAGE_SCN_CNT_CODE			0x00000020
+#define IMAGE_SCN_CNT_INITIALIZED_DATA		0x00000040
+#define IMAGE_SCN_CNT_UNINITIALIZED_DATA	0x00000080
+
+#define	IMAGE_SCN_LNK_OTHER			0x00000100 
+#define	IMAGE_SCN_LNK_INFO			0x00000200  
+/* #define	IMAGE_SCN_TYPE_OVER		0x00000400 - Reserved */
+#define	IMAGE_SCN_LNK_REMOVE			0x00000800
+#define	IMAGE_SCN_LNK_COMDAT			0x00001000
+
+/* 						0x00002000 - Reserved */
+/* #define IMAGE_SCN_MEM_PROTECTED 		0x00004000 - Obsolete */
+#define	IMAGE_SCN_MEM_FARDATA			0x00008000
+
+/* #define IMAGE_SCN_MEM_SYSHEAP		0x00010000 - Obsolete */
+#define	IMAGE_SCN_MEM_PURGEABLE			0x00020000
+#define	IMAGE_SCN_MEM_16BIT			0x00020000
+#define	IMAGE_SCN_MEM_LOCKED			0x00040000
+#define	IMAGE_SCN_MEM_PRELOAD			0x00080000
+
+#define	IMAGE_SCN_ALIGN_1BYTES			0x00100000
+#define	IMAGE_SCN_ALIGN_2BYTES			0x00200000
+#define	IMAGE_SCN_ALIGN_4BYTES			0x00300000
+#define	IMAGE_SCN_ALIGN_8BYTES			0x00400000
+#define	IMAGE_SCN_ALIGN_16BYTES			0x00500000  /* Default */
+#define IMAGE_SCN_ALIGN_32BYTES			0x00600000
+#define IMAGE_SCN_ALIGN_64BYTES			0x00700000
+/* 						0x00800000 - Unused */
+
+#define IMAGE_SCN_LNK_NRELOC_OVFL		0x01000000
+
+
+#define IMAGE_SCN_MEM_DISCARDABLE		0x02000000
+#define IMAGE_SCN_MEM_NOT_CACHED		0x04000000
+#define IMAGE_SCN_MEM_NOT_PAGED			0x08000000
+#define IMAGE_SCN_MEM_SHARED			0x10000000
+#define IMAGE_SCN_MEM_EXECUTE			0x20000000
+#define IMAGE_SCN_MEM_READ			0x40000000
+#define IMAGE_SCN_MEM_WRITE			0x80000000
+
+#include "pshpack2.h"
+
+typedef struct _IMAGE_SYMBOL {
+    union {
+        BYTE    ShortName[8];
+        struct {
+            DWORD   Short;
+            DWORD   Long;
+        } Name;
+        DWORD   LongName[2];
+    } N;
+    DWORD   Value;
+    SHORT   SectionNumber;
+    WORD    Type;
+    BYTE    StorageClass;
+    BYTE    NumberOfAuxSymbols;
+} IMAGE_SYMBOL;
+typedef IMAGE_SYMBOL *PIMAGE_SYMBOL;
+
+#define IMAGE_SIZEOF_SYMBOL 18
+
+typedef struct _IMAGE_LINENUMBER {
+    union {
+        DWORD   SymbolTableIndex;
+        DWORD   VirtualAddress;
+    } Type;
+    WORD    Linenumber;
+} IMAGE_LINENUMBER;
+typedef IMAGE_LINENUMBER *PIMAGE_LINENUMBER;
+
+#define IMAGE_SIZEOF_LINENUMBER  6
+
+typedef union _IMAGE_AUX_SYMBOL {
+    struct {
+        DWORD    TagIndex;
+        union {
+            struct {
+                WORD    Linenumber;
+                WORD    Size;
+            } LnSz;
+           DWORD    TotalSize;
+        } Misc;
+        union {
+            struct {
+                DWORD    PointerToLinenumber;
+                DWORD    PointerToNextFunction;
+            } Function;
+            struct {
+                WORD     Dimension[4];
+            } Array;
+        } FcnAry;
+        WORD    TvIndex;
+    } Sym;
+    struct {
+        BYTE    Name[IMAGE_SIZEOF_SYMBOL];
+    } File;
+    struct {
+        DWORD   Length;
+        WORD    NumberOfRelocations;
+        WORD    NumberOfLinenumbers;
+        DWORD   CheckSum;
+        SHORT   Number;
+        BYTE    Selection;
+    } Section;
+} IMAGE_AUX_SYMBOL;
+typedef IMAGE_AUX_SYMBOL *PIMAGE_AUX_SYMBOL;
+
+#define IMAGE_SIZEOF_AUX_SYMBOL 18
+
+#include "poppack.h"
+
+#define IMAGE_SYM_UNDEFINED           (SHORT)0
+#define IMAGE_SYM_ABSOLUTE            (SHORT)-1
+#define IMAGE_SYM_DEBUG               (SHORT)-2
+
+#define IMAGE_SYM_TYPE_NULL                 0x0000
+#define IMAGE_SYM_TYPE_VOID                 0x0001
+#define IMAGE_SYM_TYPE_CHAR                 0x0002
+#define IMAGE_SYM_TYPE_SHORT                0x0003
+#define IMAGE_SYM_TYPE_INT                  0x0004
+#define IMAGE_SYM_TYPE_LONG                 0x0005
+#define IMAGE_SYM_TYPE_FLOAT                0x0006
+#define IMAGE_SYM_TYPE_DOUBLE               0x0007
+#define IMAGE_SYM_TYPE_STRUCT               0x0008
+#define IMAGE_SYM_TYPE_UNION                0x0009
+#define IMAGE_SYM_TYPE_ENUM                 0x000A
+#define IMAGE_SYM_TYPE_MOE                  0x000B
+#define IMAGE_SYM_TYPE_BYTE                 0x000C
+#define IMAGE_SYM_TYPE_WORD                 0x000D
+#define IMAGE_SYM_TYPE_UINT                 0x000E
+#define IMAGE_SYM_TYPE_DWORD                0x000F
+#define IMAGE_SYM_TYPE_PCODE                0x8000
+
+#define IMAGE_SYM_DTYPE_NULL                0
+#define IMAGE_SYM_DTYPE_POINTER             1
+#define IMAGE_SYM_DTYPE_FUNCTION            2
+#define IMAGE_SYM_DTYPE_ARRAY               3
+
+#define IMAGE_SYM_CLASS_END_OF_FUNCTION     (BYTE )-1
+#define IMAGE_SYM_CLASS_NULL                0x0000
+#define IMAGE_SYM_CLASS_AUTOMATIC           0x0001
+#define IMAGE_SYM_CLASS_EXTERNAL            0x0002
+#define IMAGE_SYM_CLASS_STATIC              0x0003
+#define IMAGE_SYM_CLASS_REGISTER            0x0004
+#define IMAGE_SYM_CLASS_EXTERNAL_DEF        0x0005
+#define IMAGE_SYM_CLASS_LABEL               0x0006
+#define IMAGE_SYM_CLASS_UNDEFINED_LABEL     0x0007
+#define IMAGE_SYM_CLASS_MEMBER_OF_STRUCT    0x0008
+#define IMAGE_SYM_CLASS_ARGUMENT            0x0009
+#define IMAGE_SYM_CLASS_STRUCT_TAG          0x000A
+#define IMAGE_SYM_CLASS_MEMBER_OF_UNION     0x000B
+#define IMAGE_SYM_CLASS_UNION_TAG           0x000C
+#define IMAGE_SYM_CLASS_TYPE_DEFINITION     0x000D
+#define IMAGE_SYM_CLASS_UNDEFINED_STATIC    0x000E
+#define IMAGE_SYM_CLASS_ENUM_TAG            0x000F
+#define IMAGE_SYM_CLASS_MEMBER_OF_ENUM      0x0010
+#define IMAGE_SYM_CLASS_REGISTER_PARAM      0x0011
+#define IMAGE_SYM_CLASS_BIT_FIELD           0x0012
+
+#define IMAGE_SYM_CLASS_FAR_EXTERNAL        0x0044
+#define IMAGE_SYM_CLASS_BLOCK               0x0064
+#define IMAGE_SYM_CLASS_FUNCTION            0x0065
+#define IMAGE_SYM_CLASS_END_OF_STRUCT       0x0066
+#define IMAGE_SYM_CLASS_FILE                0x0067
+#define IMAGE_SYM_CLASS_SECTION             0x0068
+#define IMAGE_SYM_CLASS_WEAK_EXTERNAL       0x0069
+
+#define N_BTMASK                            0x000F
+#define N_TMASK                             0x0030
+#define N_TMASK1                            0x00C0
+#define N_TMASK2                            0x00F0
+#define N_BTSHFT                            4
+#define N_TSHIFT                            2
+
+#define BTYPE(x) ((x) & N_BTMASK)
+
+#ifndef ISPTR
+#define ISPTR(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT))
+#endif
+
+#ifndef ISFCN
+#define ISFCN(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
+#endif
+
+#ifndef ISARY
+#define ISARY(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_ARRAY << N_BTSHFT))
+#endif
+
+#ifndef ISTAG
+#define ISTAG(x) ((x)==IMAGE_SYM_CLASS_STRUCT_TAG || (x)==IMAGE_SYM_CLASS_UNION_TAG || (x)==IMAGE_SYM_CLASS_ENUM_TAG)
+#endif
+
+#ifndef INCREF
+#define INCREF(x) ((((x)&~N_BTMASK)<<N_TSHIFT)|(IMAGE_SYM_DTYPE_POINTER<<N_BTSHFT)|((x)&N_BTMASK))
+#endif
+#ifndef DECREF
+#define DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
+#endif
+
+#define IMAGE_COMDAT_SELECT_NODUPLICATES    1
+#define IMAGE_COMDAT_SELECT_ANY             2
+#define IMAGE_COMDAT_SELECT_SAME_SIZE       3
+#define IMAGE_COMDAT_SELECT_EXACT_MATCH     4
+#define IMAGE_COMDAT_SELECT_ASSOCIATIVE     5
+#define IMAGE_COMDAT_SELECT_LARGEST         6
+#define IMAGE_COMDAT_SELECT_NEWEST          7
+
+#define IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY  1
+#define IMAGE_WEAK_EXTERN_SEARCH_LIBRARY    2
+#define IMAGE_WEAK_EXTERN_SEARCH_ALIAS      3
+
+/* Export module directory */
+
+typedef struct _IMAGE_EXPORT_DIRECTORY {
+	DWORD	Characteristics;
+	DWORD	TimeDateStamp;
+	WORD	MajorVersion;
+	WORD	MinorVersion;
+	DWORD	Name;
+	DWORD	Base;
+	DWORD	NumberOfFunctions;
+	DWORD	NumberOfNames;
+	LPDWORD	*AddressOfFunctions;
+	LPDWORD	*AddressOfNames;
+	LPWORD	*AddressOfNameOrdinals;
+} IMAGE_EXPORT_DIRECTORY,*PIMAGE_EXPORT_DIRECTORY;
+
+/* Import name entry */
+typedef struct _IMAGE_IMPORT_BY_NAME {
+	WORD	Hint;
+	BYTE	Name[1];
+} IMAGE_IMPORT_BY_NAME,*PIMAGE_IMPORT_BY_NAME;
+
+/* Import thunk */
+typedef struct _IMAGE_THUNK_DATA {
+	union {
+		LPBYTE    ForwarderString;
+		FARPROC Function;
+		DWORD     Ordinal;
+		PIMAGE_IMPORT_BY_NAME	AddressOfData;
+	} u1;
+} IMAGE_THUNK_DATA,*PIMAGE_THUNK_DATA;
+
+/* Import module directory */
+
+typedef struct _IMAGE_IMPORT_DESCRIPTOR {
+	union {
+		DWORD	Characteristics; /* 0 for terminating null import descriptor  */
+		PIMAGE_THUNK_DATA OriginalFirstThunk;	/* RVA to original unbound IAT */
+	} u;
+	DWORD	TimeDateStamp;	/* 0 if not bound,
+				 * -1 if bound, and real date\time stamp
+				 *    in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT
+				 * (new BIND)
+				 * otherwise date/time stamp of DLL bound to
+				 * (Old BIND)
+				 */
+	DWORD	ForwarderChain;	/* -1 if no forwarders */
+	DWORD	Name;
+	/* RVA to IAT (if bound this IAT has actual addresses) */
+	PIMAGE_THUNK_DATA FirstThunk;	
+} IMAGE_IMPORT_DESCRIPTOR,*PIMAGE_IMPORT_DESCRIPTOR;
+
+#define	IMAGE_ORDINAL_FLAG		0x80000000
+#define	IMAGE_SNAP_BY_ORDINAL(Ordinal)	((Ordinal & IMAGE_ORDINAL_FLAG) != 0)
+#define	IMAGE_ORDINAL(Ordinal)		(Ordinal & 0xffff)
+
+typedef struct _IMAGE_BOUND_IMPORT_DESCRIPTOR
+{
+    DWORD   TimeDateStamp;
+    WORD    OffsetModuleName;
+    WORD    NumberOfModuleForwarderRefs;
+/* Array of zero or more IMAGE_BOUND_FORWARDER_REF follows */
+} IMAGE_BOUND_IMPORT_DESCRIPTOR,  *PIMAGE_BOUND_IMPORT_DESCRIPTOR;
+
+typedef struct _IMAGE_BOUND_FORWARDER_REF
+{
+    DWORD   TimeDateStamp;
+    WORD    OffsetModuleName;
+    WORD    Reserved;
+} IMAGE_BOUND_FORWARDER_REF, *PIMAGE_BOUND_FORWARDER_REF;
+
+typedef struct _IMAGE_BASE_RELOCATION
+{
+	DWORD	VirtualAddress;
+	DWORD	SizeOfBlock;
+	WORD	TypeOffset[1];
+} IMAGE_BASE_RELOCATION,*PIMAGE_BASE_RELOCATION;
+
+typedef struct _IMAGE_RELOCATION
+{
+    union {
+        DWORD   VirtualAddress;
+        DWORD   RelocCount;
+    } u;
+    DWORD   SymbolTableIndex;
+    WORD    Type;
+} IMAGE_RELOCATION;
+typedef IMAGE_RELOCATION *PIMAGE_RELOCATION;
+
+#define IMAGE_SIZEOF_RELOCATION 10
+
+/* generic relocation types */
+#define IMAGE_REL_BASED_ABSOLUTE 		0
+#define IMAGE_REL_BASED_HIGH			1
+#define IMAGE_REL_BASED_LOW			2
+#define IMAGE_REL_BASED_HIGHLOW			3
+#define IMAGE_REL_BASED_HIGHADJ			4
+#define IMAGE_REL_BASED_MIPS_JMPADDR		5
+#define IMAGE_REL_BASED_SECTION			6
+#define	IMAGE_REL_BASED_REL			7
+#define IMAGE_REL_BASED_MIPS_JMPADDR16		9
+#define IMAGE_REL_BASED_IA64_IMM64		9 /* yes, 9 too */
+#define IMAGE_REL_BASED_DIR64			10
+#define IMAGE_REL_BASED_HIGH3ADJ		11
+
+/* I386 relocation types */
+#define	IMAGE_REL_I386_ABSOLUTE			0
+#define	IMAGE_REL_I386_DIR16			1
+#define	IMAGE_REL_I386_REL16			2
+#define	IMAGE_REL_I386_DIR32			6
+#define	IMAGE_REL_I386_DIR32NB			7
+#define	IMAGE_REL_I386_SEG12			9
+#define	IMAGE_REL_I386_SECTION			10
+#define	IMAGE_REL_I386_SECREL			11
+#define	IMAGE_REL_I386_REL32			20
+
+/* MIPS relocation types */
+#define IMAGE_REL_MIPS_ABSOLUTE		0x0000
+#define IMAGE_REL_MIPS_REFHALF		0x0001
+#define IMAGE_REL_MIPS_REFWORD		0x0002
+#define IMAGE_REL_MIPS_JMPADDR		0x0003
+#define IMAGE_REL_MIPS_REFHI		0x0004
+#define IMAGE_REL_MIPS_REFLO		0x0005
+#define IMAGE_REL_MIPS_GPREL		0x0006
+#define IMAGE_REL_MIPS_LITERAL		0x0007
+#define IMAGE_REL_MIPS_SECTION		0x000A
+#define IMAGE_REL_MIPS_SECREL		0x000B
+#define IMAGE_REL_MIPS_SECRELLO		0x000C
+#define IMAGE_REL_MIPS_SECRELHI		0x000D
+#define	IMAGE_REL_MIPS_JMPADDR16	0x0010
+#define IMAGE_REL_MIPS_REFWORDNB	0x0022
+#define IMAGE_REL_MIPS_PAIR		0x0025
+
+/* ALPHA relocation types */
+#define IMAGE_REL_ALPHA_ABSOLUTE	0x0000
+#define IMAGE_REL_ALPHA_REFLONG		0x0001
+#define IMAGE_REL_ALPHA_REFQUAD		0x0002
+#define IMAGE_REL_ALPHA_GPREL		0x0003
+#define IMAGE_REL_ALPHA_LITERAL		0x0004
+#define IMAGE_REL_ALPHA_LITUSE		0x0005
+#define IMAGE_REL_ALPHA_GPDISP		0x0006
+#define IMAGE_REL_ALPHA_BRADDR		0x0007
+#define IMAGE_REL_ALPHA_HINT		0x0008
+#define IMAGE_REL_ALPHA_INLINE_REFLONG	0x0009
+#define IMAGE_REL_ALPHA_REFHI		0x000A
+#define IMAGE_REL_ALPHA_REFLO		0x000B
+#define IMAGE_REL_ALPHA_PAIR		0x000C
+#define IMAGE_REL_ALPHA_MATCH		0x000D
+#define IMAGE_REL_ALPHA_SECTION		0x000E
+#define IMAGE_REL_ALPHA_SECREL		0x000F
+#define IMAGE_REL_ALPHA_REFLONGNB	0x0010
+#define IMAGE_REL_ALPHA_SECRELLO	0x0011
+#define IMAGE_REL_ALPHA_SECRELHI	0x0012
+#define IMAGE_REL_ALPHA_REFQ3		0x0013
+#define IMAGE_REL_ALPHA_REFQ2		0x0014
+#define IMAGE_REL_ALPHA_REFQ1		0x0015
+#define IMAGE_REL_ALPHA_GPRELLO		0x0016
+#define IMAGE_REL_ALPHA_GPRELHI		0x0017
+
+/* PowerPC relocation types */
+#define IMAGE_REL_PPC_ABSOLUTE          0x0000
+#define IMAGE_REL_PPC_ADDR64            0x0001
+#define IMAGE_REL_PPC_ADDR            0x0002
+#define IMAGE_REL_PPC_ADDR24            0x0003
+#define IMAGE_REL_PPC_ADDR16            0x0004
+#define IMAGE_REL_PPC_ADDR14            0x0005
+#define IMAGE_REL_PPC_REL24             0x0006
+#define IMAGE_REL_PPC_REL14             0x0007
+#define IMAGE_REL_PPC_TOCREL16          0x0008
+#define IMAGE_REL_PPC_TOCREL14          0x0009
+#define IMAGE_REL_PPC_ADDR32NB          0x000A
+#define IMAGE_REL_PPC_SECREL            0x000B
+#define IMAGE_REL_PPC_SECTION           0x000C
+#define IMAGE_REL_PPC_IFGLUE            0x000D
+#define IMAGE_REL_PPC_IMGLUE            0x000E
+#define IMAGE_REL_PPC_SECREL16          0x000F
+#define IMAGE_REL_PPC_REFHI             0x0010
+#define IMAGE_REL_PPC_REFLO             0x0011
+#define IMAGE_REL_PPC_PAIR              0x0012
+#define IMAGE_REL_PPC_SECRELLO          0x0013
+#define IMAGE_REL_PPC_SECRELHI          0x0014
+#define IMAGE_REL_PPC_GPREL		0x0015
+#define IMAGE_REL_PPC_TYPEMASK          0x00FF
+/* modifier bits */
+#define IMAGE_REL_PPC_NEG               0x0100
+#define IMAGE_REL_PPC_BRTAKEN           0x0200
+#define IMAGE_REL_PPC_BRNTAKEN          0x0400
+#define IMAGE_REL_PPC_TOCDEFN           0x0800
+
+/* SH3 ? relocation type */
+#define IMAGE_REL_SH3_ABSOLUTE          0x0000
+#define IMAGE_REL_SH3_DIRECT16          0x0001
+#define IMAGE_REL_SH3_DIRECT          0x0002
+#define IMAGE_REL_SH3_DIRECT8           0x0003
+#define IMAGE_REL_SH3_DIRECT8_WORD      0x0004
+#define IMAGE_REL_SH3_DIRECT8_LONG      0x0005
+#define IMAGE_REL_SH3_DIRECT4           0x0006
+#define IMAGE_REL_SH3_DIRECT4_WORD      0x0007
+#define IMAGE_REL_SH3_DIRECT4_LONG      0x0008
+#define IMAGE_REL_SH3_PCREL8_WORD       0x0009
+#define IMAGE_REL_SH3_PCREL8_LONG       0x000A
+#define IMAGE_REL_SH3_PCREL12_WORD      0x000B
+#define IMAGE_REL_SH3_STARTOF_SECTION   0x000C
+#define IMAGE_REL_SH3_SIZEOF_SECTION    0x000D
+#define IMAGE_REL_SH3_SECTION           0x000E
+#define IMAGE_REL_SH3_SECREL            0x000F
+#define IMAGE_REL_SH3_DIRECT32_NB       0x0010
+
+/* ARM (Archimedes?) relocation types */
+#define IMAGE_REL_ARM_ABSOLUTE		0x0000
+#define IMAGE_REL_ARM_ADDR		0x0001
+#define IMAGE_REL_ARM_ADDR32NB		0x0002
+#define IMAGE_REL_ARM_BRANCH24		0x0003
+#define IMAGE_REL_ARM_BRANCH11		0x0004
+#define IMAGE_REL_ARM_SECTION		0x000E
+#define IMAGE_REL_ARM_SECREL		0x000F
+
+/* IA64 relocation types */
+#define IMAGE_REL_IA64_ABSOLUTE		0x0000
+#define IMAGE_REL_IA64_IMM14		0x0001
+#define IMAGE_REL_IA64_IMM22		0x0002
+#define IMAGE_REL_IA64_IMM64		0x0003
+#define IMAGE_REL_IA64_DIR		0x0004
+#define IMAGE_REL_IA64_DIR64		0x0005
+#define IMAGE_REL_IA64_PCREL21B		0x0006
+#define IMAGE_REL_IA64_PCREL21M		0x0007
+#define IMAGE_REL_IA64_PCREL21F		0x0008
+#define IMAGE_REL_IA64_GPREL22		0x0009
+#define IMAGE_REL_IA64_LTOFF22		0x000A
+#define IMAGE_REL_IA64_SECTION		0x000B
+#define IMAGE_REL_IA64_SECREL22		0x000C
+#define IMAGE_REL_IA64_SECREL64I	0x000D
+#define IMAGE_REL_IA64_SECREL		0x000E
+#define IMAGE_REL_IA64_LTOFF64		0x000F
+#define IMAGE_REL_IA64_DIR32NB		0x0010
+#define IMAGE_REL_IA64_RESERVED_11	0x0011
+#define IMAGE_REL_IA64_RESERVED_12	0x0012
+#define IMAGE_REL_IA64_RESERVED_13	0x0013
+#define IMAGE_REL_IA64_RESERVED_14	0x0014
+#define IMAGE_REL_IA64_RESERVED_15	0x0015
+#define IMAGE_REL_IA64_RESERVED_16	0x0016
+#define IMAGE_REL_IA64_ADDEND		0x001F
+
+/* archive format */
+
+#define IMAGE_ARCHIVE_START_SIZE             8
+#define IMAGE_ARCHIVE_START                  "!<arch>\n"
+#define IMAGE_ARCHIVE_END                    "`\n"
+#define IMAGE_ARCHIVE_PAD                    "\n"
+#define IMAGE_ARCHIVE_LINKER_MEMBER          "/               "
+#define IMAGE_ARCHIVE_LONGNAMES_MEMBER       "//              "
+
+typedef struct _IMAGE_ARCHIVE_MEMBER_HEADER
+{
+    BYTE     Name[16];
+    BYTE     Date[12];
+    BYTE     UserID[6];
+    BYTE     GroupID[6];
+    BYTE     Mode[8];
+    BYTE     Size[10];
+    BYTE     EndHeader[2];
+} IMAGE_ARCHIVE_MEMBER_HEADER, *PIMAGE_ARCHIVE_MEMBER_HEADER;
+
+#define IMAGE_SIZEOF_ARCHIVE_MEMBER_HDR 60
+
+/*
+ * Resource directory stuff
+ */
+typedef struct _IMAGE_RESOURCE_DIRECTORY {
+	DWORD	Characteristics;
+	DWORD	TimeDateStamp;
+	WORD	MajorVersion;
+	WORD	MinorVersion;
+	WORD	NumberOfNamedEntries;
+	WORD	NumberOfIdEntries;
+	/*  IMAGE_RESOURCE_DIRECTORY_ENTRY DirectoryEntries[]; */
+} IMAGE_RESOURCE_DIRECTORY,*PIMAGE_RESOURCE_DIRECTORY;
+
+#define	IMAGE_RESOURCE_NAME_IS_STRING		0x80000000
+#define	IMAGE_RESOURCE_DATA_IS_DIRECTORY	0x80000000
+
+typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
+	union {
+		struct {
+			unsigned NameOffset:31;
+			unsigned NameIsString:1;
+		} s;
+		DWORD   Name;
+		WORD    Id;
+	} u1;
+	union {
+		DWORD   OffsetToData;
+		struct {
+			unsigned OffsetToDirectory:31;
+			unsigned DataIsDirectory:1;
+		} s;
+	} u2;
+} IMAGE_RESOURCE_DIRECTORY_ENTRY,*PIMAGE_RESOURCE_DIRECTORY_ENTRY;
+
+
+typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
+	WORD	Length;
+	CHAR	NameString[ 1 ];
+} IMAGE_RESOURCE_DIRECTORY_STRING,*PIMAGE_RESOURCE_DIRECTORY_STRING;
+
+typedef struct _IMAGE_RESOURCE_DIR_STRING_U {
+	WORD	Length;
+	WCHAR	NameString[ 1 ];
+} IMAGE_RESOURCE_DIR_STRING_U,*PIMAGE_RESOURCE_DIR_STRING_U;
+
+typedef struct _IMAGE_RESOURCE_DATA_ENTRY {
+	DWORD	OffsetToData;
+	DWORD	Size;
+	DWORD	CodePage;
+	DWORD	ResourceHandle;
+} IMAGE_RESOURCE_DATA_ENTRY,*PIMAGE_RESOURCE_DATA_ENTRY;
+
+
+typedef VOID CALLBACK (*PIMAGE_TLS_CALLBACK)(
+	LPVOID DllHandle,DWORD Reason,LPVOID Reserved
+);
+
+typedef struct _IMAGE_TLS_DIRECTORY {
+	DWORD	StartAddressOfRawData;
+	DWORD	EndAddressOfRawData;
+	LPDWORD	AddressOfIndex;
+	PIMAGE_TLS_CALLBACK *AddressOfCallBacks;
+	DWORD	SizeOfZeroFill;
+	DWORD	Characteristics;
+} IMAGE_TLS_DIRECTORY,*PIMAGE_TLS_DIRECTORY;
+
+typedef struct _IMAGE_DEBUG_DIRECTORY {
+  DWORD Characteristics;
+  DWORD TimeDateStamp;
+  WORD  MajorVersion;
+  WORD  MinorVersion;
+  DWORD Type;
+  DWORD SizeOfData;
+  DWORD AddressOfRawData;
+  DWORD PointerToRawData;
+} IMAGE_DEBUG_DIRECTORY, *PIMAGE_DEBUG_DIRECTORY;
+
+#define IMAGE_DEBUG_TYPE_UNKNOWN        0
+#define IMAGE_DEBUG_TYPE_COFF           1
+#define IMAGE_DEBUG_TYPE_CODEVIEW       2
+#define IMAGE_DEBUG_TYPE_FPO            3
+#define IMAGE_DEBUG_TYPE_MISC           4
+#define IMAGE_DEBUG_TYPE_EXCEPTION      5
+#define IMAGE_DEBUG_TYPE_FIXUP          6
+#define IMAGE_DEBUG_TYPE_OMAP_TO_SRC    7
+#define IMAGE_DEBUG_TYPE_OMAP_FROM_SRC  8
+#define IMAGE_DEBUG_TYPE_BORLAND        9
+#define IMAGE_DEBUG_TYPE_RESERVED10    10
+
+typedef struct _IMAGE_COFF_SYMBOLS_HEADER {
+  DWORD NumberOfSymbols;
+  DWORD LvaToFirstSymbol;
+  DWORD NumberOfLinenumbers;
+  DWORD LvaToFirstLinenumber;
+  DWORD RvaToFirstByteOfCode;
+  DWORD RvaToLastByteOfCode;
+  DWORD RvaToFirstByteOfData;
+  DWORD RvaToLastByteOfData;
+} IMAGE_COFF_SYMBOLS_HEADER, *PIMAGE_COFF_SYMBOLS_HEADER;
+
+#define FRAME_FPO       0
+#define FRAME_TRAP      1
+#define FRAME_TSS       2
+#define FRAME_NONFPO    3
+
+typedef struct _FPO_DATA {
+  DWORD ulOffStart;
+  DWORD cbProcSize;
+  DWORD cdwLocals;
+  WORD  cdwParams;
+  unsigned cbProlog : 8;
+  unsigned cbRegs   : 3;
+  unsigned fHasSEH  : 1;
+  unsigned fUseBP   : 1;
+  unsigned reserved : 1;
+  unsigned cbFrame  : 2;
+} FPO_DATA, *PFPO_DATA;
+
+typedef struct _IMAGE_LOAD_CONFIG_DIRECTORY {
+  DWORD Characteristics;
+  DWORD TimeDateStamp;
+  WORD  MajorVersion;
+  WORD  MinorVersion;
+  DWORD GlobalFlagsClear;
+  DWORD GlobalFlagsSet;
+  DWORD CriticalSectionDefaultTimeout;
+  DWORD DeCommitFreeBlockThreshold;
+  DWORD DeCommitTotalFreeThreshold;
+  PVOID LockPrefixTable;
+  DWORD MaximumAllocationSize;
+  DWORD VirtualMemoryThreshold;
+  DWORD ProcessHeapFlags;
+  DWORD ProcessAffinityMask;
+  WORD  CSDVersion;
+  WORD  Reserved1;
+  PVOID EditList;
+  DWORD Reserved[1];
+} IMAGE_LOAD_CONFIG_DIRECTORY, *PIMAGE_LOAD_CONFIG_DIRECTORY;
+
+typedef struct _IMAGE_FUNCTION_ENTRY {
+  DWORD StartingAddress;
+  DWORD EndingAddress;
+  DWORD EndOfPrologue;
+} IMAGE_FUNCTION_ENTRY, *PIMAGE_FUNCTION_ENTRY;
+
+/* This is the structure that appears at the very start of a .DBG file. */
+
+typedef struct _IMAGE_SEPARATE_DEBUG_HEADER {
+	WORD	Signature;
+	WORD	Flags;
+	WORD	Machine;
+	WORD	Characteristics;
+	DWORD	TimeDateStamp;
+	DWORD	CheckSum;
+	DWORD	ImageBase;
+	DWORD	SizeOfImage;
+	DWORD	NumberOfSections;
+	DWORD	ExportedNamesSize;
+	DWORD	DebugDirectorySize;
+	DWORD	SectionAlignment;
+	DWORD	Reserved[ 2 ];
+} IMAGE_SEPARATE_DEBUG_HEADER,*PIMAGE_SEPARATE_DEBUG_HEADER;
+
+#define IMAGE_SEPARATE_DEBUG_SIGNATURE 0x4944
+
+
+typedef struct tagMESSAGE_RESOURCE_ENTRY {
+	WORD	Length;
+	WORD	Flags;
+	BYTE	Text[1];
+} MESSAGE_RESOURCE_ENTRY,*PMESSAGE_RESOURCE_ENTRY;
+#define	MESSAGE_RESOURCE_UNICODE	0x0001
+
+typedef struct tagMESSAGE_RESOURCE_BLOCK {
+	DWORD	LowId;
+	DWORD	HighId;
+	DWORD	OffsetToEntries;
+} MESSAGE_RESOURCE_BLOCK,*PMESSAGE_RESOURCE_BLOCK;
+
+typedef struct tagMESSAGE_RESOURCE_DATA {
+	DWORD			NumberOfBlocks;
+	MESSAGE_RESOURCE_BLOCK	Blocks[ 1 ];
+} MESSAGE_RESOURCE_DATA,*PMESSAGE_RESOURCE_DATA;
+
+/*
+ * Here follows typedefs for security and tokens.
+ */ 
+
+/*
+ * First a constant for the following typdefs.
+ */
+
+#define ANYSIZE_ARRAY   1
+
+/* FIXME:  Orphan.  What does it point to? */
+typedef PVOID PACCESS_TOKEN;
+
+/*
+ * TOKEN_INFORMATION_CLASS
+ */
+
+typedef enum _TOKEN_INFORMATION_CLASS {
+  TokenUser = 1, 
+  TokenGroups, 
+  TokenPrivileges, 
+  TokenOwner, 
+  TokenPrimaryGroup, 
+  TokenDefaultDacl, 
+  TokenSource, 
+  TokenType, 
+  TokenImpersonationLevel, 
+  TokenStatistics 
+} TOKEN_INFORMATION_CLASS; 
+
+#ifndef _SECURITY_DEFINED
+#define _SECURITY_DEFINED
+
+#include "pshpack1.h"
+
+typedef DWORD ACCESS_MASK, *PACCESS_MASK;
+
+typedef struct _GENERIC_MAPPING {
+    ACCESS_MASK GenericRead;
+    ACCESS_MASK GenericWrite;
+    ACCESS_MASK GenericExecute;
+    ACCESS_MASK GenericAll;
+} GENERIC_MAPPING, *PGENERIC_MAPPING;
+
+#ifndef SID_IDENTIFIER_AUTHORITY_DEFINED
+#define SID_IDENTIFIER_AUTHORITY_DEFINED
+typedef struct {
+    BYTE Value[6];
+} SID_IDENTIFIER_AUTHORITY,*PSID_IDENTIFIER_AUTHORITY,*LPSID_IDENTIFIER_AUTHORITY;
+#endif /* !defined(SID_IDENTIFIER_AUTHORITY_DEFINED) */
+
+#ifndef SID_DEFINED
+#define SID_DEFINED
+typedef struct _SID {
+    BYTE Revision;
+    BYTE SubAuthorityCount;
+    SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
+    DWORD SubAuthority[1];
+} SID,*PSID;
+#endif /* !defined(SID_DEFINED) */
+
+#define	SID_REVISION			(1)	/* Current revision */
+#define	SID_MAX_SUB_AUTHORITIES		(15)	/* current max subauths */
+#define	SID_RECOMMENDED_SUB_AUTHORITIES	(1)	/* recommended subauths */
+
+
+/* 
+ * ACL 
+ */
+
+#define ACL_REVISION1 1
+#define ACL_REVISION2 2
+#define ACL_REVISION3 3
+#define ACL_REVISION4 4
+
+#define MIN_ACL_REVISION ACL_REVISION2
+#define MAX_ACL_REVISION ACL_REVISION4
+
+typedef struct _ACL {
+    BYTE AclRevision;
+    BYTE Sbz1;
+    WORD AclSize;
+    WORD AceCount;
+    WORD Sbz2;
+} ACL, *PACL;
+
+/* SECURITY_DESCRIPTOR */
+#define	SECURITY_DESCRIPTOR_REVISION	1
+#define	SECURITY_DESCRIPTOR_REVISION1	1
+
+
+#define	SE_OWNER_DEFAULTED	0x0001
+#define	SE_GROUP_DEFAULTED	0x0002
+#define	SE_DACL_PRESENT		0x0004
+#define	SE_DACL_DEFAULTED	0x0008
+#define	SE_SACL_PRESENT		0x0010
+#define	SE_SACL_DEFAULTED	0x0020
+#define	SE_SELF_RELATIVE	0x8000
+
+typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION;
+typedef WORD SECURITY_DESCRIPTOR_CONTROL, *PSECURITY_DESCRIPTOR_CONTROL;
+
+/* The security descriptor structure */
+typedef struct {
+    BYTE Revision;
+    BYTE Sbz1;
+    SECURITY_DESCRIPTOR_CONTROL Control;
+    DWORD Owner;
+    DWORD Group;
+    DWORD Sacl;
+    DWORD Dacl;
+} SECURITY_DESCRIPTOR_RELATIVE, *PISECURITY_DESCRIPTOR_RELATIVE;
+
+typedef struct {
+    BYTE Revision;
+    BYTE Sbz1;
+    SECURITY_DESCRIPTOR_CONTROL Control;
+    PSID Owner;
+    PSID Group;
+    PACL Sacl;
+    PACL Dacl;
+} SECURITY_DESCRIPTOR, *PSECURITY_DESCRIPTOR;
+
+#define SECURITY_DESCRIPTOR_MIN_LENGTH   (sizeof(SECURITY_DESCRIPTOR)) 
+
+#include "poppack.h"
+
+#endif /* _SECURITY_DEFINED */
+
+#include "pshpack1.h"
+
+/* 
+ * SID_AND_ATTRIBUTES
+ */
+
+typedef struct _SID_AND_ATTRIBUTES {
+  PSID  Sid; 
+  DWORD Attributes; 
+} SID_AND_ATTRIBUTES ; 
+ 
+/* security entities */
+#define SECURITY_NULL_RID			(0x00000000L)
+#define SECURITY_WORLD_RID			(0x00000000L)
+#define SECURITY_LOCAL_RID			(0X00000000L)
+
+#define SECURITY_NULL_SID_AUTHORITY		{0,0,0,0,0,0}
+
+/* S-1-1 */
+#define SECURITY_WORLD_SID_AUTHORITY		{0,0,0,0,0,1}
+
+/* S-1-2 */
+#define SECURITY_LOCAL_SID_AUTHORITY		{0,0,0,0,0,2}
+
+/* S-1-3 */
+#define SECURITY_CREATOR_SID_AUTHORITY		{0,0,0,0,0,3}
+#define SECURITY_CREATOR_OWNER_RID		(0x00000000L) 
+#define SECURITY_CREATOR_GROUP_RID		(0x00000001L)
+#define SECURITY_CREATOR_OWNER_SERVER_RID	(0x00000002L)
+#define SECURITY_CREATOR_GROUP_SERVER_RID	(0x00000003L)
+
+/* S-1-4 */
+#define SECURITY_NON_UNIQUE_AUTHORITY		{0,0,0,0,0,4}
+
+/* S-1-5 */
+#define SECURITY_NT_AUTHORITY			{0,0,0,0,0,5} 
+#define SECURITY_DIALUP_RID                     0x00000001L
+#define SECURITY_NETWORK_RID                    0x00000002L
+#define SECURITY_BATCH_RID                      0x00000003L
+#define SECURITY_INTERACTIVE_RID                0x00000004L
+#define SECURITY_LOGON_IDS_RID                  0x00000005L
+#define SECURITY_SERVICE_RID                    0x00000006L
+#define SECURITY_ANONYMOUS_LOGON_RID            0x00000007L
+#define SECURITY_PROXY_RID                      0x00000008L
+#define SECURITY_ENTERPRISE_CONTROLLERS_RID     0x00000009L
+#define SECURITY_PRINCIPAL_SELF_RID             0x0000000AL
+#define SECURITY_AUTHENTICATED_USER_RID         0x0000000BL
+#define SECURITY_RESTRICTED_CODE_RID            0x0000000CL
+#define SECURITY_TERMINAL_SERVER_RID            0x0000000DL
+#define SECURITY_LOCAL_SYSTEM_RID               0x00000012L
+#define SECURITY_NT_NON_UNIQUE                  0x00000015L
+#define SECURITY_BUILTIN_DOMAIN_RID             0x00000020L
+
+#define DOMAIN_GROUP_RID_ADMINS                 0x00000200L
+#define DOMAIN_GROUP_RID_USERS                  0x00000201L
+#define DOMAIN_GROUP_RID_GUESTS                 0x00000202L
+
+#define DOMAIN_ALIAS_RID_ADMINS                 0x00000220L
+#define DOMAIN_ALIAS_RID_USERS                  0x00000221L
+#define DOMAIN_ALIAS_RID_GUESTS                 0x00000222L
+
+#define SECURITY_SERVER_LOGON_RID		SECURITY_ENTERPRISE_CONTROLLERS_RID
+
+#define SECURITY_LOGON_IDS_RID_COUNT		(3L)
+
+/*
+ * TOKEN_USER
+ */
+
+typedef struct _TOKEN_USER {
+  SID_AND_ATTRIBUTES User; 
+} TOKEN_USER; 
+
+/*
+ * TOKEN_GROUPS
+ */
+
+typedef struct _TOKEN_GROUPS  {
+  DWORD GroupCount; 
+  SID_AND_ATTRIBUTES Groups[ANYSIZE_ARRAY]; 
+} TOKEN_GROUPS; 
+
+/*
+ * LUID_AND_ATTRIBUTES
+ */
+
+typedef union _LARGE_INTEGER {
+    struct {
+        DWORD    LowPart;
+        LONG     HighPart;
+    } DUMMYSTRUCTNAME;
+    LONGLONG QuadPart;
+} LARGE_INTEGER, *LPLARGE_INTEGER, *PLARGE_INTEGER;
+
+typedef union _ULARGE_INTEGER {
+    struct {
+        DWORD    LowPart;
+        LONG     HighPart;
+    } DUMMYSTRUCTNAME;
+    LONGLONG QuadPart;
+} ULARGE_INTEGER, *LPULARGE_INTEGER, *PULARGE_INTEGER;
+
+/*
+ * Locally Unique Identifier
+ */
+
+typedef LARGE_INTEGER LUID,*PLUID;
+
+typedef struct _LUID_AND_ATTRIBUTES {
+  LUID   Luid; 
+  DWORD  Attributes; 
+} LUID_AND_ATTRIBUTES; 
+
+/*
+ * PRIVILEGE_SET
+ */
+
+typedef struct _PRIVILEGE_SET {
+    DWORD PrivilegeCount;
+    DWORD Control;
+    LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
+} PRIVILEGE_SET, *PPRIVILEGE_SET;
+
+/*
+ * TOKEN_PRIVILEGES
+ */
+
+typedef struct _TOKEN_PRIVILEGES {
+  DWORD PrivilegeCount; 
+  LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]; 
+} TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES; 
+
+/*
+ * TOKEN_OWNER
+ */
+
+typedef struct _TOKEN_OWNER {
+  PSID Owner; 
+} TOKEN_OWNER; 
+
+/*
+ * TOKEN_PRIMARY_GROUP
+ */
+
+typedef struct _TOKEN_PRIMARY_GROUP {
+  PSID PrimaryGroup; 
+} TOKEN_PRIMARY_GROUP; 
+
+
+/*
+ * TOKEN_DEFAULT_DACL
+ */
+
+typedef struct _TOKEN_DEFAULT_DACL { 
+  PACL DefaultDacl; 
+} TOKEN_DEFAULT_DACL; 
+
+/*
+ * TOKEN_SOURCEL
+ */
+
+typedef struct _TOKEN_SOURCE {
+  char Sourcename[8]; 
+  LUID SourceIdentifier; 
+} TOKEN_SOURCE; 
+
+/*
+ * TOKEN_TYPE
+ */
+
+typedef enum tagTOKEN_TYPE {
+  TokenPrimary = 1, 
+  TokenImpersonation 
+} TOKEN_TYPE; 
+
+/*
+ * SECURITY_IMPERSONATION_LEVEL
+ */
+
+typedef enum _SECURITY_IMPERSONATION_LEVEL {
+  SecurityAnonymous, 
+  SecurityIdentification, 
+  SecurityImpersonation, 
+  SecurityDelegation 
+} SECURITY_IMPERSONATION_LEVEL, *PSECURITY_IMPERSONATION_LEVEL; 
+
+
+typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE,
+	* PSECURITY_CONTEXT_TRACKING_MODE;
+/*
+ *	Quality of Service
+ */
+
+typedef struct _SECURITY_QUALITY_OF_SERVICE {
+  DWORD				Length;
+  SECURITY_IMPERSONATION_LEVEL	ImpersonationLevel;
+  SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
+  WIN_BOOL				EffectiveOnly;
+} SECURITY_QUALITY_OF_SERVICE, *PSECURITY_QUALITY_OF_SERVICE;
+
+/*
+ * TOKEN_STATISTICS
+ */
+
+typedef struct _TOKEN_STATISTICS {
+  LUID  TokenId; 
+  LUID  AuthenticationId; 
+  LARGE_INTEGER ExpirationTime; 
+  TOKEN_TYPE    TokenType; 
+  SECURITY_IMPERSONATION_LEVEL ImpersonationLevel; 
+  DWORD DynamicCharged; 
+  DWORD DynamicAvailable; 
+  DWORD GroupCount; 
+  DWORD PrivilegeCount; 
+  LUID  ModifiedId; 
+} TOKEN_STATISTICS; 
+
+/* 
+ *	ACLs of NT 
+ */
+
+#define	ACL_REVISION	2
+
+#define	ACL_REVISION1	1
+#define	ACL_REVISION2	2
+
+/* ACEs, directly starting after an ACL */
+typedef struct _ACE_HEADER {
+	BYTE	AceType;
+	BYTE	AceFlags;
+	WORD	AceSize;
+} ACE_HEADER,*PACE_HEADER;
+
+/* AceType */
+#define	ACCESS_ALLOWED_ACE_TYPE		0
+#define	ACCESS_DENIED_ACE_TYPE		1
+#define	SYSTEM_AUDIT_ACE_TYPE		2
+#define	SYSTEM_ALARM_ACE_TYPE		3
+
+/* inherit AceFlags */
+#define	OBJECT_INHERIT_ACE		0x01
+#define	CONTAINER_INHERIT_ACE		0x02
+#define	NO_PROPAGATE_INHERIT_ACE	0x04
+#define	INHERIT_ONLY_ACE		0x08
+#define	VALID_INHERIT_FLAGS		0x0F
+
+/* AceFlags mask for what events we (should) audit */
+#define	SUCCESSFUL_ACCESS_ACE_FLAG	0x40
+#define	FAILED_ACCESS_ACE_FLAG		0x80
+
+/* different ACEs depending on AceType 
+ * SidStart marks the begin of a SID
+ * so the thing finally looks like this:
+ * 0: ACE_HEADER
+ * 4: ACCESS_MASK
+ * 8... : SID
+ */
+typedef struct _ACCESS_ALLOWED_ACE {
+	ACE_HEADER	Header;
+	DWORD		Mask;
+	DWORD		SidStart;
+} ACCESS_ALLOWED_ACE,*PACCESS_ALLOWED_ACE;
+
+typedef struct _ACCESS_DENIED_ACE {
+	ACE_HEADER	Header;
+	DWORD		Mask;
+	DWORD		SidStart;
+} ACCESS_DENIED_ACE,*PACCESS_DENIED_ACE;
+
+typedef struct _SYSTEM_AUDIT_ACE {
+	ACE_HEADER	Header;
+	DWORD		Mask;
+	DWORD		SidStart;
+} SYSTEM_AUDIT_ACE,*PSYSTEM_AUDIT_ACE;
+
+typedef struct _SYSTEM_ALARM_ACE {
+	ACE_HEADER	Header;
+	DWORD		Mask;
+	DWORD		SidStart;
+} SYSTEM_ALARM_ACE,*PSYSTEM_ALARM_ACE;
+
+typedef enum tagSID_NAME_USE {
+	SidTypeUser = 1,
+	SidTypeGroup,
+	SidTypeDomain,
+	SidTypeAlias,
+	SidTypeWellKnownGroup,
+	SidTypeDeletedAccount,
+	SidTypeInvalid,
+	SidTypeUnknown
+} SID_NAME_USE,*PSID_NAME_USE;
+
+/* Access rights */
+
+#define DELETE                     0x00010000
+#define READ_CONTROL               0x00020000
+#define WRITE_DAC                  0x00040000
+#define WRITE_OWNER                0x00080000
+#define SYNCHRONIZE                0x00100000
+#define STANDARD_RIGHTS_REQUIRED   0x000f0000
+
+#define STANDARD_RIGHTS_READ       READ_CONTROL
+#define STANDARD_RIGHTS_WRITE      READ_CONTROL
+#define STANDARD_RIGHTS_EXECUTE    READ_CONTROL
+
+#define STANDARD_RIGHTS_ALL        0x001f0000
+
+#define SPECIFIC_RIGHTS_ALL        0x0000ffff
+
+#define GENERIC_READ               0x80000000
+#define GENERIC_WRITE              0x40000000
+#define GENERIC_EXECUTE            0x20000000
+#define GENERIC_ALL                0x10000000
+
+#define MAXIMUM_ALLOWED            0x02000000
+#define ACCESS_SYSTEM_SECURITY     0x01000000
+
+#define EVENT_MODIFY_STATE         0x0002
+#define EVENT_ALL_ACCESS           (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
+
+#define SEMAPHORE_MODIFY_STATE     0x0002
+#define SEMAPHORE_ALL_ACCESS       (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
+
+#define MUTEX_MODIFY_STATE         0x0001
+#define MUTEX_ALL_ACCESS           (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x1)
+
+#define PROCESS_TERMINATE          0x0001
+#define PROCESS_CREATE_THREAD      0x0002
+#define PROCESS_VM_OPERATION       0x0008
+#define PROCESS_VM_READ            0x0010
+#define PROCESS_VM_WRITE           0x0020
+#define PROCESS_DUP_HANDLE         0x0040
+#define PROCESS_CREATE_PROCESS     0x0080
+#define PROCESS_SET_QUOTA          0x0100
+#define PROCESS_SET_INFORMATION    0x0200
+#define PROCESS_QUERY_INFORMATION  0x0400
+#define PROCESS_ALL_ACCESS         (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0xfff)
+
+#define THREAD_TERMINATE           0x0001
+#define THREAD_SUSPEND_RESUME      0x0002
+#define THREAD_GET_CONTEXT         0x0008
+#define THREAD_SET_CONTEXT         0x0010
+#define THREAD_SET_INFORMATION     0x0020
+#define THREAD_QUERY_INFORMATION   0x0040
+#define THREAD_SET_THREAD_TOKEN    0x0080
+#define THREAD_IMPERSONATE         0x0100
+#define THREAD_DIRECT_IMPERSONATION 0x0200
+#define THREAD_ALL_ACCESS          (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3ff)
+
+#define THREAD_BASE_PRIORITY_LOWRT  15 
+#define THREAD_BASE_PRIORITY_MAX    2 
+#define THREAD_BASE_PRIORITY_MIN   -2
+#define THREAD_BASE_PRIORITY_IDLE  -15
+
+#define FILE_READ_DATA            0x0001    /* file & pipe */
+#define FILE_LIST_DIRECTORY       0x0001    /* directory */
+#define FILE_WRITE_DATA           0x0002    /* file & pipe */
+#define FILE_ADD_FILE             0x0002    /* directory */
+#define FILE_APPEND_DATA          0x0004    /* file */
+#define FILE_ADD_SUBDIRECTORY     0x0004    /* directory */
+#define FILE_CREATE_PIPE_INSTANCE 0x0004    /* named pipe */
+#define FILE_READ_EA              0x0008    /* file & directory */
+#define FILE_READ_PROPERTIES      FILE_READ_EA
+#define FILE_WRITE_EA             0x0010    /* file & directory */
+#define FILE_WRITE_PROPERTIES     FILE_WRITE_EA
+#define FILE_EXECUTE              0x0020    /* file */
+#define FILE_TRAVERSE             0x0020    /* directory */
+#define FILE_DELETE_CHILD         0x0040    /* directory */
+#define FILE_READ_ATTRIBUTES      0x0080    /* all */
+#define FILE_WRITE_ATTRIBUTES     0x0100    /* all */
+#define FILE_ALL_ACCESS           (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x1ff)
+
+#define FILE_GENERIC_READ         (STANDARD_RIGHTS_READ | FILE_READ_DATA | \
+                                   FILE_READ_ATTRIBUTES | FILE_READ_EA | \
+                                   SYNCHRONIZE)
+#define FILE_GENERIC_WRITE        (STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA | \
+                                   FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA | \
+                                   FILE_APPEND_DATA | SYNCHRONIZE)
+#define FILE_GENERIC_EXECUTE      (STANDARD_RIGHTS_EXECUTE | FILE_EXECUTE | \
+                                   FILE_READ_ATTRIBUTES | SYNCHRONIZE)
+
+
+/* File attribute flags
+ */
+#define FILE_SHARE_READ			0x00000001L
+#define FILE_SHARE_WRITE		0x00000002L
+#define FILE_SHARE_DELETE		0x00000004L
+#define FILE_ATTRIBUTE_READONLY         0x00000001L
+#define FILE_ATTRIBUTE_HIDDEN           0x00000002L
+#define FILE_ATTRIBUTE_SYSTEM           0x00000004L
+#define FILE_ATTRIBUTE_LABEL            0x00000008L  /* Not in Windows API */
+#define FILE_ATTRIBUTE_DIRECTORY        0x00000010L
+#define FILE_ATTRIBUTE_ARCHIVE          0x00000020L
+#define FILE_ATTRIBUTE_NORMAL           0x00000080L
+#define FILE_ATTRIBUTE_TEMPORARY        0x00000100L
+#define FILE_ATTRIBUTE_ATOMIC_WRITE     0x00000200L
+#define FILE_ATTRIBUTE_XACTION_WRITE    0x00000400L
+#define FILE_ATTRIBUTE_COMPRESSED       0x00000800L
+#define FILE_ATTRIBUTE_OFFLINE		0x00001000L
+
+/* File alignments (NT) */
+#define	FILE_BYTE_ALIGNMENT		0x00000000
+#define	FILE_WORD_ALIGNMENT		0x00000001
+#define	FILE_LONG_ALIGNMENT		0x00000003
+#define	FILE_QUAD_ALIGNMENT		0x00000007
+#define	FILE_OCTA_ALIGNMENT		0x0000000f
+#define	FILE_32_BYTE_ALIGNMENT		0x0000001f
+#define	FILE_64_BYTE_ALIGNMENT		0x0000003f
+#define	FILE_128_BYTE_ALIGNMENT		0x0000007f
+#define	FILE_256_BYTE_ALIGNMENT		0x000000ff
+#define	FILE_512_BYTE_ALIGNMENT		0x000001ff
+
+#define REG_NONE		0	/* no type */
+#define REG_SZ			1	/* string type (ASCII) */
+#define REG_EXPAND_SZ		2	/* string, includes %ENVVAR% (expanded by caller) (ASCII) */
+#define REG_BINARY		3	/* binary format, callerspecific */
+/* YES, REG_DWORD == REG_DWORD_LITTLE_ENDIAN */
+#define REG_DWORD		4	/* DWORD in little endian format */
+#define REG_DWORD_LITTLE_ENDIAN	4	/* DWORD in little endian format */
+#define REG_DWORD_BIG_ENDIAN	5	/* DWORD in big endian format  */
+#define REG_LINK		6	/* symbolic link (UNICODE) */
+#define REG_MULTI_SZ		7	/* multiple strings, delimited by \0, terminated by \0\0 (ASCII) */
+#define REG_RESOURCE_LIST	8	/* resource list? huh? */
+#define REG_FULL_RESOURCE_DESCRIPTOR	9	/* full resource descriptor? huh? */
+#define REG_RESOURCE_REQUIREMENTS_LIST	10
+
+/* ----------------------------- begin registry ----------------------------- */
+
+/* Registry security values */
+#define OWNER_SECURITY_INFORMATION	0x00000001
+#define GROUP_SECURITY_INFORMATION	0x00000002
+#define DACL_SECURITY_INFORMATION	0x00000004
+#define SACL_SECURITY_INFORMATION	0x00000008
+
+#define REG_OPTION_RESERVED		0x00000000
+#define REG_OPTION_NON_VOLATILE		0x00000000
+#define REG_OPTION_VOLATILE		0x00000001
+#define REG_OPTION_CREATE_LINK		0x00000002
+#define REG_OPTION_BACKUP_RESTORE	0x00000004 /* FIXME */
+#define REG_OPTION_OPEN_LINK		0x00000008
+#define REG_LEGAL_OPTION	       (REG_OPTION_RESERVED|  \
+					REG_OPTION_NON_VOLATILE|  \
+					REG_OPTION_VOLATILE|  \
+					REG_OPTION_CREATE_LINK|  \
+					REG_OPTION_BACKUP_RESTORE|  \
+					REG_OPTION_OPEN_LINK)
+
+
+#define REG_CREATED_NEW_KEY	0x00000001
+#define REG_OPENED_EXISTING_KEY	0x00000002
+
+/* For RegNotifyChangeKeyValue */
+#define REG_NOTIFY_CHANGE_NAME	0x1
+
+#define KEY_QUERY_VALUE		0x00000001
+#define KEY_SET_VALUE		0x00000002
+#define KEY_CREATE_SUB_KEY	0x00000004
+#define KEY_ENUMERATE_SUB_KEYS	0x00000008
+#define KEY_NOTIFY		0x00000010
+#define KEY_CREATE_LINK		0x00000020
+
+#define KEY_READ	      ((STANDARD_RIGHTS_READ|  \
+				KEY_QUERY_VALUE|  \
+				KEY_ENUMERATE_SUB_KEYS|  \
+				KEY_NOTIFY)  \
+				& (~SYNCHRONIZE)  \
+			      )
+#define KEY_WRITE	      ((STANDARD_RIGHTS_WRITE|  \
+				KEY_SET_VALUE|  \
+				KEY_CREATE_SUB_KEY)  \
+				& (~SYNCHRONIZE)  \
+			      )
+#define KEY_EXECUTE	      ((KEY_READ)  \
+				& (~SYNCHRONIZE))  \
+			      )
+#define KEY_ALL_ACCESS        ((STANDARD_RIGHTS_ALL|  \
+				KEY_QUERY_VALUE|  \
+				KEY_SET_VALUE|  \
+				KEY_CREATE_SUB_KEY|  \
+				KEY_ENUMERATE_SUB_KEYS|  \
+				KEY_NOTIFY|  \
+				KEY_CREATE_LINK)  \
+				& (~SYNCHRONIZE)  \
+			      )
+/* ------------------------------ end registry ------------------------------ */
+
+
+#define RtlEqualMemory(Destination, Source, Length) (!memcmp((Destination),(Source),(Length)))
+#define RtlMoveMemory(Destination, Source, Length) memmove((Destination),(Source),(Length))
+#define RtlCopyMemory(Destination, Source, Length) memcpy((Destination),(Source),(Length))
+#define RtlFillMemory(Destination, Length, Fill) memset((Destination),(Fill),(Length))
+#define RtlZeroMemory(Destination, Length) memset((Destination),0,(Length))
+
+#include "poppack.h"
+
+#endif  /* __WINE_WINNT_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/winreg.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,57 @@
+/*
+ * 		Win32 registry defines (see also winnt.h)
+ */
+#ifndef __WINE_WINREG_H
+#define __WINE_WINREG_H
+
+#include "winbase.h"
+#include "winnt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* defined(__cplusplus) */
+
+/*
+#define SHELL_ERROR_SUCCESS           0L
+#define SHELL_ERROR_BADDB             1L
+#define SHELL_ERROR_BADKEY            2L
+#define SHELL_ERROR_CANTOPEN          3L
+#define SHELL_ERROR_CANTREAD          4L
+#define SHELL_ERROR_CANTWRITE         5L
+#define SHELL_ERROR_OUTOFMEMORY       6L
+#define SHELL_ERROR_INVALID_PARAMETER 7L
+#define SHELL_ERROR_ACCESS_DENIED     8L
+*/
+
+#define HKEY_CLASSES_ROOT       ((HKEY) 0x80000000)
+#define HKEY_CURRENT_USER       ((HKEY) 0x80000001)
+#define HKEY_LOCAL_MACHINE      ((HKEY) 0x80000002)
+#define HKEY_USERS              ((HKEY) 0x80000003)
+#define HKEY_PERFORMANCE_DATA   ((HKEY) 0x80000004)
+#define HKEY_CURRENT_CONFIG     ((HKEY) 0x80000005)
+#define HKEY_DYN_DATA           ((HKEY) 0x80000006)
+
+/*
+ *	registry provider structs
+ */
+typedef struct value_entA 
+{   LPSTR	ve_valuename;
+    DWORD	ve_valuelen;
+    DWORD_PTR	ve_valueptr;
+    DWORD	ve_type;
+} VALENTA, *PVALENTA;
+
+typedef struct value_entW {
+    LPWSTR	ve_valuename;
+    DWORD	ve_valuelen;
+    DWORD_PTR	ve_valueptr;
+    DWORD	ve_type;
+} VALENTW, *PVALENTW;
+
+typedef ACCESS_MASK REGSAM;
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif /* defined(__cplusplus) */
+
+#endif  /* __WINE_WINREG_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wine/winuser.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,2929 @@
+#ifndef _WINUSER_
+#define _WINUSER_
+
+#ifndef RC_INVOKED
+#include <stdarg.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "pshpack1.h"
+
+/* flags for HIGHCONTRAST dwFlags field */
+#define HCF_HIGHCONTRASTON  0x00000001
+#define HCF_AVAILABLE       0x00000002
+#define HCF_HOTKEYACTIVE    0x00000004
+#define HCF_CONFIRMHOTKEY   0x00000008
+#define HCF_HOTKEYSOUND     0x00000010
+#define HCF_INDICATOR       0x00000020
+#define HCF_HOTKEYAVAILABLE 0x00000040
+
+typedef struct tagHIGHCONTRASTA
+{
+    UINT  cbSize;
+    DWORD   dwFlags;
+    LPSTR   lpszDefaultScheme;
+} HIGHCONTRASTA, *LPHIGHCONTRASTA;
+
+typedef struct tagHIGHCONTRASTW
+{
+    UINT  cbSize;
+    DWORD   dwFlags;
+    LPWSTR  lpszDefaultScheme;
+} HIGHCONTRASTW, *LPHIGHCONTRASTW;
+
+DECL_WINELIB_TYPE_AW(HIGHCONTRAST)
+DECL_WINELIB_TYPE_AW(LPHIGHCONTRAST)
+
+typedef struct
+{
+    UINT  message;
+    UINT  paramL;
+    UINT  paramH;
+    DWORD   time;
+    HWND  hwnd;
+} EVENTMSG, *LPEVENTMSG;
+
+
+    /* Mouse hook structure */
+
+typedef struct
+{
+    POINT pt;
+    HWND  hwnd;
+    UINT  wHitTestCode;
+    DWORD   dwExtraInfo;
+} MOUSEHOOKSTRUCT, *PMOUSEHOOKSTRUCT, *LPMOUSEHOOKSTRUCT;
+
+
+    /* Hardware hook structure */
+
+typedef struct
+{
+    HWND    hWnd;
+    UINT    wMessage;
+    WPARAM  wParam;
+    LPARAM    lParam;
+} HARDWAREHOOKSTRUCT, *LPHARDWAREHOOKSTRUCT;
+
+
+  /* Debug hook structure */
+
+typedef struct
+{
+    DWORD       idThread;
+    DWORD       idThreadInstaller;
+    LPARAM      lParam;
+    WPARAM    wParam;
+    INT       code;
+} DEBUGHOOKINFO, *LPDEBUGHOOKINFO;
+
+#define HKL_PREV   0
+#define HKL_NEXT   1
+
+#define KLF_ACTIVATE       0x00000001
+#define KLF_SUBSTITUTE_OK  0x00000002
+#define KLF_UNLOADPREVIOUS 0x00000004
+#define KLF_REORDER        0x00000008
+#define KLF_REPLACELANG    0x00000010
+#define KLF_NOTELLSHELL    0x00000080
+
+#define KL_NAMELENGTH      9
+
+  /***** Dialogs *****/
+#ifdef FSHIFT
+/* Gcc on Solaris has a version of this that we don't care about.  */
+#undef FSHIFT
+#endif
+
+#define	FVIRTKEY	TRUE          /* Assumed to be == TRUE */
+#define	FNOINVERT	0x02
+#define	FSHIFT		0x04
+#define	FCONTROL	0x08
+#define	FALT		0x10
+
+
+typedef struct tagANIMATIONINFO
+{
+       UINT          cbSize;
+       INT           iMinAnimate;
+} ANIMATIONINFO, *LPANIMATIONINFO;
+
+typedef struct tagNMHDR
+{
+    HWND  hwndFrom;
+    UINT  idFrom;
+    UINT  code;
+} NMHDR, *LPNMHDR;
+
+typedef struct
+{
+	UINT	cbSize;
+	INT	iTabLength;
+	INT	iLeftMargin;
+	INT	iRightMargin;
+	UINT	uiLengthDrawn;
+} DRAWTEXTPARAMS,*LPDRAWTEXTPARAMS;
+
+#define WM_USER             0x0400
+
+#define DT_EDITCONTROL      0x00002000
+#define DT_PATH_ELLIPSIS    0x00004000
+#define DT_END_ELLIPSIS     0x00008000
+#define DT_MODIFYSTRING     0x00010000
+#define DT_RTLREADING       0x00020000
+#define DT_WORD_ELLIPSIS    0x00040000
+
+typedef struct
+{
+   LPARAM   lParam;
+   WPARAM16 wParam;
+   UINT16   message;
+   HWND16   hwnd;
+} CWPSTRUCT16, *LPCWPSTRUCT16;
+
+typedef struct
+{
+  LPARAM        lParam;
+  WPARAM      wParam;
+  UINT        message;
+  HWND        hwnd;
+} CWPSTRUCT, *LPCWPSTRUCT;
+
+
+
+typedef struct
+{
+  LRESULT       lResult;
+  LPARAM        lParam;
+  WPARAM16      wParam;
+  DWORD         message;
+  HWND16        hwnd;
+} CWPRETSTRUCT16, *LPCWPRETSTRUCT16;
+
+typedef struct
+{
+  LRESULT       lResult;
+  LPARAM        lParam;
+  WPARAM      wParam;
+  DWORD         message;
+  HWND        hwnd;
+} CWPRETSTRUCT, *LPCWPRETSTRUCT;
+
+typedef struct
+{
+    UINT   length;
+    UINT   flags;
+    UINT   showCmd;
+    POINT  ptMinPosition WINE_PACKED;
+    POINT  ptMaxPosition WINE_PACKED;
+    RECT   rcNormalPosition WINE_PACKED;
+} WINDOWPLACEMENT, *LPWINDOWPLACEMENT;
+
+
+  /* WINDOWPLACEMENT flags */
+#define WPF_SETMINPOSITION      0x0001
+#define WPF_RESTORETOMAXIMIZED  0x0002
+
+/***** Dialogs *****/
+
+  /* cbWndExtra bytes for dialog class */
+#define DLGWINDOWEXTRA      30
+
+/* Button control styles */
+#define BS_PUSHBUTTON          0x00000000L
+#define BS_DEFPUSHBUTTON       0x00000001L
+#define BS_CHECKBOX            0x00000002L
+#define BS_AUTOCHECKBOX        0x00000003L
+#define BS_RADIOBUTTON         0x00000004L
+#define BS_3STATE              0x00000005L
+#define BS_AUTO3STATE          0x00000006L
+#define BS_GROUPBOX            0x00000007L
+#define BS_USERBUTTON          0x00000008L
+#define BS_AUTORADIOBUTTON     0x00000009L
+#define BS_OWNERDRAW           0x0000000BL
+#define BS_LEFTTEXT            0x00000020L
+
+#define BS_TEXT                0x00000000L
+#define BS_ICON                0x00000040L
+#define BS_BITMAP              0x00000080L
+#define BS_LEFT                0x00000100L
+#define BS_RIGHT               0x00000200L
+#define BS_CENTER              0x00000300L
+#define BS_TOP                 0x00000400L
+#define BS_BOTTOM              0x00000800L
+#define BS_VCENTER             0x00000C00L
+#define BS_PUSHLIKE            0x00001000L
+#define BS_MULTILINE           0x00002000L
+#define BS_NOTIFY              0x00004000L
+#define BS_FLAT                0x00008000L
+
+  /* Dialog styles */
+#define DS_ABSALIGN		0x0001
+#define DS_SYSMODAL		0x0002
+#define DS_3DLOOK		0x0004	/* win95 */
+#define DS_FIXEDSYS		0x0008	/* win95 */
+#define DS_NOFAILCREATE		0x0010	/* win95 */
+#define DS_LOCALEDIT		0x0020
+#define DS_SETFONT		0x0040
+#define DS_MODALFRAME		0x0080
+#define DS_NOIDLEMSG		0x0100
+#define DS_SETFOREGROUND	0x0200	/* win95 */
+#define DS_CONTROL		0x0400	/* win95 */
+#define DS_CENTER		0x0800	/* win95 */
+#define DS_CENTERMOUSE		0x1000	/* win95 */
+#define DS_CONTEXTHELP		0x2000	/* win95 */
+
+
+  /* Dialog messages */
+#define DM_GETDEFID         (WM_USER+0)
+#define DM_SETDEFID         (WM_USER+1)
+
+#define DC_HASDEFID         0x534b
+
+/* Owner draw control types */
+#define ODT_MENU        1
+#define ODT_LISTBOX     2
+#define ODT_COMBOBOX    3
+#define ODT_BUTTON      4
+#define ODT_STATIC      5
+
+/* Owner draw actions */
+#define ODA_DRAWENTIRE  0x0001
+#define ODA_SELECT      0x0002
+#define ODA_FOCUS       0x0004
+
+/* Owner draw state */
+#define ODS_SELECTED    0x0001
+#define ODS_GRAYED      0x0002
+#define ODS_DISABLED    0x0004
+#define ODS_CHECKED     0x0008
+#define ODS_FOCUS       0x0010
+#define ODS_COMBOBOXEDIT 0x1000
+#define ODS_HOTLIGHT    0x0040
+#define ODS_INACTIVE    0x0080
+
+/* Edit control styles */
+#define ES_LEFT         0x00000000
+#define ES_CENTER       0x00000001
+#define ES_RIGHT        0x00000002
+#define ES_MULTILINE    0x00000004
+#define ES_UPPERCASE    0x00000008
+#define ES_LOWERCASE    0x00000010
+#define ES_PASSWORD     0x00000020
+#define ES_AUTOVSCROLL  0x00000040
+#define ES_AUTOHSCROLL  0x00000080
+#define ES_NOHIDESEL    0x00000100
+#define ES_OEMCONVERT   0x00000400
+#define ES_READONLY     0x00000800
+#define ES_WANTRETURN   0x00001000
+#define ES_NUMBER       0x00002000
+
+/* OEM Resource Ordinal Numbers */
+#define OBM_CLOSED          32731
+#define OBM_RADIOCHECK      32732
+#define OBM_TRTYPE          32733
+#define OBM_LFARROWI        32734
+#define OBM_RGARROWI        32735
+#define OBM_DNARROWI        32736
+#define OBM_UPARROWI        32737
+#define OBM_COMBO           32738
+#define OBM_MNARROW         32739
+#define OBM_LFARROWD        32740
+#define OBM_RGARROWD        32741
+#define OBM_DNARROWD        32742
+#define OBM_UPARROWD        32743
+#define OBM_RESTORED        32744
+#define OBM_ZOOMD           32745
+#define OBM_REDUCED         32746
+#define OBM_RESTORE         32747
+#define OBM_ZOOM            32748
+#define OBM_REDUCE          32749
+#define OBM_LFARROW         32750
+#define OBM_RGARROW         32751
+#define OBM_DNARROW         32752
+#define OBM_UPARROW         32753
+#define OBM_CLOSE           32754
+#define OBM_OLD_RESTORE     32755
+#define OBM_OLD_ZOOM        32756
+#define OBM_OLD_REDUCE      32757
+#define OBM_BTNCORNERS      32758
+#define OBM_CHECKBOXES      32759
+#define OBM_CHECK           32760
+#define OBM_BTSIZE          32761
+#define OBM_OLD_LFARROW     32762
+#define OBM_OLD_RGARROW     32763
+#define OBM_OLD_DNARROW     32764
+#define OBM_OLD_UPARROW     32765
+#define OBM_SIZE            32766
+#define OBM_OLD_CLOSE       32767
+
+#define OCR_BUMMER	    100
+#define OCR_DRAGOBJECT	    101
+
+#define OCR_NORMAL          32512
+#define OCR_IBEAM           32513
+#define OCR_WAIT            32514
+#define OCR_CROSS           32515
+#define OCR_UP              32516
+#define OCR_SIZE            32640
+#define OCR_ICON            32641
+#define OCR_SIZENWSE        32642
+#define OCR_SIZENESW        32643
+#define OCR_SIZEWE          32644
+#define OCR_SIZENS          32645
+#define OCR_SIZEALL         32646
+#define OCR_ICOCUR          32647
+#define OCR_NO              32648
+#define OCR_APPSTARTING     32650
+#define OCR_HELP            32651  /* only defined in wine */
+
+#define OIC_SAMPLE          32512
+#define OIC_HAND            32513
+#define OIC_QUES            32514
+#define OIC_BANG            32515
+#define OIC_NOTE            32516
+#define OIC_PORTRAIT        32517
+#define OIC_LANDSCAPE       32518
+#define OIC_WINEICON        32519
+#define OIC_FOLDER          32520
+#define OIC_FOLDER2         32521
+#define OIC_FLOPPY          32522
+#define OIC_CDROM           32523
+#define OIC_HDISK           32524
+#define OIC_NETWORK         32525
+
+#define COLOR_SCROLLBAR		    0
+#define COLOR_BACKGROUND	    1
+#define COLOR_ACTIVECAPTION	    2
+#define COLOR_INACTIVECAPTION	    3
+#define COLOR_MENU		    4
+#define COLOR_WINDOW		    5
+#define COLOR_WINDOWFRAME	    6
+#define COLOR_MENUTEXT		    7
+#define COLOR_WINDOWTEXT	    8
+#define COLOR_CAPTIONTEXT  	    9
+#define COLOR_ACTIVEBORDER	   10
+#define COLOR_INACTIVEBORDER	   11
+#define COLOR_APPWORKSPACE	   12
+#define COLOR_HIGHLIGHT		   13
+#define COLOR_HIGHLIGHTTEXT	   14
+#define COLOR_BTNFACE              15
+#define COLOR_BTNSHADOW            16
+#define COLOR_GRAYTEXT             17
+#define COLOR_BTNTEXT		   18
+#define COLOR_INACTIVECAPTIONTEXT  19
+#define COLOR_BTNHIGHLIGHT         20
+/* win95 colors */
+#define COLOR_3DDKSHADOW           21
+#define COLOR_3DLIGHT              22
+#define COLOR_INFOTEXT             23
+#define COLOR_INFOBK               24
+#define COLOR_DESKTOP              COLOR_BACKGROUND
+#define COLOR_3DFACE               COLOR_BTNFACE
+#define COLOR_3DSHADOW             COLOR_BTNSHADOW
+#define COLOR_3DHIGHLIGHT          COLOR_BTNHIGHLIGHT
+#define COLOR_3DHILIGHT            COLOR_BTNHIGHLIGHT
+#define COLOR_BTNHILIGHT           COLOR_BTNHIGHLIGHT
+/* win98 colors */
+#define COLOR_ALTERNATEBTNFACE         25  /* undocumented, constant's name unknown */
+#define COLOR_HOTLIGHT                 26
+#define COLOR_GRADIENTACTIVECAPTION    27
+#define COLOR_GRADIENTINACTIVECAPTION  28
+
+  /* WM_CTLCOLOR values */
+#define CTLCOLOR_MSGBOX             0
+#define CTLCOLOR_EDIT               1
+#define CTLCOLOR_LISTBOX            2
+#define CTLCOLOR_BTN                3
+#define CTLCOLOR_DLG                4
+#define CTLCOLOR_SCROLLBAR          5
+#define CTLCOLOR_STATIC             6
+
+/* Edit control messages */
+#define EM_GETSEL                0x00b0
+#define EM_SETSEL                0x00b1
+#define EM_GETRECT               0x00b2
+#define EM_SETRECT               0x00b3
+#define EM_SETRECTNP             0x00b4
+#define EM_SCROLL                0x00b5
+#define EM_LINESCROLL            0x00b6
+#define EM_SCROLLCARET           0x00b7
+#define EM_GETMODIFY             0x00b8
+#define EM_SETMODIFY             0x00b9
+#define EM_GETLINECOUNT          0x00ba
+#define EM_LINEINDEX             0x00bb
+#define EM_SETHANDLE             0x00bc
+#define EM_GETHANDLE             0x00bd
+#define EM_GETTHUMB              0x00be
+/* FIXME : missing from specs 0x00bf and 0x00c0 */
+#define EM_LINELENGTH            0x00c1
+#define EM_REPLACESEL            0x00c2
+/* FIXME : missing from specs 0x00c3 */
+#define EM_GETLINE               0x00c4
+#define EM_LIMITTEXT             0x00c5
+#define EM_CANUNDO               0x00c6
+#define EM_UNDO                  0x00c7
+#define EM_FMTLINES              0x00c8
+#define EM_LINEFROMCHAR          0x00c9
+/* FIXME : missing from specs 0x00ca */
+#define EM_SETTABSTOPS           0x00cb
+#define EM_SETPASSWORDCHAR       0x00cc
+#define EM_EMPTYUNDOBUFFER       0x00cd
+#define EM_GETFIRSTVISIBLELINE   0x00ce
+#define EM_SETREADONLY           0x00cf
+#define EM_SETWORDBREAKPROC      0x00d0
+#define EM_GETWORDBREAKPROC      0x00d1
+#define EM_GETPASSWORDCHAR       0x00d2
+#define EM_SETMARGINS            0x00d3
+#define EM_GETMARGINS            0x00d4
+#define EM_GETLIMITTEXT          0x00d5
+#define EM_POSFROMCHAR           0x00d6
+#define EM_CHARFROMPOS           0x00d7
+/* a name change since win95 */
+#define EM_SETLIMITTEXT          EM_LIMITTEXT
+
+/* EDITWORDBREAKPROC code values */
+#define WB_LEFT         0
+#define WB_RIGHT        1
+#define WB_ISDELIMITER  2
+
+/* Edit control notification codes */
+#define EN_SETFOCUS     0x0100
+#define EN_KILLFOCUS    0x0200
+#define EN_CHANGE       0x0300
+#define EN_UPDATE       0x0400
+#define EN_ERRSPACE     0x0500
+#define EN_MAXTEXT      0x0501
+#define EN_HSCROLL      0x0601
+#define EN_VSCROLL      0x0602
+
+/* New since win95 : EM_SETMARGIN parameters */
+#define EC_LEFTMARGIN	0x0001
+#define EC_RIGHTMARGIN	0x0002
+#define EC_USEFONTINFO	0xffff
+
+
+/* Messages */
+
+  /* WM_GETDLGCODE values */
+
+
+#define WM_NULL                 0x0000
+#define WM_CREATE               0x0001
+#define WM_DESTROY              0x0002
+#define WM_MOVE                 0x0003
+#define WM_SIZEWAIT             0x0004
+#define WM_SIZE                 0x0005
+#define WM_ACTIVATE             0x0006
+#define WM_SETFOCUS             0x0007
+#define WM_KILLFOCUS            0x0008
+#define WM_SETVISIBLE           0x0009
+#define WM_ENABLE               0x000a
+#define WM_SETREDRAW            0x000b
+#define WM_SETTEXT              0x000c
+#define WM_GETTEXT              0x000d
+#define WM_GETTEXTLENGTH        0x000e
+#define WM_PAINT                0x000f
+#define WM_CLOSE                0x0010
+#define WM_QUERYENDSESSION      0x0011
+#define WM_QUIT                 0x0012
+#define WM_QUERYOPEN            0x0013
+#define WM_ERASEBKGND           0x0014
+#define WM_SYSCOLORCHANGE       0x0015
+#define WM_ENDSESSION           0x0016
+#define WM_SYSTEMERROR          0x0017
+#define WM_SHOWWINDOW           0x0018
+#define WM_CTLCOLOR             0x0019
+#define WM_WININICHANGE         0x001a
+#define WM_SETTINGCHANGE        WM_WININICHANGE
+#define WM_DEVMODECHANGE        0x001b
+#define WM_ACTIVATEAPP          0x001c
+#define WM_FONTCHANGE           0x001d
+#define WM_TIMECHANGE           0x001e
+#define WM_CANCELMODE           0x001f
+#define WM_SETCURSOR            0x0020
+#define WM_MOUSEACTIVATE        0x0021
+#define WM_CHILDACTIVATE        0x0022
+#define WM_QUEUESYNC            0x0023
+#define WM_GETMINMAXINFO        0x0024
+
+#define WM_PAINTICON            0x0026
+#define WM_ICONERASEBKGND       0x0027
+#define WM_NEXTDLGCTL           0x0028
+#define WM_ALTTABACTIVE         0x0029
+#define WM_SPOOLERSTATUS        0x002a
+#define WM_DRAWITEM             0x002b
+#define WM_MEASUREITEM          0x002c
+#define WM_DELETEITEM           0x002d
+#define WM_VKEYTOITEM           0x002e
+#define WM_CHARTOITEM           0x002f
+#define WM_SETFONT              0x0030
+#define WM_GETFONT              0x0031
+#define WM_SETHOTKEY            0x0032
+#define WM_GETHOTKEY            0x0033
+#define WM_FILESYSCHANGE        0x0034
+#define WM_ISACTIVEICON         0x0035
+#define WM_QUERYPARKICON        0x0036
+#define WM_QUERYDRAGICON        0x0037
+#define WM_QUERYSAVESTATE       0x0038
+#define WM_COMPAREITEM          0x0039
+#define WM_TESTING              0x003a
+
+#define WM_OTHERWINDOWCREATED	0x003c
+#define WM_OTHERWINDOWDESTROYED	0x003d
+#define WM_ACTIVATESHELLWINDOW	0x003e
+
+#define WM_COMPACTING		0x0041
+
+#define WM_COMMNOTIFY		0x0044
+#define WM_WINDOWPOSCHANGING 	0x0046
+#define WM_WINDOWPOSCHANGED 	0x0047
+#define WM_POWER		0x0048
+
+  /* Win32 4.0 messages */
+#define WM_COPYDATA		0x004a
+#define WM_CANCELJOURNAL	0x004b
+#define WM_NOTIFY		0x004e
+#define WM_HELP			0x0053
+#define WM_NOTIFYFORMAT		0x0055
+
+#define WM_CONTEXTMENU		0x007b
+#define WM_STYLECHANGING 	0x007c
+#define WM_STYLECHANGED		0x007d
+#define WM_DISPLAYCHANGE        0x007e
+#define WM_GETICON		0x007f
+#define WM_SETICON		0x0080
+
+  /* Non-client system messages */
+#define WM_NCCREATE         0x0081
+#define WM_NCDESTROY        0x0082
+#define WM_NCCALCSIZE       0x0083
+#define WM_NCHITTEST        0x0084
+#define WM_NCPAINT          0x0085
+#define WM_NCACTIVATE       0x0086
+
+#define WM_GETDLGCODE	    0x0087
+#define WM_SYNCPAINT	    0x0088
+#define WM_SYNCTASK	    0x0089
+
+  /* Non-client mouse messages */
+#define WM_NCMOUSEMOVE      0x00a0
+#define WM_NCLBUTTONDOWN    0x00a1
+#define WM_NCLBUTTONUP      0x00a2
+#define WM_NCLBUTTONDBLCLK  0x00a3
+#define WM_NCRBUTTONDOWN    0x00a4
+#define WM_NCRBUTTONUP      0x00a5
+#define WM_NCRBUTTONDBLCLK  0x00a6
+#define WM_NCMBUTTONDOWN    0x00a7
+#define WM_NCMBUTTONUP      0x00a8
+#define WM_NCMBUTTONDBLCLK  0x00a9
+
+  /* Keyboard messages */
+#define WM_KEYDOWN          0x0100
+#define WM_KEYUP            0x0101
+#define WM_CHAR             0x0102
+#define WM_DEADCHAR         0x0103
+#define WM_SYSKEYDOWN       0x0104
+#define WM_SYSKEYUP         0x0105
+#define WM_SYSCHAR          0x0106
+#define WM_SYSDEADCHAR      0x0107
+#define WM_KEYFIRST         WM_KEYDOWN
+#define WM_KEYLAST          0x0108
+
+/* Win32 4.0 messages for IME */
+#define WM_IME_STARTCOMPOSITION     0x010d
+#define WM_IME_ENDCOMPOSITION       0x010e
+#define WM_IME_COMPOSITION          0x010f
+#define WM_IME_KEYLAST              0x010f
+
+#define WM_INITDIALOG       0x0110 
+#define WM_COMMAND          0x0111
+#define WM_SYSCOMMAND       0x0112
+#define WM_TIMER	    0x0113
+#define WM_SYSTIMER	    0x0118
+
+  /* scroll messages */
+#define WM_HSCROLL          0x0114
+#define WM_VSCROLL          0x0115
+
+/* Menu messages */
+#define WM_INITMENU         0x0116
+#define WM_INITMENUPOPUP    0x0117
+
+#define WM_MENUSELECT       0x011F
+#define WM_MENUCHAR         0x0120
+#define WM_ENTERIDLE        0x0121
+
+#define WM_LBTRACKPOINT     0x0131
+
+  /* Win32 CTLCOLOR messages */
+#define WM_CTLCOLORMSGBOX    0x0132
+#define WM_CTLCOLOREDIT      0x0133
+#define WM_CTLCOLORLISTBOX   0x0134
+#define WM_CTLCOLORBTN       0x0135
+#define WM_CTLCOLORDLG       0x0136
+#define WM_CTLCOLORSCROLLBAR 0x0137
+#define WM_CTLCOLORSTATIC    0x0138
+
+  /* Mouse messages */
+#define WM_MOUSEMOVE	    0x0200
+#define WM_LBUTTONDOWN	    0x0201
+#define WM_LBUTTONUP	    0x0202
+#define WM_LBUTTONDBLCLK    0x0203
+#define WM_RBUTTONDOWN	    0x0204
+#define WM_RBUTTONUP	    0x0205
+#define WM_RBUTTONDBLCLK    0x0206
+#define WM_MBUTTONDOWN	    0x0207
+#define WM_MBUTTONUP	    0x0208
+#define WM_MBUTTONDBLCLK    0x0209
+#define WM_MOUSEWHEEL       0x020A
+#define WM_MOUSEFIRST	    WM_MOUSEMOVE
+
+
+#define WM_MOUSELAST	    WM_MOUSEWHEEL
+ 
+#define WHEEL_DELTA      120
+#define WHEEL_PAGESCROLL  (UINT_MAX)
+#define WM_PARENTNOTIFY     0x0210
+#define WM_ENTERMENULOOP    0x0211
+#define WM_EXITMENULOOP     0x0212
+#define WM_NEXTMENU	    0x0213
+
+  /* Win32 4.0 messages */
+#define WM_SIZING	    0x0214
+#define WM_CAPTURECHANGED   0x0215
+#define WM_MOVING	    0x0216
+
+  /* MDI messages */
+#define WM_MDICREATE	    0x0220
+#define WM_MDIDESTROY	    0x0221
+#define WM_MDIACTIVATE	    0x0222
+#define WM_MDIRESTORE	    0x0223
+#define WM_MDINEXT	    0x0224
+#define WM_MDIMAXIMIZE	    0x0225
+#define WM_MDITILE	    0x0226
+#define WM_MDICASCADE	    0x0227
+#define WM_MDIICONARRANGE   0x0228
+#define WM_MDIGETACTIVE     0x0229
+#define WM_MDIREFRESHMENU   0x0234
+
+  /* D&D messages */
+#define WM_DROPOBJECT	    0x022A
+#define WM_QUERYDROPOBJECT  0x022B
+#define WM_BEGINDRAG	    0x022C
+#define WM_DRAGLOOP	    0x022D
+#define WM_DRAGSELECT	    0x022E
+#define WM_DRAGMOVE	    0x022F
+#define WM_MDISETMENU	    0x0230
+
+#define WM_ENTERSIZEMOVE    0x0231
+#define WM_EXITSIZEMOVE     0x0232
+#define WM_DROPFILES	    0x0233
+
+
+/* Win32 4.0 messages for IME */
+#define WM_IME_SETCONTEXT           0x0281
+#define WM_IME_NOTIFY               0x0282
+#define WM_IME_CONTROL              0x0283
+#define WM_IME_COMPOSITIONFULL      0x0284
+#define WM_IME_SELECT               0x0285
+#define WM_IME_CHAR                 0x0286
+/* Win32 5.0 messages for IME */
+#define WM_IME_REQUEST              0x0288
+
+/* Win32 4.0 messages for IME */
+#define WM_IME_KEYDOWN              0x0290
+#define WM_IME_KEYUP                0x0291
+
+/* Clipboard command messages */
+#define WM_CUT               0x0300
+#define WM_COPY              0x0301
+#define WM_PASTE             0x0302
+#define WM_CLEAR             0x0303
+#define WM_UNDO              0x0304
+
+/* Clipboard owner messages */
+#define WM_RENDERFORMAT      0x0305
+#define WM_RENDERALLFORMATS  0x0306
+#define WM_DESTROYCLIPBOARD  0x0307
+
+/* Clipboard viewer messages */
+#define WM_DRAWCLIPBOARD     0x0308
+#define WM_PAINTCLIPBOARD    0x0309
+#define WM_VSCROLLCLIPBOARD  0x030A
+#define WM_SIZECLIPBOARD     0x030B
+#define WM_ASKCBFORMATNAME   0x030C
+#define WM_CHANGECBCHAIN     0x030D
+#define WM_HSCROLLCLIPBOARD  0x030E
+
+#define WM_QUERYNEWPALETTE   0x030F
+#define WM_PALETTEISCHANGING 0x0310
+#define WM_PALETTECHANGED    0x0311
+#define WM_HOTKEY	     0x0312
+
+#define WM_PRINT             0x0317
+#define WM_PRINTCLIENT       0x0318
+
+  /* FIXME: This does not belong to any libwine interface header */
+  /* MFC messages [360-38f] */
+
+#define WM_QUERYAFXWNDPROC  0x0360
+#define WM_SIZEPARENT       0x0361
+#define WM_SETMESSAGESTRING 0x0362
+#define WM_IDLEUPDATECMDUI  0x0363 
+#define WM_INITIALUPDATE    0x0364
+#define WM_COMMANDHELP      0x0365
+#define WM_HELPHITTEST      0x0366
+#define WM_EXITHELPMODE     0x0367
+#define WM_RECALCPARENT     0x0368
+#define WM_SIZECHILD        0x0369
+#define WM_KICKIDLE         0x036A 
+#define WM_QUERYCENTERWND   0x036B
+#define WM_DISABLEMODAL     0x036C
+#define WM_FLOATSTATUS      0x036D 
+#define WM_ACTIVATETOPLEVEL 0x036E 
+#define WM_QUERY3DCONTROLS  0x036F 
+#define WM_SOCKET_NOTIFY    0x0373
+#define WM_SOCKET_DEAD      0x0374
+#define WM_POPMESSAGESTRING 0x0375
+#define WM_OCC_LOADFROMSTREAM           0x0376
+#define WM_OCC_LOADFROMSTORAGE          0x0377
+#define WM_OCC_INITNEW                  0x0378
+#define WM_OCC_LOADFROMSTREAM_EX        0x037A
+#define WM_OCC_LOADFROMSTORAGE_EX       0x037B
+#define WM_QUEUE_SENTINEL   0x0379
+
+#define WM_PENWINFIRST      0x0380
+#define WM_PENWINLAST       0x038F
+
+/* end of MFC messages */
+
+/* FIXME: The following two lines do not belong to any libwine interface header */
+#define WM_COALESCE_FIRST    0x0390
+#define WM_COALESCE_LAST     0x039F
+
+#define WM_APP               0x8000
+
+
+#define DLGC_WANTARROWS      0x0001
+#define DLGC_WANTTAB         0x0002
+#define DLGC_WANTALLKEYS     0x0004
+#define DLGC_WANTMESSAGE     0x0004
+#define DLGC_HASSETSEL       0x0008
+#define DLGC_DEFPUSHBUTTON   0x0010
+#define DLGC_UNDEFPUSHBUTTON 0x0020
+#define DLGC_RADIOBUTTON     0x0040
+#define DLGC_WANTCHARS       0x0080
+#define DLGC_STATIC          0x0100
+#define DLGC_BUTTON          0x2000
+
+/* Standard dialog button IDs */
+#define IDOK                1
+#define IDCANCEL            2
+#define IDABORT             3
+#define IDRETRY             4
+#define IDIGNORE            5
+#define IDYES               6
+#define IDNO                7
+#define IDCLOSE             8
+#define IDHELP              9      
+
+/****** Window classes ******/
+
+typedef struct tagCREATESTRUCTA
+{
+    LPVOID      lpCreateParams;
+    HINSTANCE hInstance;
+    HMENU     hMenu;
+    HWND      hwndParent;
+    INT       cy;
+    INT       cx;
+    INT       y;
+    INT       x;
+    LONG        style;
+    LPCSTR      lpszName;
+    LPCSTR      lpszClass;
+    DWORD       dwExStyle;
+} CREATESTRUCTA, *LPCREATESTRUCTA;
+
+typedef struct
+{
+    LPVOID      lpCreateParams;
+    HINSTANCE hInstance;
+    HMENU     hMenu;
+    HWND      hwndParent;
+    INT       cy;
+    INT       cx;
+    INT       y;
+    INT       x;
+    LONG        style;
+    LPCWSTR     lpszName;
+    LPCWSTR     lpszClass;
+    DWORD       dwExStyle;
+} CREATESTRUCTW, *LPCREATESTRUCTW;
+
+DECL_WINELIB_TYPE_AW(CREATESTRUCT)
+DECL_WINELIB_TYPE_AW(LPCREATESTRUCT)
+
+typedef struct
+{
+    HDC   hdc;
+    WIN_BOOL  fErase;
+    RECT  rcPaint;
+    WIN_BOOL  fRestore;
+    WIN_BOOL  fIncUpdate;
+    BYTE    rgbReserved[32];
+} PAINTSTRUCT, *PPAINTSTRUCT, *LPPAINTSTRUCT;
+
+typedef struct 
+{
+    HMENU   hWindowMenu;
+    UINT    idFirstChild;
+} CLIENTCREATESTRUCT, *LPCLIENTCREATESTRUCT;
+
+
+typedef struct
+{
+    LPCSTR       szClass;
+    LPCSTR       szTitle;
+    HINSTANCE  hOwner;
+    INT        x;
+    INT        y;
+    INT        cx;
+    INT        cy;
+    DWORD        style;
+    LPARAM       lParam;
+} MDICREATESTRUCTA, *LPMDICREATESTRUCTA;
+
+typedef struct
+{
+    LPCWSTR      szClass;
+    LPCWSTR      szTitle;
+    HINSTANCE  hOwner;
+    INT        x;
+    INT        y;
+    INT        cx;
+    INT        cy;
+    DWORD        style;
+    LPARAM       lParam;
+} MDICREATESTRUCTW, *LPMDICREATESTRUCTW;
+
+DECL_WINELIB_TYPE_AW(MDICREATESTRUCT)
+DECL_WINELIB_TYPE_AW(LPMDICREATESTRUCT)
+
+#define MDITILE_VERTICAL     0x0000   
+#define MDITILE_HORIZONTAL   0x0001
+#define MDITILE_SKIPDISABLED 0x0002
+
+#define MDIS_ALLCHILDSTYLES  0x0001
+
+typedef struct {
+    DWORD   styleOld;
+    DWORD   styleNew;
+} STYLESTRUCT, *LPSTYLESTRUCT;
+
+  /* Offsets for GetWindowLong() and GetWindowWord() */
+#define GWL_USERDATA        (-21)
+#define GWL_EXSTYLE         (-20)
+#define GWL_STYLE           (-16)
+#define GWW_ID              (-12)
+#define GWL_ID              GWW_ID
+#define GWW_HWNDPARENT      (-8)
+#define GWL_HWNDPARENT      GWW_HWNDPARENT
+#define GWW_HINSTANCE       (-6)
+#define GWL_HINSTANCE       GWW_HINSTANCE
+#define GWL_WNDPROC         (-4)
+#define DWL_MSGRESULT	    0
+#define DWL_DLGPROC	    4
+#define DWL_USER	    8
+
+  /* GetWindow() constants */
+#define GW_HWNDFIRST	0
+#define GW_HWNDLAST	1
+#define GW_HWNDNEXT	2
+#define GW_HWNDPREV	3
+#define GW_OWNER	4
+#define GW_CHILD	5
+
+  /* WM_GETMINMAXINFO struct */
+typedef struct
+{
+    POINT   ptReserved;
+    POINT   ptMaxSize;
+    POINT   ptMaxPosition;
+    POINT   ptMinTrackSize;
+    POINT   ptMaxTrackSize;
+} MINMAXINFO, *PMINMAXINFO, *LPMINMAXINFO;
+
+
+  /* RedrawWindow() flags */
+#define RDW_INVALIDATE       0x0001
+#define RDW_INTERNALPAINT    0x0002
+#define RDW_ERASE            0x0004
+#define RDW_VALIDATE         0x0008
+#define RDW_NOINTERNALPAINT  0x0010
+#define RDW_NOERASE          0x0020
+#define RDW_NOCHILDREN       0x0040
+#define RDW_ALLCHILDREN      0x0080
+#define RDW_UPDATENOW        0x0100
+#define RDW_ERASENOW         0x0200
+#define RDW_FRAME            0x0400
+#define RDW_NOFRAME          0x0800
+
+/* debug flags */
+#define DBGFILL_ALLOC  0xfd
+#define DBGFILL_FREE   0xfb
+#define DBGFILL_BUFFER 0xf9
+#define DBGFILL_STACK  0xf7
+
+  /* WM_WINDOWPOSCHANGING/CHANGED struct */
+typedef struct tagWINDOWPOS
+{
+    HWND  hwnd;
+    HWND  hwndInsertAfter;
+    INT   x;
+    INT   y;
+    INT   cx;
+    INT   cy;
+    UINT  flags;
+} WINDOWPOS, *PWINDOWPOS, *LPWINDOWPOS;
+
+
+  /* WM_MOUSEACTIVATE return values */
+#define MA_ACTIVATE             1
+#define MA_ACTIVATEANDEAT       2
+#define MA_NOACTIVATE           3
+#define MA_NOACTIVATEANDEAT     4
+
+  /* WM_ACTIVATE wParam values */
+#define WA_INACTIVE             0
+#define WA_ACTIVE               1
+#define WA_CLICKACTIVE          2
+
+/* WM_GETICON/WM_SETICON params values */
+#define ICON_SMALL              0
+#define ICON_BIG                1
+
+  /* WM_NCCALCSIZE parameter structure */
+typedef struct
+{
+    RECT       rgrc[3];
+    WINDOWPOS *lppos;
+} NCCALCSIZE_PARAMS, *LPNCCALCSIZE_PARAMS;
+
+
+  /* WM_NCCALCSIZE return flags */
+#define WVR_ALIGNTOP        0x0010
+#define WVR_ALIGNLEFT       0x0020
+#define WVR_ALIGNBOTTOM     0x0040
+#define WVR_ALIGNRIGHT      0x0080
+#define WVR_HREDRAW         0x0100
+#define WVR_VREDRAW         0x0200
+#define WVR_REDRAW          (WVR_HREDRAW | WVR_VREDRAW)
+#define WVR_VALIDRECTS      0x0400
+
+  /* WM_NCHITTEST return codes */
+#define HTERROR             (-2)
+#define HTTRANSPARENT       (-1)
+#define HTNOWHERE           0
+#define HTCLIENT            1
+#define HTCAPTION           2
+#define HTSYSMENU           3
+#define HTSIZE              4
+#define HTMENU              5
+#define HTHSCROLL           6
+#define HTVSCROLL           7
+#define HTMINBUTTON         8
+#define HTMAXBUTTON         9
+#define HTLEFT              10
+#define HTRIGHT             11
+#define HTTOP               12
+#define HTTOPLEFT           13
+#define HTTOPRIGHT          14
+#define HTBOTTOM            15
+#define HTBOTTOMLEFT        16
+#define HTBOTTOMRIGHT       17
+#define HTBORDER            18
+#define HTGROWBOX           HTSIZE
+#define HTREDUCE            HTMINBUTTON
+#define HTZOOM              HTMAXBUTTON
+#define HTOBJECT            19
+#define HTCLOSE             20
+#define HTHELP              21
+#define HTSIZEFIRST         HTLEFT
+#define HTSIZELAST          HTBOTTOMRIGHT
+
+  /* WM_SYSCOMMAND parameters */
+#ifdef SC_SIZE /* at least HP-UX: already defined in /usr/include/sys/signal.h */
+#undef SC_SIZE
+#endif
+#define SC_SIZE         0xf000
+#define SC_MOVE         0xf010
+#define SC_MINIMIZE     0xf020
+#define SC_MAXIMIZE     0xf030
+#define SC_NEXTWINDOW   0xf040
+#define SC_PREVWINDOW   0xf050
+#define SC_CLOSE        0xf060
+#define SC_VSCROLL      0xf070
+#define SC_HSCROLL      0xf080
+#define SC_MOUSEMENU    0xf090
+#define SC_KEYMENU      0xf100
+#define SC_ARRANGE      0xf110
+#define SC_RESTORE      0xf120
+#define SC_TASKLIST     0xf130
+#define SC_SCREENSAVE   0xf140
+#define SC_HOTKEY       0xf150
+
+#define CS_VREDRAW          0x0001
+#define CS_HREDRAW          0x0002
+#define CS_KEYCVTWINDOW     0x0004
+#define CS_DBLCLKS          0x0008
+#define CS_OWNDC            0x0020
+#define CS_CLASSDC          0x0040
+#define CS_PARENTDC         0x0080
+#define CS_NOKEYCVT         0x0100
+#define CS_NOCLOSE          0x0200
+#define CS_SAVEBITS         0x0800
+#define CS_BYTEALIGNCLIENT  0x1000
+#define CS_BYTEALIGNWINDOW  0x2000
+#define CS_GLOBALCLASS      0x4000
+#define CS_IME              0x00010000
+
+#define PRF_CHECKVISIBLE    0x00000001L
+#define PRF_NONCLIENT       0x00000002L
+#define PRF_CLIENT          0x00000004L
+#define PRF_ERASEBKGND      0x00000008L
+#define PRF_CHILDREN        0x00000010L
+#define PRF_OWNED           0x00000020L
+ 
+  /* Offsets for GetClassLong() and GetClassWord() */
+#define GCL_MENUNAME        (-8)
+#define GCW_HBRBACKGROUND   (-10)
+#define GCL_HBRBACKGROUND   GCW_HBRBACKGROUND
+#define GCW_HCURSOR         (-12)
+#define GCL_HCURSOR         GCW_HCURSOR
+#define GCW_HICON           (-14)
+#define GCL_HICON           GCW_HICON
+#define GCW_HMODULE         (-16)
+#define GCL_HMODULE         GCW_HMODULE
+#define GCW_CBWNDEXTRA      (-18)
+#define GCL_CBWNDEXTRA      GCW_CBWNDEXTRA
+#define GCW_CBCLSEXTRA      (-20)
+#define GCL_CBCLSEXTRA      GCW_CBCLSEXTRA
+#define GCL_WNDPROC         (-24)
+#define GCW_STYLE           (-26)
+#define GCL_STYLE           GCW_STYLE
+#define GCW_ATOM            (-32)
+#define GCW_HICONSM         (-34)
+#define GCL_HICONSM         GCW_HICONSM
+
+
+/***** Window hooks *****/
+
+  /* Hook values */
+#define WH_MIN		    (-1)
+#define WH_MSGFILTER	    (-1)
+#define WH_JOURNALRECORD    0
+#define WH_JOURNALPLAYBACK  1
+#define WH_KEYBOARD	    2
+#define WH_GETMESSAGE	    3
+#define WH_CALLWNDPROC	    4
+#define WH_CBT		    5
+#define WH_SYSMSGFILTER	    6
+#define WH_MOUSE	    7
+#define WH_HARDWARE	    8
+#define WH_DEBUG	    9
+#define WH_SHELL            10
+#define WH_FOREGROUNDIDLE   11
+#define WH_CALLWNDPROCRET   12
+#define WH_MAX              12
+
+#define WH_MINHOOK          WH_MIN
+#define WH_MAXHOOK          WH_MAX
+#define WH_NB_HOOKS         (WH_MAXHOOK-WH_MINHOOK+1)
+
+  /* Hook action codes */
+#define HC_ACTION           0
+#define HC_GETNEXT          1
+#define HC_SKIP             2
+#define HC_NOREMOVE         3
+#define HC_NOREM            HC_NOREMOVE
+#define HC_SYSMODALON       4
+#define HC_SYSMODALOFF      5
+
+  /* CallMsgFilter() values */
+#define MSGF_DIALOGBOX      0
+#define MSGF_MESSAGEBOX     1
+#define MSGF_MENU           2
+#define MSGF_MOVE           3
+#define MSGF_SIZE           4
+#define MSGF_SCROLLBAR      5
+#define MSGF_NEXTWINDOW     6
+#define MSGF_MAINLOOP       8
+#define MSGF_USER        4096
+
+typedef struct
+{
+    UINT      style;
+    WNDPROC   lpfnWndProc;
+    INT       cbClsExtra;
+    INT       cbWndExtra;
+    HINSTANCE hInstance;
+    HICON     hIcon;
+    HCURSOR   hCursor;
+    HBRUSH    hbrBackground;
+    LPCSTR      lpszMenuName;
+    LPCSTR      lpszClassName;
+} WNDCLASSA, *LPWNDCLASSA;
+
+typedef struct
+{
+    UINT      style;
+    WNDPROC   lpfnWndProc;
+    INT       cbClsExtra;
+    INT       cbWndExtra;
+    HINSTANCE hInstance;
+    HICON     hIcon;
+    HCURSOR   hCursor;
+    HBRUSH    hbrBackground;
+    LPCWSTR     lpszMenuName;
+    LPCWSTR     lpszClassName;
+} WNDCLASSW, *LPWNDCLASSW;
+
+DECL_WINELIB_TYPE_AW(WNDCLASS)
+DECL_WINELIB_TYPE_AW(LPWNDCLASS)
+
+typedef struct {
+    DWORD dwData;
+    DWORD cbData;
+    LPVOID lpData;
+} COPYDATASTRUCT, *PCOPYDATASTRUCT, *LPCOPYDATASTRUCT;
+
+typedef struct {
+    HMENU hmenuIn;
+    HMENU hmenuNext;
+    HWND  hwndNext;
+} MDINEXTMENU, *PMDINEXTMENU, *LPMDINEXTMENU;
+
+/* WinHelp internal structure */
+typedef struct {
+	WORD size;
+	WORD command;
+	LONG data;
+	LONG reserved;
+	WORD ofsFilename;
+	WORD ofsData;
+} WINHELP,*LPWINHELP;
+
+typedef struct
+{
+    UINT16  mkSize;
+    BYTE    mkKeyList;
+    BYTE    szKeyphrase[1];
+} MULTIKEYHELP, *LPMULTIKEYHELP;
+
+typedef struct {
+	WORD wStructSize;
+	WORD x;
+	WORD y;
+	WORD dx;
+	WORD dy;
+	WORD wMax;
+	char rgchMember[2];
+} HELPWININFO, *LPHELPWININFO;
+
+#define HELP_CONTEXT        0x0001
+#define HELP_QUIT           0x0002
+#define HELP_INDEX          0x0003
+#define HELP_CONTENTS       0x0003
+#define HELP_HELPONHELP     0x0004
+#define HELP_SETINDEX       0x0005
+#define HELP_SETCONTENTS    0x0005
+#define HELP_CONTEXTPOPUP   0x0008
+#define HELP_FORCEFILE      0x0009
+#define HELP_KEY            0x0101
+#define HELP_COMMAND        0x0102
+#define HELP_PARTIALKEY     0x0105
+#define HELP_MULTIKEY       0x0201
+#define HELP_SETWINPOS      0x0203
+#define HELP_CONTEXTMENU    0x000a
+#define HELP_FINDER	    0x000b
+#define HELP_WM_HELP	    0x000c
+#define HELP_SETPOPUP_POS   0x000d
+
+#define HELP_TCARD	    0x8000
+#define HELP_TCARD_DATA	    0x0010
+#define HELP_TCARD_OTHER_CALLER 0x0011
+
+
+     /* ChangeDisplaySettings return codes */
+
+#define DISP_CHANGE_SUCCESSFUL 0
+#define DISP_CHANGE_RESTART    1
+#define DISP_CHANGE_FAILED     (-1)
+#define DISP_CHANGE_BADMODE    (-2)
+#define DISP_CHANGE_NOTUPDATED (-3)
+#define DISP_CHANGE_BADFLAGS   (-4)
+#define DISP_CHANGE_BADPARAM   (-5)
+
+/* ChangeDisplaySettings.dwFlags */
+#define	CDS_UPDATEREGISTRY	0x00000001
+#define	CDS_TEST		0x00000002
+#define	CDS_FULLSCREEN		0x00000004
+#define	CDS_GLOBAL		0x00000008
+#define	CDS_SET_PRIMARY		0x00000010
+#define	CDS_RESET		0x40000000
+#define	CDS_SETRECT		0x20000000
+#define	CDS_NORESET		0x10000000
+
+/* flags to FormatMessage */
+#define	FORMAT_MESSAGE_ALLOCATE_BUFFER	0x00000100
+#define	FORMAT_MESSAGE_IGNORE_INSERTS	0x00000200
+#define	FORMAT_MESSAGE_FROM_STRING	0x00000400
+#define	FORMAT_MESSAGE_FROM_HMODULE	0x00000800
+#define	FORMAT_MESSAGE_FROM_SYSTEM	0x00001000
+#define	FORMAT_MESSAGE_ARGUMENT_ARRAY	0x00002000
+#define	FORMAT_MESSAGE_MAX_WIDTH_MASK	0x000000FF
+
+typedef struct
+{
+    UINT      cbSize;
+    UINT      style;
+    WNDPROC   lpfnWndProc;
+    INT       cbClsExtra;
+    INT       cbWndExtra;
+    HINSTANCE hInstance;
+    HICON     hIcon;
+    HCURSOR   hCursor;
+    HBRUSH    hbrBackground;
+    LPCSTR      lpszMenuName;
+    LPCSTR      lpszClassName;
+    HICON     hIconSm;
+} WNDCLASSEXA, *LPWNDCLASSEXA;
+
+typedef struct
+{
+    UINT      cbSize;
+    UINT      style;
+    WNDPROC   lpfnWndProc;
+    INT       cbClsExtra;
+    INT       cbWndExtra;
+    HINSTANCE hInstance;
+    HICON     hIcon;
+    HCURSOR   hCursor;
+    HBRUSH    hbrBackground;
+    LPCWSTR     lpszMenuName;
+    LPCWSTR     lpszClassName;
+    HICON     hIconSm;
+} WNDCLASSEXW, *LPWNDCLASSEXW;
+
+DECL_WINELIB_TYPE_AW(WNDCLASSEX)
+DECL_WINELIB_TYPE_AW(LPWNDCLASSEX)
+
+typedef struct tagMSG
+{
+    HWND    hwnd;
+    UINT    message;
+    WPARAM  wParam;
+    LPARAM    lParam;
+    DWORD     time;
+    POINT   pt;
+} MSG, *LPMSG;
+
+#define POINTSTOPOINT(pt, pts)                          \
+        { (pt).x = (LONG)(SHORT)LOWORD(*(LONG*)&pts);   \
+          (pt).y = (LONG)(SHORT)HIWORD(*(LONG*)&pts); }          
+
+#define POINTTOPOINTS(pt)      (MAKELONG((short)((pt).x), (short)((pt).y)))
+
+
+/* Cursors / Icons */
+
+typedef struct {
+	WIN_BOOL	fIcon;
+	DWORD		xHotspot;
+	DWORD		yHotspot;
+	HBITMAP	hbmMask;
+	HBITMAP	hbmColor;
+} ICONINFO,*LPICONINFO;
+
+
+/* this is the 6 byte accel struct used in Win32 when presented to the user */
+typedef struct
+{
+    BYTE   fVirt;
+    BYTE   pad0;
+    WORD   key;
+    WORD   cmd;
+} ACCEL, *LPACCEL;
+
+/* this is the 8 byte accel struct used in Win32 resources (internal only) */
+typedef struct
+{
+    BYTE   fVirt;
+    BYTE   pad0;
+    WORD   key;
+    WORD   cmd;
+    WORD   pad1;
+} PE_ACCEL, *LPPE_ACCEL;
+
+
+/* Flags for TrackPopupMenu */
+#define TPM_LEFTBUTTON    0x0000
+#define TPM_RIGHTBUTTON   0x0002
+#define TPM_LEFTALIGN     0x0000
+#define TPM_CENTERALIGN   0x0004
+#define TPM_RIGHTALIGN    0x0008
+#define TPM_TOPALIGN      0x0000
+#define TPM_VCENTERALIGN  0x0010
+#define TPM_BOTTOMALIGN   0x0020
+#define TPM_HORIZONTAL    0x0000
+#define TPM_VERTICAL      0x0040
+#define TPM_NONOTIFY      0x0080
+#define TPM_RETURNCMD     0x0100
+
+typedef struct 
+{
+    UINT   cbSize;
+    RECT   rcExclude;
+} TPMPARAMS, *LPTPMPARAMS;
+
+/* FIXME: not sure this one is correct */
+typedef struct {
+  UINT    cbSize;
+  UINT    fMask;
+  UINT    fType;
+  UINT    fState;
+  UINT    wID;
+  HMENU   hSubMenu;
+  HBITMAP hbmpChecked;
+  HBITMAP hbmpUnchecked;
+  DWORD   dwItemData;
+  LPSTR   dwTypeData;
+  UINT    cch;
+  HBITMAP hbmpItem;
+} MENUITEMINFOA, *LPMENUITEMINFOA;
+
+typedef struct {
+  UINT    cbSize;
+  UINT    fMask;
+  UINT    fType;
+  UINT    fState;
+  UINT    wID;
+  HMENU   hSubMenu;
+  HBITMAP hbmpChecked;
+  HBITMAP hbmpUnchecked;
+  DWORD     dwItemData;
+  LPWSTR    dwTypeData;
+  UINT    cch;
+  HBITMAP hbmpItem;
+} MENUITEMINFOW, *LPMENUITEMINFOW;
+
+DECL_WINELIB_TYPE_AW(MENUITEMINFO)
+DECL_WINELIB_TYPE_AW(LPMENUITEMINFO)
+
+typedef struct {
+  DWORD   cbSize;
+  DWORD   fMask;
+  DWORD   dwStyle;
+  UINT    cyMax;
+  HBRUSH  hbrBack;
+  DWORD   dwContextHelpID;
+  DWORD   dwMenuData;
+} MENUINFO, *LPMENUINFO;
+
+typedef MENUINFO const * LPCMENUINFO;
+
+#define MIM_MAXHEIGHT		0x00000001
+#define MIM_BACKGROUND		0x00000002
+#define MIM_HELPID		0x00000004
+#define MIM_MENUDATA		0x00000008
+#define MIM_STYLE		0x00000010
+#define MIM_APPLYTOSUBMENUS	0x80000000
+
+typedef struct {
+  WORD versionNumber;
+  WORD offset;
+} MENUITEMTEMPLATEHEADER, *PMENUITEMTEMPLATEHEADER;
+
+
+typedef struct {
+  WORD mtOption;
+  WORD mtID;
+  WCHAR mtString[1];
+} MENUITEMTEMPLATE, *PMENUITEMTEMPLATE;
+
+
+typedef VOID   MENUTEMPLATE;
+typedef PVOID *LPMENUTEMPLATE;
+
+/* Field specifiers for MENUITEMINFO[AW] type.  */
+#define MIIM_STATE       0x00000001
+#define MIIM_ID          0x00000002
+#define MIIM_SUBMENU     0x00000004
+#define MIIM_CHECKMARKS  0x00000008
+#define MIIM_TYPE        0x00000010
+#define MIIM_DATA        0x00000020
+#define MIIM_STRING      0x00000040
+#define MIIM_BITMAP      0x00000080
+#define MIIM_FTYPE       0x00000100
+
+#define HBMMENU_CALLBACK	((HBITMAP) -1)
+#define HBMMENU_SYSTEM		((HBITMAP)  1)
+#define HBMMENU_MBAR_RESTORE	((HBITMAP)  2)
+#define HBMMENU_MBAR_MINIMIZE	((HBITMAP)  3)
+#define HBMMENU_MBAR_CLOSE	((HBITMAP)  5)
+#define HBMMENU_MBAR_CLOSE_D	((HBITMAP)  6)
+#define HBMMENU_MBAR_MINIMIZE_D	((HBITMAP)  7)
+#define HBMMENU_POPUP_CLOSE	((HBITMAP)  8)
+#define HBMMENU_POPUP_RESTORE	((HBITMAP)  9)
+#define HBMMENU_POPUP_MAXIMIZE	((HBITMAP) 10)
+#define HBMMENU_POPUP_MINIMIZE	((HBITMAP) 11)
+
+/* DrawState defines ... */
+typedef WIN_BOOL CALLBACK (*DRAWSTATEPROC)(HDC,LPARAM,WPARAM,INT,INT);
+
+/* WM_H/VSCROLL commands */
+#define SB_LINEUP           0
+#define SB_LINELEFT         0
+#define SB_LINEDOWN         1
+#define SB_LINERIGHT        1
+#define SB_PAGEUP           2
+#define SB_PAGELEFT         2
+#define SB_PAGEDOWN         3
+#define SB_PAGERIGHT        3
+#define SB_THUMBPOSITION    4
+#define SB_THUMBTRACK       5
+#define SB_TOP              6
+#define SB_LEFT             6
+#define SB_BOTTOM           7
+#define SB_RIGHT            7
+#define SB_ENDSCROLL        8
+
+/* Scroll bar selection constants */
+#define SB_HORZ             0
+#define SB_VERT             1
+#define SB_CTL              2
+#define SB_BOTH             3
+
+/* Scrollbar styles */
+#define SBS_HORZ                    0x0000L
+#define SBS_VERT                    0x0001L
+#define SBS_TOPALIGN                0x0002L
+#define SBS_LEFTALIGN               0x0002L
+#define SBS_BOTTOMALIGN             0x0004L
+#define SBS_RIGHTALIGN              0x0004L
+#define SBS_SIZEBOXTOPLEFTALIGN     0x0002L
+#define SBS_SIZEBOXBOTTOMRIGHTALIGN 0x0004L
+#define SBS_SIZEBOX                 0x0008L
+#define SBS_SIZEGRIP                0x0010L
+
+/* EnableScrollBar() flags */
+#define ESB_ENABLE_BOTH     0x0000
+#define ESB_DISABLE_BOTH    0x0003
+
+#define ESB_DISABLE_LEFT    0x0001
+#define ESB_DISABLE_RIGHT   0x0002
+
+#define ESB_DISABLE_UP      0x0001
+#define ESB_DISABLE_DOWN    0x0002
+
+#define ESB_DISABLE_LTUP    ESB_DISABLE_LEFT
+#define ESB_DISABLE_RTDN    ESB_DISABLE_RIGHT
+
+/* Win32 button control messages */
+#define BM_GETCHECK          0x00f0
+#define BM_SETCHECK          0x00f1
+#define BM_GETSTATE          0x00f2
+#define BM_SETSTATE          0x00f3
+#define BM_SETSTYLE          0x00f4
+#define BM_CLICK             0x00f5
+#define BM_GETIMAGE          0x00f6
+#define BM_SETIMAGE          0x00f7
+/* Winelib button control messages */
+
+/* Button notification codes */
+#define BN_CLICKED             0
+#define BN_PAINT               1
+#define BN_HILITE              2
+#define BN_UNHILITE            3
+#define BN_DISABLE             4
+#define BN_DOUBLECLICKED       5
+
+/* Button states */
+#define BST_UNCHECKED        0x0000
+#define BST_CHECKED          0x0001
+#define BST_INDETERMINATE    0x0002
+#define BST_PUSHED           0x0004
+#define BST_FOCUS            0x0008      
+
+/* Static Control Styles */
+#define SS_LEFT             0x00000000L
+#define SS_CENTER           0x00000001L
+#define SS_RIGHT            0x00000002L
+#define SS_ICON             0x00000003L
+#define SS_BLACKRECT        0x00000004L
+#define SS_GRAYRECT         0x00000005L
+#define SS_WHITERECT        0x00000006L
+#define SS_BLACKFRAME       0x00000007L
+#define SS_GRAYFRAME        0x00000008L
+#define SS_WHITEFRAME       0x00000009L
+
+#define SS_SIMPLE           0x0000000BL
+#define SS_LEFTNOWORDWRAP   0x0000000CL
+
+#define SS_OWNERDRAW        0x0000000DL
+#define SS_BITMAP           0x0000000EL
+#define SS_ENHMETAFILE      0x0000000FL
+
+#define SS_ETCHEDHORZ       0x00000010L
+#define SS_ETCHEDVERT       0x00000011L
+#define SS_ETCHEDFRAME      0x00000012L
+#define SS_TYPEMASK         0x0000001FL
+
+#define SS_NOPREFIX         0x00000080L
+#define SS_NOTIFY           0x00000100L
+#define SS_CENTERIMAGE      0x00000200L
+#define SS_RIGHTJUST        0x00000400L
+#define SS_REALSIZEIMAGE    0x00000800L
+#define SS_SUNKEN           0x00001000L
+
+/* Static Control Messages */
+#define STM_SETICON       0x0170
+#define STM_GETICON       0x0171
+#define STM_SETIMAGE        0x0172
+#define STM_GETIMAGE        0x0173
+
+/* Scrollbar messages */
+#define SBM_SETPOS             0x00e0
+#define SBM_GETPOS             0x00e1
+#define SBM_SETRANGE           0x00e2
+#define SBM_GETRANGE           0x00e3
+#define SBM_ENABLE_ARROWS      0x00e4
+#define SBM_SETRANGEREDRAW     0x00e6
+#define SBM_SETSCROLLINFO      0x00e9
+#define SBM_GETSCROLLINFO      0x00ea
+
+/* Scrollbar info */
+typedef struct
+{
+    UINT    cbSize;
+    UINT    fMask;
+    INT     nMin;
+    INT     nMax;
+    UINT    nPage;
+    INT     nPos;
+    INT     nTrackPos;
+} SCROLLINFO, *LPSCROLLINFO;
+ 
+/* GetScrollInfo() flags */ 
+#define SIF_RANGE           0x0001
+#define SIF_PAGE            0x0002
+#define SIF_POS             0x0004
+#define SIF_DISABLENOSCROLL 0x0008
+#define SIF_TRACKPOS        0x0010
+#define SIF_ALL             (SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS)
+
+/* Listbox styles */
+#define LBS_NOTIFY               0x0001
+#define LBS_SORT                 0x0002
+#define LBS_NOREDRAW             0x0004
+#define LBS_MULTIPLESEL          0x0008
+#define LBS_OWNERDRAWFIXED       0x0010
+#define LBS_OWNERDRAWVARIABLE    0x0020
+#define LBS_HASSTRINGS           0x0040
+#define LBS_USETABSTOPS          0x0080
+#define LBS_NOINTEGRALHEIGHT     0x0100
+#define LBS_MULTICOLUMN          0x0200
+#define LBS_WANTKEYBOARDINPUT    0x0400
+#define LBS_EXTENDEDSEL          0x0800
+#define LBS_DISABLENOSCROLL      0x1000
+#define LBS_NODATA               0x2000
+#define LBS_NOSEL                0x4000
+#define LBS_STANDARD  (LBS_NOTIFY | LBS_SORT | WS_VSCROLL | WS_BORDER)
+
+/* Listbox messages */
+#define LB_ADDSTRING           0x0180
+#define LB_INSERTSTRING        0x0181
+#define LB_DELETESTRING        0x0182
+#define LB_SELITEMRANGEEX      0x0183
+#define LB_RESETCONTENT        0x0184
+#define LB_SETSEL              0x0185
+#define LB_SETCURSEL           0x0186
+#define LB_GETSEL              0x0187
+#define LB_GETCURSEL           0x0188
+#define LB_GETTEXT             0x0189
+#define LB_GETTEXTLEN          0x018a
+#define LB_GETCOUNT            0x018b
+#define LB_SELECTSTRING        0x018c
+#define LB_DIR                 0x018d
+#define LB_GETTOPINDEX         0x018e
+#define LB_FINDSTRING          0x018f
+#define LB_GETSELCOUNT         0x0190
+#define LB_GETSELITEMS         0x0191
+#define LB_SETTABSTOPS         0x0192
+#define LB_GETHORIZONTALEXTENT 0x0193
+#define LB_SETHORIZONTALEXTENT 0x0194
+#define LB_SETCOLUMNWIDTH      0x0195
+#define LB_ADDFILE             0x0196
+#define LB_SETTOPINDEX         0x0197
+#define LB_GETITEMRECT         0x0198
+#define LB_GETITEMDATA         0x0199
+#define LB_SETITEMDATA         0x019a
+#define LB_SELITEMRANGE        0x019b
+#define LB_SETANCHORINDEX      0x019c
+#define LB_GETANCHORINDEX      0x019d
+#define LB_SETCARETINDEX       0x019e
+#define LB_GETCARETINDEX       0x019f
+#define LB_SETITEMHEIGHT       0x01a0
+#define LB_GETITEMHEIGHT       0x01a1
+#define LB_FINDSTRINGEXACT     0x01a2
+#define LB_CARETON             0x01a3
+#define LB_CARETOFF            0x01a4
+#define LB_SETLOCALE           0x01a5
+#define LB_GETLOCALE           0x01a6
+#define LB_SETCOUNT            0x01a7
+#define LB_INITSTORAGE         0x01a8
+#define LB_ITEMFROMPOINT       0x01a9
+
+/* Listbox notification codes */
+#define LBN_ERRSPACE        (-2)
+#define LBN_SELCHANGE       1
+#define LBN_DBLCLK          2
+#define LBN_SELCANCEL       3
+#define LBN_SETFOCUS        4
+#define LBN_KILLFOCUS       5
+
+/* Listbox message return values */
+#define LB_OKAY             0
+#define LB_ERR              (-1)
+#define LB_ERRSPACE         (-2)
+
+#define LB_CTLCODE          0L
+
+/* Combo box styles */
+#define CBS_SIMPLE            0x0001L
+#define CBS_DROPDOWN          0x0002L
+#define CBS_DROPDOWNLIST      0x0003L
+#define CBS_OWNERDRAWFIXED    0x0010L
+#define CBS_OWNERDRAWVARIABLE 0x0020L
+#define CBS_AUTOHSCROLL       0x0040L
+#define CBS_OEMCONVERT        0x0080L
+#define CBS_SORT              0x0100L
+#define CBS_HASSTRINGS        0x0200L
+#define CBS_NOINTEGRALHEIGHT  0x0400L
+#define CBS_DISABLENOSCROLL   0x0800L
+
+#define CBS_UPPERCASE	      0x2000L
+#define CBS_LOWERCASE	      0x4000L
+
+
+/* Combo box messages */
+#define CB_GETEDITSEL            0x0140
+#define CB_LIMITTEXT             0x0141
+#define CB_SETEDITSEL            0x0142
+#define CB_ADDSTRING             0x0143
+#define CB_DELETESTRING          0x0144
+#define CB_DIR                   0x0145
+#define CB_GETCOUNT              0x0146
+#define CB_GETCURSEL             0x0147
+#define CB_GETLBTEXT             0x0148
+#define CB_GETLBTEXTLEN          0x0149
+#define CB_INSERTSTRING          0x014a
+#define CB_RESETCONTENT          0x014b
+#define CB_FINDSTRING            0x014c
+#define CB_SELECTSTRING          0x014d
+#define CB_SETCURSEL             0x014e
+#define CB_SHOWDROPDOWN          0x014f
+#define CB_GETITEMDATA           0x0150
+#define CB_SETITEMDATA           0x0151
+#define CB_GETDROPPEDCONTROLRECT 0x0152
+#define CB_SETITEMHEIGHT         0x0153
+#define CB_GETITEMHEIGHT         0x0154
+#define CB_SETEXTENDEDUI         0x0155
+#define CB_GETEXTENDEDUI         0x0156
+#define CB_GETDROPPEDSTATE       0x0157
+#define CB_FINDSTRINGEXACT       0x0158
+#define CB_SETLOCALE             0x0159
+#define CB_GETLOCALE             0x015a
+#define CB_GETTOPINDEX           0x015b
+#define CB_SETTOPINDEX           0x015c
+#define CB_GETHORIZONTALEXTENT   0x015d
+#define CB_SETHORIZONTALEXTENT   0x015e
+#define CB_GETDROPPEDWIDTH       0x015f
+#define CB_SETDROPPEDWIDTH       0x0160
+#define CB_INITSTORAGE           0x0161
+
+/* Combo box notification codes */
+#define CBN_ERRSPACE        (-1)
+#define CBN_SELCHANGE       1
+#define CBN_DBLCLK          2
+#define CBN_SETFOCUS        3
+#define CBN_KILLFOCUS       4
+#define CBN_EDITCHANGE      5
+#define CBN_EDITUPDATE      6
+#define CBN_DROPDOWN        7
+#define CBN_CLOSEUP         8
+#define CBN_SELENDOK        9
+#define CBN_SELENDCANCEL    10
+
+/* Combo box message return values */
+#define CB_OKAY             0
+#define CB_ERR              (-1)
+#define CB_ERRSPACE         (-2)
+
+#define MB_OK			0x00000000
+#define MB_OKCANCEL		0x00000001
+#define MB_ABORTRETRYIGNORE	0x00000002
+#define MB_YESNOCANCEL		0x00000003
+#define MB_YESNO		0x00000004
+#define MB_RETRYCANCEL		0x00000005
+#define MB_TYPEMASK		0x0000000F
+
+#define MB_ICONHAND		0x00000010
+#define MB_ICONQUESTION		0x00000020
+#define MB_ICONEXCLAMATION	0x00000030
+#define MB_ICONASTERISK		0x00000040
+#define	MB_USERICON		0x00000080
+#define MB_ICONMASK		0x000000F0
+
+#define MB_ICONINFORMATION	MB_ICONASTERISK
+#define MB_ICONSTOP		MB_ICONHAND
+#define MB_ICONWARNING		MB_ICONEXCLAMATION
+#define MB_ICONERROR		MB_ICONHAND
+
+#define MB_DEFBUTTON1		0x00000000
+#define MB_DEFBUTTON2		0x00000100
+#define MB_DEFBUTTON3		0x00000200
+#define MB_DEFBUTTON4		0x00000300
+#define MB_DEFMASK		0x00000F00
+
+#define MB_APPLMODAL		0x00000000
+#define MB_SYSTEMMODAL		0x00001000
+#define MB_TASKMODAL		0x00002000
+#define MB_MODEMASK		0x00003000
+
+#define MB_HELP			0x00004000
+#define MB_NOFOCUS		0x00008000
+#define MB_MISCMASK		0x0000C000
+
+#define MB_SETFOREGROUND	0x00010000
+#define MB_DEFAULT_DESKTOP_ONLY	0x00020000
+#define MB_SERVICE_NOTIFICATION	0x00040000
+#define MB_TOPMOST		0x00040000
+#define MB_RIGHT		0x00080000
+#define MB_RTLREADING		0x00100000
+
+#define	HELPINFO_WINDOW		0x0001
+#define	HELPINFO_MENUITEM	0x0002
+
+/* Structure pointed to by lParam of WM_HELP */
+typedef struct			
+{
+    UINT	cbSize;		/* Size in bytes of this struct  */
+    INT	iContextType;	/* Either HELPINFO_WINDOW or HELPINFO_MENUITEM */
+    INT	iCtrlId;	/* Control Id or a Menu item Id. */
+    HANDLE	hItemHandle;	/* hWnd of control or hMenu.     */
+    DWORD	dwContextId;	/* Context Id associated with this item */
+    POINT	MousePos;	/* Mouse Position in screen co-ordinates */
+}  HELPINFO,*LPHELPINFO;
+
+typedef void CALLBACK (*MSGBOXCALLBACK)(LPHELPINFO lpHelpInfo);
+
+typedef struct
+{
+    UINT	cbSize;
+    HWND	hwndOwner;
+    HINSTANCE	hInstance;
+    LPCSTR	lpszText;
+    LPCSTR	lpszCaption;
+    DWORD	dwStyle;
+    LPCSTR	lpszIcon;
+    DWORD	dwContextHelpId;
+    MSGBOXCALLBACK	lpfnMsgBoxCallback;
+    DWORD	dwLanguageId;
+} MSGBOXPARAMSA,*LPMSGBOXPARAMSA;
+
+typedef struct
+{
+    UINT	cbSize;
+    HWND	hwndOwner;
+    HINSTANCE	hInstance;
+    LPCWSTR	lpszText;
+    LPCWSTR	lpszCaption;
+    DWORD	dwStyle;
+    LPCWSTR	lpszIcon;
+    DWORD	dwContextHelpId;
+    MSGBOXCALLBACK	lpfnMsgBoxCallback;
+    DWORD	dwLanguageId;
+} MSGBOXPARAMSW,*LPMSGBOXPARAMSW;
+
+DECL_WINELIB_TYPE_AW(MSGBOXPARAMS)
+DECL_WINELIB_TYPE_AW(LPMSGBOXPARAMS)
+
+typedef struct _numberfmt32a {
+    UINT NumDigits;
+    UINT LeadingZero;
+    UINT Grouping;
+    LPCSTR lpDecimalSep;
+    LPCSTR lpThousandSep;
+    UINT NegativeOrder;
+} NUMBERFMTA;
+
+typedef struct _numberfmt32w {
+    UINT NumDigits;
+    UINT LeadingZero;
+    UINT Grouping;
+    LPCWSTR lpDecimalSep;
+    LPCWSTR lpThousandSep;
+    UINT NegativeOrder;
+} NUMBERFMTW;
+
+typedef struct _currencyfmt32a
+{   
+	UINT      NumDigits;   
+	UINT      LeadingZero; 
+	UINT      Grouping;   
+	LPCSTR    lpDecimalSep;   
+	LPCSTR    lpThousandSep; 
+	UINT      NegativeOrder;   
+	UINT      PositiveOrder; 
+	LPCSTR    lpCurrencySymbol;
+} CURRENCYFMTA; 
+
+typedef struct _currencyfmt32w
+{   
+	UINT      NumDigits;   
+	UINT      LeadingZero; 
+	UINT      Grouping;   
+	LPCWSTR   lpDecimalSep;   
+	LPCWSTR   lpThousandSep; 
+	UINT      NegativeOrder;   
+	UINT      PositiveOrder; 
+	LPCWSTR   lpCurrencySymbol;
+} CURRENCYFMTW; 
+
+#define MONITOR_DEFAULTTONULL       0x00000000
+#define MONITOR_DEFAULTTOPRIMARY    0x00000001
+#define MONITOR_DEFAULTTONEAREST    0x00000002
+
+#define MONITORINFOF_PRIMARY        0x00000001
+
+typedef struct tagMONITORINFO
+{
+    DWORD   cbSize;
+    RECT  rcMonitor;
+    RECT  rcWork;
+    DWORD   dwFlags;
+} MONITORINFO, *LPMONITORINFO;
+
+
+typedef WIN_BOOL  CALLBACK (*MONITORENUMPROC)(HMONITOR,HDC,LPRECT,LPARAM);
+
+/* FIXME: use this instead of LPCVOID for CreateDialogIndirectParam
+   and DialogBoxIndirectParam */
+typedef struct tagDLGTEMPLATE
+{
+    DWORD style;
+    DWORD dwExtendedStyle;
+    WORD cdit;
+    short x;
+    short y;
+    short cx;
+    short cy;
+} DLGTEMPLATE;
+
+typedef DLGTEMPLATE *LPDLGTEMPLATEA;
+typedef DLGTEMPLATE *LPDLGTEMPLATEW;
+#define LPDLGTEMPLATE WINELIB_NAME_AW(LPDLGTEMPLATE)
+typedef const DLGTEMPLATE *LPCDLGTEMPLATEA;
+typedef const DLGTEMPLATE *LPCDLGTEMPLATEW;
+#define LPCDLGTEMPLATE WINELIB_NAME_AW(LPCDLGTEMPLATE)
+
+typedef struct tagDLGITEMTEMPLATE
+{
+    DWORD style;
+    DWORD dwExtendedStyle;
+    short x;
+    short y;
+    short cx;
+    short cy;
+    WORD id;
+} DLGITEMTEMPLATE;
+
+typedef DLGITEMTEMPLATE *LPDLGITEMTEMPLATEA;
+typedef DLGITEMTEMPLATE *LPDLGITEMTEMPLATEW;
+#define LPDLGITEMTEMPLATE WINELIB_NAME_AW(LPDLGITEMTEMPLATE)
+typedef const DLGITEMTEMPLATE *LPCDLGITEMTEMPLATEA;
+typedef const DLGITEMTEMPLATE *LPCDLGITEMTEMPLATEW;
+#define LPCDLGITEMTEMPLATE WINELIB_NAME_AW(LPCDLGITEMTEMPLATE)
+
+
+  /* CBT hook values */
+#define HCBT_MOVESIZE	    0
+#define HCBT_MINMAX	    1
+#define HCBT_QS 	    2
+#define HCBT_CREATEWND	    3
+#define HCBT_DESTROYWND	    4
+#define HCBT_ACTIVATE	    5
+#define HCBT_CLICKSKIPPED   6
+#define HCBT_KEYSKIPPED     7
+#define HCBT_SYSCOMMAND	    8
+#define HCBT_SETFOCUS	    9
+
+  /* CBT hook structures */
+
+typedef struct
+{
+    CREATESTRUCTA *lpcs;
+    HWND           hwndInsertAfter;
+} CBT_CREATEWNDA, *LPCBT_CREATEWNDA;
+
+typedef struct
+{
+    CREATESTRUCTW *lpcs;
+    HWND           hwndInsertAfter;
+} CBT_CREATEWNDW, *LPCBT_CREATEWNDW;
+
+DECL_WINELIB_TYPE_AW(CBT_CREATEWND)
+DECL_WINELIB_TYPE_AW(LPCBT_CREATEWND)
+
+typedef struct
+{
+    WIN_BOOL    fMouse;
+    HWND    hWndActive;
+} CBTACTIVATESTRUCT, *LPCBTACTIVATESTRUCT;
+
+
+/* modifiers for RegisterHotKey */
+#define	MOD_ALT		0x0001
+#define	MOD_CONTROL	0x0002
+#define	MOD_SHIFT	0x0004
+#define	MOD_WIN		0x0008
+
+/* ids for RegisterHotKey */
+#define	IDHOT_SNAPWINDOW	(-1)    /* SHIFT-PRINTSCRN  */
+#define	IDHOT_SNAPDESKTOP	(-2)    /* PRINTSCRN        */
+
+  /* keybd_event flags */
+#define KEYEVENTF_EXTENDEDKEY        0x0001
+#define KEYEVENTF_KEYUP              0x0002
+#define KEYEVENTF_WINE_FORCEEXTENDED 0x8000
+
+  /* mouse_event flags */
+#define MOUSEEVENTF_MOVE        0x0001
+#define MOUSEEVENTF_LEFTDOWN    0x0002
+#define MOUSEEVENTF_LEFTUP      0x0004
+#define MOUSEEVENTF_RIGHTDOWN   0x0008
+#define MOUSEEVENTF_RIGHTUP     0x0010
+#define MOUSEEVENTF_MIDDLEDOWN  0x0020
+#define MOUSEEVENTF_MIDDLEUP    0x0040
+#define MOUSEEVENTF_WHEEL       0x0800
+#define MOUSEEVENTF_ABSOLUTE    0x8000
+
+/* ExitWindows() flags */
+#define EW_RESTARTWINDOWS   0x0042
+#define EW_REBOOTSYSTEM     0x0043
+#define EW_EXITANDEXECAPP   0x0044
+
+/* ExitWindowsEx() flags */
+#define EWX_LOGOFF           0
+#define EWX_SHUTDOWN         1
+#define EWX_REBOOT           2
+#define EWX_FORCE            4
+#define EWX_POWEROFF         8
+
+/* SetLastErrorEx types */
+#define	SLE_ERROR	0x00000001
+#define	SLE_MINORERROR	0x00000002
+#define	SLE_WARNING	0x00000003
+
+/* Predefined resources */
+#define IDI_APPLICATIONA MAKEINTRESOURCEA(32512)
+#define IDI_APPLICATIONW MAKEINTRESOURCEW(32512)
+#define IDI_APPLICATION    WINELIB_NAME_AW(IDI_APPLICATION)
+#define IDI_HANDA        MAKEINTRESOURCEA(32513)
+#define IDI_HANDW        MAKEINTRESOURCEW(32513)
+#define IDI_HAND           WINELIB_NAME_AW(IDI_HAND)
+#define IDI_QUESTIONA    MAKEINTRESOURCEA(32514)
+#define IDI_QUESTIONW    MAKEINTRESOURCEW(32514)
+#define IDI_QUESTION       WINELIB_NAME_AW(IDI_QUESTION)
+#define IDI_EXCLAMATIONA MAKEINTRESOURCEA(32515)
+#define IDI_EXCLAMATIONW MAKEINTRESOURCEW(32515)
+#define IDI_EXCLAMATION    WINELIB_NAME_AW(IDI_EXCLAMATION)
+#define IDI_ASTERISKA    MAKEINTRESOURCEA(32516)
+#define IDI_ASTERISKW    MAKEINTRESOURCEW(32516)
+#define IDI_ASTERISK       WINELIB_NAME_AW(IDI_ASTERISK)
+
+#define IDC_BUMMERA      MAKEINTRESOURCEA(100)
+#define IDC_BUMMERW      MAKEINTRESOURCEW(100)
+#define IDC_BUMMER         WINELIB_NAME_AW(IDC_BUMMER)
+#define IDC_ARROWA       MAKEINTRESOURCEA(32512)
+#define IDC_ARROWW       MAKEINTRESOURCEW(32512)
+#define IDC_ARROW          WINELIB_NAME_AW(IDC_ARROW)
+#define IDC_IBEAMA       MAKEINTRESOURCEA(32513)
+#define IDC_IBEAMW       MAKEINTRESOURCEW(32513)
+#define IDC_IBEAM          WINELIB_NAME_AW(IDC_IBEAM)
+#define IDC_WAITA        MAKEINTRESOURCEA(32514)
+#define IDC_WAITW        MAKEINTRESOURCEW(32514)
+#define IDC_WAIT           WINELIB_NAME_AW(IDC_WAIT)
+#define IDC_CROSSA       MAKEINTRESOURCEA(32515)
+#define IDC_CROSSW       MAKEINTRESOURCEW(32515)
+#define IDC_CROSS          WINELIB_NAME_AW(IDC_CROSS)
+#define IDC_UPARROWA     MAKEINTRESOURCEA(32516)
+#define IDC_UPARROWW     MAKEINTRESOURCEW(32516)
+#define IDC_UPARROW        WINELIB_NAME_AW(IDC_UPARROW)
+#define IDC_SIZEA        MAKEINTRESOURCEA(32640)
+#define IDC_SIZEW        MAKEINTRESOURCEW(32640)
+#define IDC_SIZE           WINELIB_NAME_AW(IDC_SIZE)
+#define IDC_ICONA        MAKEINTRESOURCEA(32641)
+#define IDC_ICONW        MAKEINTRESOURCEW(32641)
+#define IDC_ICON           WINELIB_NAME_AW(IDC_ICON)
+#define IDC_SIZENWSEA    MAKEINTRESOURCEA(32642)
+#define IDC_SIZENWSEW    MAKEINTRESOURCEW(32642)
+#define IDC_SIZENWSE       WINELIB_NAME_AW(IDC_SIZENWSE)
+#define IDC_SIZENESWA    MAKEINTRESOURCEA(32643)
+#define IDC_SIZENESWW    MAKEINTRESOURCEW(32643)
+#define IDC_SIZENESW       WINELIB_NAME_AW(IDC_SIZENESW)
+#define IDC_SIZEWEA      MAKEINTRESOURCEA(32644)
+#define IDC_SIZEWEW      MAKEINTRESOURCEW(32644)
+#define IDC_SIZEWE         WINELIB_NAME_AW(IDC_SIZEWE)
+#define IDC_SIZENSA      MAKEINTRESOURCEA(32645)
+#define IDC_SIZENSW      MAKEINTRESOURCEW(32645)
+#define IDC_SIZENS         WINELIB_NAME_AW(IDC_SIZENS)
+#define IDC_SIZEALLA     MAKEINTRESOURCEA(32646)
+#define IDC_SIZEALLW     MAKEINTRESOURCEW(32646)
+#define IDC_SIZEALL        WINELIB_NAME_AW(IDC_SIZEALL)
+#define IDC_NOA          MAKEINTRESOURCEA(32648)
+#define IDC_NOW          MAKEINTRESOURCEW(32648)
+#define IDC_NO             WINELIB_NAME_AW(IDC_NO)
+#define IDC_APPSTARTINGA MAKEINTRESOURCEA(32650)
+#define IDC_APPSTARTINGW MAKEINTRESOURCEW(32650)
+#define IDC_APPSTARTING    WINELIB_NAME_AW(IDC_APPSTARTING)
+#define IDC_HELPA        MAKEINTRESOURCEA(32651)
+#define IDC_HELPW        MAKEINTRESOURCEW(32651)
+#define IDC_HELP           WINELIB_NAME_AW(IDC_HELP)
+
+#define MNC_IGNORE 0
+#define MNC_CLOSE 1
+#define MNC_EXECUTE 2
+#define MNC_SELECT 3 
+
+/* SystemParametersInfo */
+/* defines below are for all win versions */
+#define SPI_GETBEEP               1
+#define SPI_SETBEEP               2
+#define SPI_GETMOUSE              3
+#define SPI_SETMOUSE              4
+#define SPI_GETBORDER             5
+#define SPI_SETBORDER             6
+#define SPI_GETKEYBOARDSPEED      10
+#define SPI_SETKEYBOARDSPEED      11
+#define SPI_LANGDRIVER            12
+#define SPI_ICONHORIZONTALSPACING 13
+#define SPI_GETSCREENSAVETIMEOUT  14
+#define SPI_SETSCREENSAVETIMEOUT  15
+#define SPI_GETSCREENSAVEACTIVE   16
+#define SPI_SETSCREENSAVEACTIVE   17
+#define SPI_GETGRIDGRANULARITY    18
+#define SPI_SETGRIDGRANULARITY    19
+#define SPI_SETDESKWALLPAPER      20
+#define SPI_SETDESKPATTERN        21
+#define SPI_GETKEYBOARDDELAY      22
+#define SPI_SETKEYBOARDDELAY      23
+#define SPI_ICONVERTICALSPACING   24
+#define SPI_GETICONTITLEWRAP      25
+#define SPI_SETICONTITLEWRAP      26
+#define SPI_GETMENUDROPALIGNMENT  27
+#define SPI_SETMENUDROPALIGNMENT  28
+#define SPI_SETDOUBLECLKWIDTH     29
+#define SPI_SETDOUBLECLKHEIGHT    30
+#define SPI_GETICONTITLELOGFONT   31
+#define SPI_SETDOUBLECLICKTIME    32
+#define SPI_SETMOUSEBUTTONSWAP    33
+#define SPI_SETICONTITLELOGFONT   34
+#define SPI_GETFASTTASKSWITCH     35
+#define SPI_SETFASTTASKSWITCH     36
+#define SPI_SETDRAGFULLWINDOWS    37
+#define SPI_GETDRAGFULLWINDOWS	  38
+
+#define SPI_GETFILTERKEYS         50
+#define SPI_SETFILTERKEYS         51
+#define SPI_GETTOGGLEKEYS         52
+#define SPI_SETTOGGLEKEYS         53
+#define SPI_GETMOUSEKEYS          54
+#define SPI_SETMOUSEKEYS          55
+#define SPI_GETSHOWSOUNDS         56
+#define SPI_SETSHOWSOUNDS         57
+#define SPI_GETSTICKYKEYS         58
+#define SPI_SETSTICKYKEYS         59
+#define SPI_GETACCESSTIMEOUT      60
+#define SPI_SETACCESSTIMEOUT      61
+
+#define SPI_GETSOUNDSENTRY        64
+#define SPI_SETSOUNDSENTRY        65
+
+/* defines below are for all win versions WINVER >= 0x0400 */
+#define SPI_SETDRAGFULLWINDOWS    37
+#define SPI_GETDRAGFULLWINDOWS    38
+#define SPI_GETNONCLIENTMETRICS   41
+#define SPI_SETNONCLIENTMETRICS   42
+#define SPI_GETMINIMIZEDMETRICS   43
+#define SPI_SETMINIMIZEDMETRICS   44
+#define SPI_GETICONMETRICS        45
+#define SPI_SETICONMETRICS        46
+#define SPI_SETWORKAREA           47
+#define SPI_GETWORKAREA           48
+#define SPI_SETPENWINDOWS         49
+
+#define SPI_GETSERIALKEYS         62
+#define SPI_SETSERIALKEYS         63
+#define SPI_GETHIGHCONTRAST       66
+#define SPI_SETHIGHCONTRAST       67
+#define SPI_GETKEYBOARDPREF       68
+#define SPI_SETKEYBOARDPREF       69
+#define SPI_GETSCREENREADER       70
+#define SPI_SETSCREENREADER       71
+#define SPI_GETANIMATION          72
+#define SPI_SETANIMATION          73
+#define SPI_GETFONTSMOOTHING      74
+#define SPI_SETFONTSMOOTHING      75
+#define SPI_SETDRAGWIDTH          76
+#define SPI_SETDRAGHEIGHT         77
+#define SPI_SETHANDHELD           78
+#define SPI_GETLOWPOWERTIMEOUT    79
+#define SPI_GETPOWEROFFTIMEOUT    80
+#define SPI_SETLOWPOWERTIMEOUT    81
+#define SPI_SETPOWEROFFTIMEOUT    82
+#define SPI_GETLOWPOWERACTIVE     83
+#define SPI_GETPOWEROFFACTIVE     84
+#define SPI_SETLOWPOWERACTIVE     85
+#define SPI_SETPOWEROFFACTIVE     86
+#define SPI_SETCURSORS            87
+#define SPI_SETICONS              88
+#define SPI_GETDEFAULTINPUTLANG   89
+#define SPI_SETDEFAULTINPUTLANG   90
+#define SPI_SETLANGTOGGLE         91
+#define SPI_GETWINDOWSEXTENSION   92
+#define SPI_SETMOUSETRAILS        93
+#define SPI_GETMOUSETRAILS        94
+#define SPI_SETSCREENSAVERRUNNING 97
+#define SPI_SCREENSAVERRUNNING    SPI_SETSCREENSAVERRUNNING
+
+/* defines below are for all win versions (_WIN32_WINNT >= 0x0400) ||
+ *                                        (_WIN32_WINDOWS > 0x0400) */
+#define SPI_GETMOUSEHOVERWIDTH    98
+#define SPI_SETMOUSEHOVERWIDTH    99
+#define SPI_GETMOUSEHOVERHEIGHT   100
+#define SPI_SETMOUSEHOVERHEIGHT   101
+#define SPI_GETMOUSEHOVERTIME     102
+#define SPI_SETMOUSEHOVERTIME     103
+#define SPI_GETWHEELSCROLLLINES   104
+#define SPI_SETWHEELSCROLLLINES   105
+
+#define SPI_GETSHOWIMEUI          110
+#define SPI_SETSHOWIMEUI          111
+
+/* defines below are for all win versions WINVER >= 0x0500 */
+#define SPI_GETMOUSESPEED         112
+#define SPI_SETMOUSESPEED         113
+#define SPI_GETSCREENSAVERRUNNING 114
+
+#define SPI_GETACTIVEWINDOWTRACKING    0x1000
+#define SPI_SETACTIVEWINDOWTRACKING    0x1001
+#define SPI_GETMENUANIMATION           0x1002
+#define SPI_SETMENUANIMATION           0x1003
+#define SPI_GETCOMBOBOXANIMATION       0x1004
+#define SPI_SETCOMBOBOXANIMATION       0x1005
+#define SPI_GETLISTBOXSMOOTHSCROLLING  0x1006
+#define SPI_SETLISTBOXSMOOTHSCROLLING  0x1007
+#define SPI_GETGRADIENTCAPTIONS        0x1008
+#define SPI_SETGRADIENTCAPTIONS        0x1009
+#define SPI_GETMENUUNDERLINES          0x100A
+#define SPI_SETMENUUNDERLINES          0x100B
+#define SPI_GETACTIVEWNDTRKZORDER      0x100C
+#define SPI_SETACTIVEWNDTRKZORDER      0x100D
+#define SPI_GETHOTTRACKING             0x100E
+#define SPI_SETHOTTRACKING             0x100F
+#define SPI_GETFOREGROUNDLOCKTIMEOUT   0x2000
+#define SPI_SETFOREGROUNDLOCKTIMEOUT   0x2001
+#define SPI_GETACTIVEWNDTRKTIMEOUT     0x2002
+#define SPI_SETACTIVEWNDTRKTIMEOUT     0x2003
+#define SPI_GETFOREGROUNDFLASHCOUNT    0x2004
+#define SPI_SETFOREGROUNDFLASHCOUNT    0x2005
+
+/* SystemParametersInfo flags */
+
+#define SPIF_UPDATEINIFILE              1
+#define SPIF_SENDWININICHANGE           2
+#define SPIF_SENDCHANGE                 SPIF_SENDWININICHANGE
+
+
+
+
+/* Window Styles */
+#define WS_OVERLAPPED    0x00000000L
+#define WS_POPUP         0x80000000L
+#define WS_CHILD         0x40000000L
+#define WS_MINIMIZE      0x20000000L
+#define WS_VISIBLE       0x10000000L
+#define WS_DISABLED      0x08000000L
+#define WS_CLIPSIBLINGS  0x04000000L
+#define WS_CLIPCHILDREN  0x02000000L
+#define WS_MAXIMIZE      0x01000000L
+#define WS_CAPTION       0x00C00000L
+#define WS_BORDER        0x00800000L
+#define WS_DLGFRAME      0x00400000L
+#define WS_VSCROLL       0x00200000L
+#define WS_HSCROLL       0x00100000L
+#define WS_SYSMENU       0x00080000L
+#define WS_THICKFRAME    0x00040000L
+#define WS_GROUP         0x00020000L
+#define WS_TABSTOP       0x00010000L
+#define WS_MINIMIZEBOX   0x00020000L
+#define WS_MAXIMIZEBOX   0x00010000L
+#define WS_TILED         WS_OVERLAPPED
+#define WS_ICONIC        WS_MINIMIZE
+#define WS_SIZEBOX       WS_THICKFRAME
+#define WS_OVERLAPPEDWINDOW (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME| WS_MINIMIZEBOX | WS_MAXIMIZEBOX)
+#define WS_POPUPWINDOW (WS_POPUP | WS_BORDER | WS_SYSMENU)
+#define WS_CHILDWINDOW (WS_CHILD)
+#define WS_TILEDWINDOW (WS_OVERLAPPEDWINDOW)
+
+/* Window extended styles */
+#define WS_EX_DLGMODALFRAME    0x00000001L
+#define WS_EX_DRAGDETECT       0x00000002L
+#define WS_EX_NOPARENTNOTIFY   0x00000004L
+#define WS_EX_TOPMOST          0x00000008L
+#define WS_EX_ACCEPTFILES      0x00000010L
+#define WS_EX_TRANSPARENT      0x00000020L
+
+/* New Win95/WinNT4 styles */
+#define WS_EX_MDICHILD         0x00000040L
+#define WS_EX_TOOLWINDOW       0x00000080L
+#define WS_EX_WINDOWEDGE       0x00000100L
+#define WS_EX_CLIENTEDGE       0x00000200L
+#define WS_EX_CONTEXTHELP      0x00000400L
+#define WS_EX_RIGHT            0x00001000L
+#define WS_EX_LEFT             0x00000000L
+#define WS_EX_RTLREADING       0x00002000L
+#define WS_EX_LTRREADING       0x00000000L
+#define WS_EX_LEFTSCROLLBAR    0x00004000L
+#define WS_EX_RIGHTSCROLLBAR   0x00000000L
+#define WS_EX_CONTROLPARENT    0x00010000L
+#define WS_EX_STATICEDGE       0x00020000L
+#define WS_EX_APPWINDOW        0x00040000L
+
+#define WS_EX_OVERLAPPEDWINDOW (WS_EX_WINDOWEDGE|WS_EX_CLIENTEDGE)
+#define WS_EX_PALETTEWINDOW    (WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW|WS_EX_TOPMOST)
+
+/* WINE internal... */
+#define WS_EX_TRAYWINDOW	0x80000000L
+
+/* Window scrolling */
+#define SW_SCROLLCHILDREN      0x0001
+#define SW_INVALIDATE          0x0002
+#define SW_ERASE               0x0004
+
+/* CreateWindow() coordinates */
+#define CW_USEDEFAULT ((INT)0x80000000)
+
+/* ChildWindowFromPointEx Flags */
+#define CWP_ALL                0x0000
+#define CWP_SKIPINVISIBLE      0x0001
+#define CWP_SKIPDISABLED       0x0002
+#define CWP_SKIPTRANSPARENT    0x0004
+
+  /* PeekMessage() options */
+#define PM_NOREMOVE	0x0000
+#define PM_REMOVE	0x0001
+#define PM_NOYIELD	0x0002
+
+/* WM_SHOWWINDOW wParam codes */
+#define SW_PARENTCLOSING    1
+#define SW_OTHERMAXIMIZED   2
+#define SW_PARENTOPENING    3
+#define SW_OTHERRESTORED    4
+
+  /* ShowWindow() codes */
+#define SW_HIDE             0
+#define SW_SHOWNORMAL       1
+#define SW_NORMAL           1
+#define SW_SHOWMINIMIZED    2
+#define SW_SHOWMAXIMIZED    3
+#define SW_MAXIMIZE         3
+#define SW_SHOWNOACTIVATE   4
+#define SW_SHOW             5
+#define SW_MINIMIZE         6
+#define SW_SHOWMINNOACTIVE  7
+#define SW_SHOWNA           8
+#define SW_RESTORE          9
+#define SW_SHOWDEFAULT	    10
+#define SW_MAX		    10
+#define SW_NORMALNA	    0xCC	/* undoc. flag in MinMaximize */
+
+  /* WM_SIZE message wParam values */
+#define SIZE_RESTORED        0
+#define SIZE_MINIMIZED       1
+#define SIZE_MAXIMIZED       2
+#define SIZE_MAXSHOW         3
+#define SIZE_MAXHIDE         4
+#define SIZENORMAL           SIZE_RESTORED
+#define SIZEICONIC           SIZE_MINIMIZED
+#define SIZEFULLSCREEN       SIZE_MAXIMIZED
+#define SIZEZOOMSHOW         SIZE_MAXSHOW
+#define SIZEZOOMHIDE         SIZE_MAXHIDE
+
+/* SetWindowPos() and WINDOWPOS flags */
+#define SWP_NOSIZE          0x0001
+#define SWP_NOMOVE          0x0002
+#define SWP_NOZORDER        0x0004
+#define SWP_NOREDRAW        0x0008
+#define SWP_NOACTIVATE      0x0010
+#define SWP_FRAMECHANGED    0x0020  /* The frame changed: send WM_NCCALCSIZE */
+#define SWP_SHOWWINDOW      0x0040
+#define SWP_HIDEWINDOW      0x0080
+#define SWP_NOCOPYBITS      0x0100
+#define SWP_NOOWNERZORDER   0x0200  /* Don't do owner Z ordering */
+
+#define SWP_DRAWFRAME       SWP_FRAMECHANGED
+#define SWP_NOREPOSITION    SWP_NOOWNERZORDER
+
+#define SWP_NOSENDCHANGING  0x0400
+#define SWP_DEFERERASE      0x2000
+#define SWP_ASYNCWINDOWPOS  0x4000
+
+#define HWND_DESKTOP        ((HWND)0)
+#define HWND_BROADCAST      ((HWND)0xffff)
+
+/* SetWindowPos() hwndInsertAfter field values */
+#define HWND_TOP            ((HWND)0)
+#define HWND_BOTTOM         ((HWND)1)
+#define HWND_TOPMOST        ((HWND)-1)
+#define HWND_NOTOPMOST      ((HWND)-2)
+
+#define MF_INSERT          0x0000
+#define MF_CHANGE          0x0080
+#define MF_APPEND          0x0100
+#define MF_DELETE          0x0200
+#define MF_REMOVE          0x1000
+#define MF_END             0x0080
+
+#define MF_ENABLED         0x0000
+#define MF_GRAYED          0x0001
+#define MF_DISABLED        0x0002
+#define MF_STRING          0x0000
+#define MF_BITMAP          0x0004
+#define MF_UNCHECKED       0x0000
+#define MF_CHECKED         0x0008
+#define MF_POPUP           0x0010
+#define MF_MENUBARBREAK    0x0020
+#define MF_MENUBREAK       0x0040
+#define MF_UNHILITE        0x0000
+#define MF_HILITE          0x0080
+#define MF_OWNERDRAW       0x0100
+#define MF_USECHECKBITMAPS 0x0200
+#define MF_BYCOMMAND       0x0000
+#define MF_BYPOSITION      0x0400
+#define MF_SEPARATOR       0x0800
+#define MF_DEFAULT         0x1000
+#define MF_SYSMENU         0x2000
+#define MF_HELP            0x4000
+#define MF_RIGHTJUSTIFY    0x4000
+#define MF_MOUSESELECT     0x8000
+
+/* Flags for extended menu item types.  */
+#define MFT_STRING         MF_STRING
+#define MFT_BITMAP         MF_BITMAP
+#define MFT_MENUBARBREAK   MF_MENUBARBREAK
+#define MFT_MENUBREAK      MF_MENUBREAK
+#define MFT_OWNERDRAW      MF_OWNERDRAW
+#define MFT_RADIOCHECK     0x00000200L
+#define MFT_SEPARATOR      MF_SEPARATOR
+#define MFT_RIGHTORDER     0x00002000L
+#define MFT_RIGHTJUSTIFY   MF_RIGHTJUSTIFY
+
+/* Flags for extended menu item states.  */
+#define MFS_GRAYED          0x00000003L
+#define MFS_DISABLED        MFS_GRAYED
+#define MFS_CHECKED         MF_CHECKED
+#define MFS_HILITE          MF_HILITE
+#define MFS_ENABLED         MF_ENABLED
+#define MFS_UNCHECKED       MF_UNCHECKED
+#define MFS_UNHILITE        MF_UNHILITE
+#define MFS_DEFAULT         MF_DEFAULT
+#define MFS_MASK            0x0000108BL
+#define MFS_HOTTRACKDRAWN   0x10000000L
+#define MFS_CACHEDBMP       0x20000000L
+#define MFS_BOTTOMGAPDROP   0x40000000L
+#define MFS_TOPGAPDROP      0x80000000L
+#define MFS_GAPDROP         0xC0000000L
+
+/* for GetMenuDefaultItem */
+#define GMDI_USEDISABLED    0x0001L
+#define GMDI_GOINTOPOPUPS   0x0002L
+
+#define DT_TOP 0
+#define DT_LEFT 0
+#define DT_CENTER 1
+#define DT_RIGHT 2
+#define DT_VCENTER 4
+#define DT_BOTTOM 8
+#define DT_WORDBREAK 16
+#define DT_SINGLELINE 32
+#define DT_EXPANDTABS 64
+#define DT_TABSTOP 128
+#define DT_NOCLIP 256
+#define DT_EXTERNALLEADING 512
+#define DT_CALCRECT 1024
+#define DT_NOPREFIX 2048
+#define DT_INTERNAL 4096
+
+/* DrawCaption()/DrawCaptionTemp() flags */
+#define DC_ACTIVE		0x0001
+#define DC_SMALLCAP		0x0002
+#define DC_ICON			0x0004
+#define DC_TEXT			0x0008
+#define DC_INBUTTON		0x0010
+
+/* DrawEdge() flags */
+#define BDR_RAISEDOUTER    0x0001
+#define BDR_SUNKENOUTER    0x0002
+#define BDR_RAISEDINNER    0x0004
+#define BDR_SUNKENINNER    0x0008
+
+#define BDR_OUTER          0x0003
+#define BDR_INNER          0x000c
+#define BDR_RAISED         0x0005
+#define BDR_SUNKEN         0x000a
+
+#define EDGE_RAISED        (BDR_RAISEDOUTER | BDR_RAISEDINNER)
+#define EDGE_SUNKEN        (BDR_SUNKENOUTER | BDR_SUNKENINNER)
+#define EDGE_ETCHED        (BDR_SUNKENOUTER | BDR_RAISEDINNER)
+#define EDGE_BUMP          (BDR_RAISEDOUTER | BDR_SUNKENINNER)
+
+/* border flags */
+#define BF_LEFT            0x0001
+#define BF_TOP             0x0002
+#define BF_RIGHT           0x0004
+#define BF_BOTTOM          0x0008
+#define BF_DIAGONAL        0x0010
+#define BF_MIDDLE          0x0800  /* Fill in the middle */
+#define BF_SOFT            0x1000  /* For softer buttons */
+#define BF_ADJUST          0x2000  /* Calculate the space left over */
+#define BF_FLAT            0x4000  /* For flat rather than 3D borders */
+#define BF_MONO            0x8000  /* For monochrome borders */
+#define BF_TOPLEFT         (BF_TOP | BF_LEFT)
+#define BF_TOPRIGHT        (BF_TOP | BF_RIGHT)
+#define BF_BOTTOMLEFT      (BF_BOTTOM | BF_LEFT)
+#define BF_BOTTOMRIGHT     (BF_BOTTOM | BF_RIGHT)
+#define BF_RECT            (BF_LEFT | BF_TOP | BF_RIGHT | BF_BOTTOM)
+#define BF_DIAGONAL_ENDTOPRIGHT     (BF_DIAGONAL | BF_TOP | BF_RIGHT)
+#define BF_DIAGONAL_ENDTOPLEFT      (BF_DIAGONAL | BF_TOP | BF_LEFT)
+#define BF_DIAGONAL_ENDBOTTOMLEFT   (BF_DIAGONAL | BF_BOTTOM | BF_LEFT)
+#define BF_DIAGONAL_ENDBOTTOMRIGHT  (BF_DIAGONAL | BF_BOTTOM | BF_RIGHT)
+
+/* DrawFrameControl() uType's */
+
+#define DFC_CAPTION             1
+#define DFC_MENU                2
+#define DFC_SCROLL              3
+#define DFC_BUTTON              4
+
+/* uState's */
+
+#define DFCS_CAPTIONCLOSE       0x0000
+#define DFCS_CAPTIONMIN         0x0001
+#define DFCS_CAPTIONMAX         0x0002
+#define DFCS_CAPTIONRESTORE     0x0003
+#define DFCS_CAPTIONHELP        0x0004		/* Windows 95 only */
+
+#define DFCS_MENUARROW          0x0000
+#define DFCS_MENUCHECK          0x0001
+#define DFCS_MENUBULLET         0x0002
+#define DFCS_MENUARROWRIGHT     0x0004
+
+#define DFCS_SCROLLUP            0x0000
+#define DFCS_SCROLLDOWN          0x0001
+#define DFCS_SCROLLLEFT          0x0002
+#define DFCS_SCROLLRIGHT         0x0003
+#define DFCS_SCROLLCOMBOBOX      0x0005
+#define DFCS_SCROLLSIZEGRIP      0x0008
+#define DFCS_SCROLLSIZEGRIPRIGHT 0x0010
+
+#define DFCS_BUTTONCHECK        0x0000
+#define DFCS_BUTTONRADIOIMAGE   0x0001
+#define DFCS_BUTTONRADIOMASK    0x0002		/* to draw nonsquare button */
+#define DFCS_BUTTONRADIO        0x0004
+#define DFCS_BUTTON3STATE       0x0008
+#define DFCS_BUTTONPUSH         0x0010
+
+/* additional state of the control */
+
+#define DFCS_INACTIVE           0x0100
+#define DFCS_PUSHED             0x0200
+#define DFCS_CHECKED            0x0400
+#define DFCS_ADJUSTRECT         0x2000		/* exclude surrounding edge */
+#define DFCS_FLAT               0x4000
+#define DFCS_MONO               0x8000
+
+/* Image type */
+#define	DST_COMPLEX	0x0000
+#define	DST_TEXT	0x0001
+#define	DST_PREFIXTEXT	0x0002
+#define	DST_ICON	0x0003
+#define	DST_BITMAP	0x0004
+
+/* State type */
+#define	DSS_NORMAL	0x0000
+#define	DSS_UNION	0x0010  /* Gray string appearance */
+#define	DSS_DISABLED	0x0020
+#define	DSS_DEFAULT	0x0040  /* Make it bold */
+#define	DSS_MONO	0x0080
+#define	DSS_RIGHT	0x8000
+
+typedef struct
+{
+    UINT      CtlType;
+    UINT      CtlID;
+    UINT      itemID;
+    UINT      itemAction;
+    UINT      itemState;
+    HWND      hwndItem;
+    HDC       hDC;
+    RECT      rcItem WINE_PACKED;
+    DWORD       itemData WINE_PACKED;
+} DRAWITEMSTRUCT, *PDRAWITEMSTRUCT, *LPDRAWITEMSTRUCT;
+
+
+typedef struct
+{
+    UINT      CtlType;
+    UINT      CtlID;
+    UINT      itemID;
+    UINT      itemWidth;
+    UINT      itemHeight;
+    DWORD       itemData;
+} MEASUREITEMSTRUCT, *PMEASUREITEMSTRUCT, *LPMEASUREITEMSTRUCT;
+
+
+typedef struct
+{
+    UINT     CtlType;
+    UINT     CtlID;
+    UINT     itemID;
+    HWND     hwndItem;
+    DWORD      itemData;
+} DELETEITEMSTRUCT, *LPDELETEITEMSTRUCT;
+
+
+typedef struct
+{
+    UINT      CtlType;
+    UINT      CtlID;
+    HWND      hwndItem;
+    UINT      itemID1;
+    DWORD       itemData1;
+    UINT      itemID2;
+    DWORD       itemData2;
+    DWORD       dwLocaleId;
+} COMPAREITEMSTRUCT, *PCOMPAREITEMSTRUCT, *LPCOMPAREITEMSTRUCT;
+
+
+/* WM_KEYUP/DOWN/CHAR HIWORD(lParam) flags */
+#define KF_EXTENDED         0x0100
+#define KF_DLGMODE          0x0800
+#define KF_MENUMODE         0x1000
+#define KF_ALTDOWN          0x2000
+#define KF_REPEAT           0x4000
+#define KF_UP               0x8000
+
+/* Virtual key codes */
+#define VK_LBUTTON          0x01
+#define VK_RBUTTON          0x02
+#define VK_CANCEL           0x03
+#define VK_MBUTTON          0x04
+/*                          0x05-0x07  Undefined */
+#define VK_BACK             0x08
+#define VK_TAB              0x09
+/*                          0x0A-0x0B  Undefined */
+#define VK_CLEAR            0x0C
+#define VK_RETURN           0x0D
+/*                          0x0E-0x0F  Undefined */
+#define VK_SHIFT            0x10
+#define VK_CONTROL          0x11
+#define VK_MENU             0x12
+#define VK_PAUSE            0x13
+#define VK_CAPITAL          0x14
+/*                          0x15-0x19  Reserved for Kanji systems */
+/*                          0x1A       Undefined */
+#define VK_ESCAPE           0x1B
+/*                          0x1C-0x1F  Reserved for Kanji systems */
+#define VK_SPACE            0x20
+#define VK_PRIOR            0x21
+#define VK_NEXT             0x22
+#define VK_END              0x23
+#define VK_HOME             0x24
+#define VK_LEFT             0x25
+#define VK_UP               0x26
+#define VK_RIGHT            0x27
+#define VK_DOWN             0x28
+#define VK_SELECT           0x29
+#define VK_PRINT            0x2A /* OEM specific in Windows 3.1 SDK */
+#define VK_EXECUTE          0x2B
+#define VK_SNAPSHOT         0x2C
+#define VK_INSERT           0x2D
+#define VK_DELETE           0x2E
+#define VK_HELP             0x2F
+#define VK_0                0x30
+#define VK_1                0x31
+#define VK_2                0x32
+#define VK_3                0x33
+#define VK_4                0x34
+#define VK_5                0x35
+#define VK_6                0x36
+#define VK_7                0x37
+#define VK_8                0x38
+#define VK_9                0x39
+/*                          0x3A-0x40  Undefined */
+#define VK_A                0x41
+#define VK_B                0x42
+#define VK_C                0x43
+#define VK_D                0x44
+#define VK_E                0x45
+#define VK_F                0x46
+#define VK_G                0x47
+#define VK_H                0x48
+#define VK_I                0x49
+#define VK_J                0x4A
+#define VK_K                0x4B
+#define VK_L                0x4C
+#define VK_M                0x4D
+#define VK_N                0x4E
+#define VK_O                0x4F
+#define VK_P                0x50
+#define VK_Q                0x51
+#define VK_R                0x52
+#define VK_S                0x53
+#define VK_T                0x54
+#define VK_U                0x55
+#define VK_V                0x56
+#define VK_W                0x57
+#define VK_X                0x58
+#define VK_Y                0x59
+#define VK_Z                0x5A
+
+#define VK_LWIN             0x5B
+#define VK_RWIN             0x5C
+#define VK_APPS             0x5D
+/*                          0x5E-0x5F Unassigned */
+#define VK_NUMPAD0          0x60
+#define VK_NUMPAD1          0x61
+#define VK_NUMPAD2          0x62
+#define VK_NUMPAD3          0x63
+#define VK_NUMPAD4          0x64
+#define VK_NUMPAD5          0x65
+#define VK_NUMPAD6          0x66
+#define VK_NUMPAD7          0x67
+#define VK_NUMPAD8          0x68
+#define VK_NUMPAD9          0x69
+#define VK_MULTIPLY         0x6A
+#define VK_ADD              0x6B
+#define VK_SEPARATOR        0x6C
+#define VK_SUBTRACT         0x6D
+#define VK_DECIMAL          0x6E
+#define VK_DIVIDE           0x6F
+#define VK_F1               0x70
+#define VK_F2               0x71
+#define VK_F3               0x72
+#define VK_F4               0x73
+#define VK_F5               0x74
+#define VK_F6               0x75
+#define VK_F7               0x76
+#define VK_F8               0x77
+#define VK_F9               0x78
+#define VK_F10              0x79
+#define VK_F11              0x7A
+#define VK_F12              0x7B
+#define VK_F13              0x7C
+#define VK_F14              0x7D
+#define VK_F15              0x7E
+#define VK_F16              0x7F
+#define VK_F17              0x80
+#define VK_F18              0x81
+#define VK_F19              0x82
+#define VK_F20              0x83
+#define VK_F21              0x84
+#define VK_F22              0x85
+#define VK_F23              0x86
+#define VK_F24              0x87
+/*                          0x88-0x8F  Unassigned */
+#define VK_NUMLOCK          0x90
+#define VK_SCROLL           0x91
+/*                          0x92-0x9F  Unassigned */
+/*
+ * differencing between right and left shift/control/alt key.
+ * Used only by GetAsyncKeyState() and GetKeyState().
+ */
+#define VK_LSHIFT           0xA0
+#define VK_RSHIFT           0xA1
+#define VK_LCONTROL         0xA2
+#define VK_RCONTROL         0xA3
+#define VK_LMENU            0xA4
+#define VK_RMENU            0xA5
+/*                          0xA6-0xB9  Unassigned */
+#define VK_OEM_1            0xBA
+#define VK_OEM_PLUS         0xBB
+#define VK_OEM_COMMA        0xBC
+#define VK_OEM_MINUS        0xBD
+#define VK_OEM_PERIOD       0xBE
+#define VK_OEM_2            0xBF
+#define VK_OEM_3            0xC0
+/*                          0xC1-0xDA  Unassigned */
+#define VK_OEM_4            0xDB
+#define VK_OEM_5            0xDC
+#define VK_OEM_6            0xDD
+#define VK_OEM_7            0xDE
+/*                          0xDF-0xE4  OEM specific */
+
+#define VK_PROCESSKEY       0xE5
+
+/*                          0xE6       OEM specific */
+/*                          0xE7-0xE8  Unassigned */
+/*                          0xE9-0xF5  OEM specific */
+
+#define VK_ATTN             0xF6
+#define VK_CRSEL            0xF7
+#define VK_EXSEL            0xF8
+#define VK_EREOF            0xF9
+#define VK_PLAY             0xFA
+#define VK_ZOOM             0xFB
+#define VK_NONAME           0xFC
+#define VK_PA1              0xFD
+#define VK_OEM_CLEAR        0xFE
+  
+  /* Key status flags for mouse events */
+#define MK_LBUTTON	    0x0001
+#define MK_RBUTTON	    0x0002
+#define MK_SHIFT	    0x0004
+#define MK_CONTROL	    0x0008
+#define MK_MBUTTON	    0x0010
+
+  /* Queue status flags */
+#define QS_KEY		0x0001
+#define QS_MOUSEMOVE	0x0002
+#define QS_MOUSEBUTTON	0x0004
+#define QS_MOUSE	(QS_MOUSEMOVE | QS_MOUSEBUTTON)
+#define QS_POSTMESSAGE	0x0008
+#define QS_TIMER	0x0010
+#define QS_PAINT	0x0020
+#define QS_SENDMESSAGE	0x0040
+#define QS_HOTKEY	0x0080
+#define QS_INPUT	(QS_MOUSE | QS_KEY)
+#define QS_ALLEVENTS	(QS_INPUT | QS_POSTMESSAGE | QS_TIMER | QS_PAINT | QS_HOTKEY)
+#define QS_ALLINPUT     (QS_ALLEVENTS | QS_SENDMESSAGE)
+
+#define DDL_READWRITE	0x0000
+#define DDL_READONLY	0x0001
+#define DDL_HIDDEN	0x0002
+#define DDL_SYSTEM	0x0004
+#define DDL_DIRECTORY	0x0010
+#define DDL_ARCHIVE	0x0020
+
+#define DDL_POSTMSGS	0x2000
+#define DDL_DRIVES	0x4000
+#define DDL_EXCLUSIVE	0x8000
+
+  /* Shell hook values */
+#define HSHELL_WINDOWCREATED       1
+#define HSHELL_WINDOWDESTROYED     2
+#define HSHELL_ACTIVATESHELLWINDOW 3
+
+/* Predefined Clipboard Formats */
+#define CF_TEXT              1
+#define CF_BITMAP            2
+#define CF_METAFILEPICT      3
+#define CF_SYLK              4
+#define CF_DIF               5
+#define CF_TIFF              6
+#define CF_OEMTEXT           7
+#define CF_DIB               8
+#define CF_PALETTE           9
+#define CF_PENDATA          10
+#define CF_RIFF             11
+#define CF_WAVE             12
+#define CF_ENHMETAFILE      14
+#define CF_HDROP            15
+#define CF_LOCALE           16
+#define CF_MAX              17
+
+#define CF_OWNERDISPLAY     0x0080
+#define CF_DSPTEXT          0x0081
+#define CF_DSPBITMAP        0x0082
+#define CF_DSPMETAFILEPICT  0x0083
+
+/* "Private" formats don't get GlobalFree()'d */
+#define CF_PRIVATEFIRST     0x0200
+#define CF_PRIVATELAST      0x02FF
+
+/* "GDIOBJ" formats do get DeleteObject()'d */
+#define CF_GDIOBJFIRST      0x0300
+#define CF_GDIOBJLAST       0x03FF
+
+
+/* DragObject stuff */
+
+typedef struct
+{
+    HWND16     hWnd;
+    HANDLE16   hScope;
+    WORD       wFlags;
+    HANDLE16   hList;
+    HANDLE16   hOfStruct;
+    POINT16 pt WINE_PACKED;
+    LONG       l WINE_PACKED;
+} DRAGINFO, *LPDRAGINFO;
+
+#define DRAGOBJ_PROGRAM		0x0001
+#define DRAGOBJ_DATA		0x0002
+#define DRAGOBJ_DIRECTORY	0x0004
+#define DRAGOBJ_MULTIPLE	0x0008
+#define DRAGOBJ_EXTERNAL	0x8000
+
+#define DRAG_PRINT		0x544E5250
+#define DRAG_FILE		0x454C4946
+
+/* types of LoadImage */
+#define IMAGE_BITMAP	0
+#define IMAGE_ICON	1
+#define IMAGE_CURSOR	2
+#define IMAGE_ENHMETAFILE	3
+
+/* loadflags to LoadImage */
+#define LR_DEFAULTCOLOR		0x0000
+#define LR_MONOCHROME		0x0001
+#define LR_COLOR		0x0002
+#define LR_COPYRETURNORG	0x0004
+#define LR_COPYDELETEORG	0x0008
+#define LR_LOADFROMFILE		0x0010
+#define LR_LOADTRANSPARENT	0x0020
+#define LR_DEFAULTSIZE		0x0040
+#define LR_VGA_COLOR		0x0080
+#define LR_LOADMAP3DCOLORS	0x1000
+#define	LR_CREATEDIBSECTION	0x2000
+#define LR_COPYFROMRESOURCE	0x4000
+#define LR_SHARED		0x8000
+
+/* Flags for DrawIconEx.  */
+#define DI_MASK                 1
+#define DI_IMAGE                2
+#define DI_NORMAL               (DI_MASK | DI_IMAGE)
+#define DI_COMPAT               4
+#define DI_DEFAULTSIZE          8
+
+  /* misc messages */
+#define WM_CPL_LAUNCH       (WM_USER + 1000)
+#define WM_CPL_LAUNCHED     (WM_USER + 1001)
+
+/* WM_NOTIFYFORMAT commands and return values */
+#define NFR_ANSI	    1
+#define NFR_UNICODE	    2
+#define NF_QUERY	    3
+#define NF_REQUERY	    4
+
+#include "poppack.h"
+#define     EnumTaskWindows(handle,proc,lparam) \
+            EnumThreadWindows(handle,proc,lparam)
+#define     OemToAnsiA OemToCharA
+#define     OemToAnsiW OemToCharW
+#define     OemToAnsi WINELIB_NAME_AW(OemToAnsi)
+#define     OemToAnsiBuffA OemToCharBuffA
+#define     OemToAnsiBuffW OemToCharBuffW
+#define     OemToAnsiBuff WINELIB_NAME_AW(OemToAnsiBuff)
+#define     AnsiToOemA CharToOemA
+#define     AnsiToOemW CharToOemW
+#define     AnsiToOem WINELIB_NAME_AW(AnsiToOem)
+#define     AnsiToOemBuffA CharToOemBuffA
+#define     AnsiToOemBuffW CharToOemBuffW
+#define     AnsiToOemBuff WINELIB_NAME_AW(AnsiToOemBuff)
+/* NOTE: This is SYSTEM.3, not USER.182, which is also named KillSystemTimer */
+WORD        WINAPI SYSTEM_KillSystemTimer( WORD );
+
+/* Extra functions that don't exist in the Windows API */
+
+HPEN      WINAPI GetSysColorPen(INT);
+INT       WINAPI LoadMessageA(HMODULE,UINT,WORD,LPSTR,INT);
+INT       WINAPI LoadMessageW(HMODULE,UINT,WORD,LPWSTR,INT);
+
+VOID        WINAPI ScreenSwitchEnable16(WORD);
+
+#define WC_DIALOG    (LPSTR)((DWORD)((WORD)( 0x8002)))
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _WINUSER_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loader/wineacm.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,55 @@
+/* -*- tab-width: 8; c-basic-offset: 4 -*- */
+
+/***********************************************************************
+ * Wine specific - Win32
+ */
+typedef struct _WINE_ACMDRIVERID *PWINE_ACMDRIVERID;
+typedef struct _WINE_ACMDRIVER   *PWINE_ACMDRIVER;
+
+typedef struct _WINE_ACMOBJ
+{
+  PWINE_ACMDRIVERID	pACMDriverID;
+} WINE_ACMOBJ, *PWINE_ACMOBJ;
+
+typedef struct _WINE_ACMDRIVER
+{
+    WINE_ACMOBJ		obj;
+    HDRVR      		hDrvr;
+    DRIVERPROC		pfnDriverProc;
+    PWINE_ACMDRIVER	pNextACMDriver;
+} WINE_ACMDRIVER;
+
+typedef struct _WINE_ACMSTREAM
+{
+    WINE_ACMOBJ		obj;
+    PWINE_ACMDRIVER	pDrv;
+    ACMDRVSTREAMINSTANCE drvInst;
+    HACMDRIVER		hAcmDriver;
+} WINE_ACMSTREAM, *PWINE_ACMSTREAM;
+
+typedef struct _WINE_ACMDRIVERID
+{
+    LPSTR               pszDriverAlias;
+    LPSTR               pszFileName;
+    HINSTANCE		hInstModule;          /* NULL if global */
+    DWORD		dwProcessID;	      /* ID of process which installed a local driver */
+    WIN_BOOL                bEnabled;
+    PWINE_ACMDRIVER     pACMDriverList;
+    PWINE_ACMDRIVERID   pNextACMDriverID;
+    PWINE_ACMDRIVERID	pPrevACMDriverID;
+} WINE_ACMDRIVERID;
+
+/* From internal.c */
+extern HANDLE MSACM_hHeap;
+extern PWINE_ACMDRIVERID MSACM_pFirstACMDriverID;
+extern PWINE_ACMDRIVERID MSACM_pLastACMDriverID;
+PWINE_ACMDRIVERID MSACM_RegisterDriver(
+  LPSTR pszDriverAlias, LPSTR pszFileName,
+  HINSTANCE hinstModule);
+void MSACM_RegisterAllDrivers(void);
+PWINE_ACMDRIVERID MSACM_UnregisterDriver(PWINE_ACMDRIVERID p);
+void MSACM_UnregisterAllDrivers(void);
+PWINE_ACMDRIVERID MSACM_GetDriverID(HACMDRIVERID hDriverID);
+PWINE_ACMDRIVER MSACM_GetDriver(HACMDRIVER hDriver);
+PWINE_ACMOBJ MSACM_GetObj(HACMOBJ hObj);
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/Makefile	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,34 @@
+
+include config.mak
+
+SRCS = sr1.c d_cpu.s decode_i586.s $(OPTIONAL_SRCS)
+OBJS = sr1.o d_cpu.o decode_i586.o $(OPTIONAL_OBJS)
+CFLAGS  = $(OPTFLAGS)
+
+.SUFFIXES: .c .o
+
+# .PHONY: all clean
+
+.c.o:
+	$(CC) -c $(CFLAGS) -o $@ $<
+
+.s.o:
+	$(CC) -c $(CFLAGS) -o $@ $<
+
+libMP3.a:	$(OBJS)
+	$(AR) r libMP3.a $(OBJS)
+
+all:	libMP3.a
+
+clean:
+	rm -f *~ *.o *.a
+
+distclean:
+	makedepend
+	rm -f *~ *.o *.a Makefile.bak
+
+dep:	depend
+
+depend:
+	makedepend -- $(CFLAGS) -- $(SRCS) &>/dev/null
+# DO NOT DELETE
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/config.mak	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,6 @@
+
+include ../config.mak
+
+OPTIONAL_SRCS = 
+OPTIONAL_OBJS = 
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/d_cpu.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,17 @@
+
+// --------------------------------------------------------------------------
+//  Cpu function detect by Pontscho/fresh!mindworkz
+// --------------------------------------------------------------------------
+
+#ifndef __MY_CPUIDENT
+#define __MY_CPUIDENT
+
+unsigned int _CpuID;
+unsigned int _i586;
+unsigned int _3dnow;
+
+extern unsigned long CpuDetect( void );
+extern unsigned long ipentium( void );
+extern unsigned long a3dnow( void );
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/d_cpu.s	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,94 @@
+
+/ ---------------------------------------------------------------------------
+/  Cpu function detect by Pontscho/fresh!mindworkz
+/   (c) 2000 - 2000
+/ ---------------------------------------------------------------------------
+
+.text
+
+.globl CpuDetect
+.globl ipentium
+.globl a3dnow
+
+/ ---------------------------------------------------------------------------
+/  in C: unsigned long CpuDetect( void );
+/   return: cpu ident number.
+/ ---------------------------------------------------------------------------
+CpuDetect:
+        pushl %ebx
+        pushl %ecx
+        pushl %edx
+
+        movl  $1,%eax
+        cpuid
+
+        popl  %edx
+        popl  %ecx
+        popl  %ebx
+        ret
+
+/ ---------------------------------------------------------------------------
+/  in C: unsigled long ipentium( void );
+/   return: 0 if the processor is not P5 or above else above 1.
+/ ---------------------------------------------------------------------------
+ipentium:
+        pushl  %ebx
+        pushl  %ecx
+        pushl  %edx
+        pushfl
+        popl   %eax
+        movl   %eax,%ebx
+        xorl   $0x00200000,%eax
+        pushl  %eax
+        popfl
+        pushfl
+        popl   %eax
+        cmpl   %eax,%ebx
+        jz     no_cpuid
+        movl   $1,%eax
+        cpuid
+        shrl   $8,%eax
+        cmpl   $5,%eax
+        jb     no_cpuid
+        movl   $1,%eax
+        jmp    exit
+no_cpuid:
+        xorl   %eax,%eax
+exit:
+        popl   %edx
+        popl   %ecx
+        popl   %ebx
+        ret
+
+/ ---------------------------------------------------------------------------
+/  in C: unsigned long a3dnow( void );
+/   return: 0 if this processor not requiment 3dnow! else above 1.
+/ ---------------------------------------------------------------------------
+a3dnow:
+        pushl  %ebx
+        pushl  %edx
+        pushl  %ecx
+
+
+        call   ipentium
+        shrl   $1,%eax
+        jnc    no_3dnow
+
+        movl   $0x80000000,%eax
+        cpuid
+        cmpl   $0x80000000,%eax
+        jbe    no_3dnow
+        movl   $0x80000001,%eax
+        cpuid
+        testl  $0x80000000,%edx
+        jz     no_3dnow
+        movl   $1,%eax
+        jmp    exit2
+no_3dnow:
+        xorl   %eax,%eax
+exit2:
+
+        popl   %ecx
+        popl   %edx
+        popl   %ebx
+        ret
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/dct12.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,139 @@
+/*
+ * new DCT12
+ */
+static void dct12(real *in,real *rawout1,real *rawout2,register real *wi,register real *ts)
+{
+#define DCT12_PART1 \
+             in5 = in[5*3];  \
+     in5 += (in4 = in[4*3]); \
+     in4 += (in3 = in[3*3]); \
+     in3 += (in2 = in[2*3]); \
+     in2 += (in1 = in[1*3]); \
+     in1 += (in0 = in[0*3]); \
+                             \
+     in5 += in3; in3 += in1; \
+                             \
+     in2 *= COS6_1; \
+     in3 *= COS6_1; \
+
+#define DCT12_PART2 \
+     in0 += in4 * COS6_2; \
+                          \
+     in4 = in0 + in2;     \
+     in0 -= in2;          \
+                          \
+     in1 += in5 * COS6_2; \
+                          \
+     in5 = (in1 + in3) * tfcos12[0]; \
+     in1 = (in1 - in3) * tfcos12[2]; \
+                         \
+     in3 = in4 + in5;    \
+     in4 -= in5;         \
+                         \
+     in2 = in0 + in1;    \
+     in0 -= in1;
+
+
+   {
+     real in0,in1,in2,in3,in4,in5;
+     register real *out1 = rawout1;
+     ts[SBLIMIT*0] = out1[0]; ts[SBLIMIT*1] = out1[1]; ts[SBLIMIT*2] = out1[2];
+     ts[SBLIMIT*3] = out1[3]; ts[SBLIMIT*4] = out1[4]; ts[SBLIMIT*5] = out1[5];
+ 
+     DCT12_PART1
+
+     {
+       real tmp0,tmp1 = (in0 - in4);
+       {
+         real tmp2 = (in1 - in5) * tfcos12[1];
+         tmp0 = tmp1 + tmp2;
+         tmp1 -= tmp2;
+       }
+       ts[(17-1)*SBLIMIT] = out1[17-1] + tmp0 * wi[11-1];
+       ts[(12+1)*SBLIMIT] = out1[12+1] + tmp0 * wi[6+1];
+       ts[(6 +1)*SBLIMIT] = out1[6 +1] + tmp1 * wi[1];
+       ts[(11-1)*SBLIMIT] = out1[11-1] + tmp1 * wi[5-1];
+     }
+
+     DCT12_PART2
+
+     ts[(17-0)*SBLIMIT] = out1[17-0] + in2 * wi[11-0];
+     ts[(12+0)*SBLIMIT] = out1[12+0] + in2 * wi[6+0];
+     ts[(12+2)*SBLIMIT] = out1[12+2] + in3 * wi[6+2];
+     ts[(17-2)*SBLIMIT] = out1[17-2] + in3 * wi[11-2];
+
+     ts[(6+0)*SBLIMIT]  = out1[6+0] + in0 * wi[0];
+     ts[(11-0)*SBLIMIT] = out1[11-0] + in0 * wi[5-0];
+     ts[(6+2)*SBLIMIT]  = out1[6+2] + in4 * wi[2];
+     ts[(11-2)*SBLIMIT] = out1[11-2] + in4 * wi[5-2];
+  }
+
+  in++;
+
+  {
+     real in0,in1,in2,in3,in4,in5;
+     register real *out2 = rawout2;
+ 
+     DCT12_PART1
+
+     {
+       real tmp0,tmp1 = (in0 - in4);
+       {
+         real tmp2 = (in1 - in5) * tfcos12[1];
+         tmp0 = tmp1 + tmp2;
+         tmp1 -= tmp2;
+       }
+       out2[5-1] = tmp0 * wi[11-1];
+       out2[0+1] = tmp0 * wi[6+1];
+       ts[(12+1)*SBLIMIT] += tmp1 * wi[1];
+       ts[(17-1)*SBLIMIT] += tmp1 * wi[5-1];
+     }
+
+     DCT12_PART2
+
+     out2[5-0] = in2 * wi[11-0];
+     out2[0+0] = in2 * wi[6+0];
+     out2[0+2] = in3 * wi[6+2];
+     out2[5-2] = in3 * wi[11-2];
+
+     ts[(12+0)*SBLIMIT] += in0 * wi[0];
+     ts[(17-0)*SBLIMIT] += in0 * wi[5-0];
+     ts[(12+2)*SBLIMIT] += in4 * wi[2];
+     ts[(17-2)*SBLIMIT] += in4 * wi[5-2];
+  }
+
+  in++; 
+
+  {
+     real in0,in1,in2,in3,in4,in5;
+     register real *out2 = rawout2;
+     out2[12]=out2[13]=out2[14]=out2[15]=out2[16]=out2[17]=0.0;
+
+     DCT12_PART1
+
+     {
+       real tmp0,tmp1 = (in0 - in4);
+       {
+         real tmp2 = (in1 - in5) * tfcos12[1];
+         tmp0 = tmp1 + tmp2;
+         tmp1 -= tmp2;
+       }
+       out2[11-1] = tmp0 * wi[11-1];
+       out2[6 +1] = tmp0 * wi[6+1];
+       out2[0+1] += tmp1 * wi[1];
+       out2[5-1] += tmp1 * wi[5-1];
+     }
+
+     DCT12_PART2
+
+     out2[11-0] = in2 * wi[11-0];
+     out2[6 +0] = in2 * wi[6+0];
+     out2[6 +2] = in3 * wi[6+2];
+     out2[11-2] = in3 * wi[11-2];
+
+     out2[0+0] += in0 * wi[0];
+     out2[5-0] += in0 * wi[5-0];
+     out2[0+2] += in4 * wi[2];
+     out2[5-2] += in4 * wi[5-2];
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/dct36.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,264 @@
+/* 
+// This is an optimized DCT from Jeff Tsay's maplay 1.2+ package.
+// Saved one multiplication by doing the 'twiddle factor' stuff
+// together with the window mul. (MH)
+//
+// This uses Byeong Gi Lee's Fast Cosine Transform algorithm, but the
+// 9 point IDCT needs to be reduced further. Unfortunately, I don't
+// know how to do that, because 9 is not an even number. - Jeff.
+//
+//////////////////////////////////////////////////////////////////
+//
+// 9 Point Inverse Discrete Cosine Transform
+//
+// This piece of code is Copyright 1997 Mikko Tommila and is freely usable
+// by anybody. The algorithm itself is of course in the public domain.
+//
+// Again derived heuristically from the 9-point WFTA.
+//
+// The algorithm is optimized (?) for speed, not for small rounding errors or
+// good readability.
+//
+// 36 additions, 11 multiplications
+//
+// Again this is very likely sub-optimal.
+//
+// The code is optimized to use a minimum number of temporary variables,
+// so it should compile quite well even on 8-register Intel x86 processors.
+// This makes the code quite obfuscated and very difficult to understand.
+//
+// References:
+// [1] S. Winograd: "On Computing the Discrete Fourier Transform",
+//     Mathematics of Computation, Volume 32, Number 141, January 1978,
+//     Pages 175-199
+*/
+
+/*------------------------------------------------------------------*/
+/*                                                                  */
+/*    Function: Calculation of the inverse MDCT                     */
+/*                                                                  */
+/*------------------------------------------------------------------*/
+
+static void dct36(real *inbuf,real *o1,real *o2,real *wintab,real *tsbuf)
+{
+#ifdef NEW_DCT9
+  real tmp[18];
+#endif
+
+  {
+    register real *in = inbuf;
+
+    in[17]+=in[16]; in[16]+=in[15]; in[15]+=in[14];
+    in[14]+=in[13]; in[13]+=in[12]; in[12]+=in[11];
+    in[11]+=in[10]; in[10]+=in[9];  in[9] +=in[8];
+    in[8] +=in[7];  in[7] +=in[6];  in[6] +=in[5];
+    in[5] +=in[4];  in[4] +=in[3];  in[3] +=in[2];
+    in[2] +=in[1];  in[1] +=in[0];
+
+    in[17]+=in[15]; in[15]+=in[13]; in[13]+=in[11]; in[11]+=in[9];
+    in[9] +=in[7];  in[7] +=in[5];  in[5] +=in[3];  in[3] +=in[1];
+
+
+#ifdef NEW_DCT9
+    {
+      real t0, t1, t2, t3, t4, t5, t6, t7;
+
+      t1 = COS6_2 * in[12];
+      t2 = COS6_2 * (in[8] + in[16] - in[4]);
+
+      t3 = in[0] + t1;
+      t4 = in[0] - t1 - t1;
+      t5 = t4 - t2;
+
+      t0 = cos9[0] * (in[4] + in[8]);
+      t1 = cos9[1] * (in[8] - in[16]);
+
+      tmp[4] = t4 + t2 + t2;
+      t2 = cos9[2] * (in[4] + in[16]);
+
+      t6 = t3 - t0 - t2;
+      t0 += t3 + t1;
+      t3 += t2 - t1;
+
+      t2 = cos18[0] * (in[2]  + in[10]);
+      t4 = cos18[1] * (in[10] - in[14]);
+      t7 = COS6_1 * in[6];
+
+      t1 = t2 + t4 + t7;
+      tmp[0] = t0 + t1;
+      tmp[8] = t0 - t1;
+      t1 = cos18[2] * (in[2] + in[14]);
+      t2 += t1 - t7;
+
+      tmp[3] = t3 + t2;
+      t0 = COS6_1 * (in[10] + in[14] - in[2]);
+      tmp[5] = t3 - t2;
+
+      t4 -= t1 + t7;
+
+      tmp[1] = t5 - t0;
+      tmp[7] = t5 + t0;
+      tmp[2] = t6 + t4;
+      tmp[6] = t6 - t4;
+    }
+
+    {
+      real t0, t1, t2, t3, t4, t5, t6, t7;
+
+      t1 = COS6_2 * in[13];
+      t2 = COS6_2 * (in[9] + in[17] - in[5]);
+
+      t3 = in[1] + t1;
+      t4 = in[1] - t1 - t1;
+      t5 = t4 - t2;
+
+      t0 = cos9[0] * (in[5] + in[9]);
+      t1 = cos9[1] * (in[9] - in[17]);
+
+      tmp[13] = (t4 + t2 + t2) * tfcos36[17-13];
+      t2 = cos9[2] * (in[5] + in[17]);
+
+      t6 = t3 - t0 - t2;
+      t0 += t3 + t1;
+      t3 += t2 - t1;
+
+      t2 = cos18[0] * (in[3]  + in[11]);
+      t4 = cos18[1] * (in[11] - in[15]);
+      t7 = COS6_1 * in[7];
+
+      t1 = t2 + t4 + t7;
+      tmp[17] = (t0 + t1) * tfcos36[17-17];
+      tmp[9]  = (t0 - t1) * tfcos36[17-9];
+      t1 = cos18[2] * (in[3] + in[15]);
+      t2 += t1 - t7;
+
+      tmp[14] = (t3 + t2) * tfcos36[17-14];
+      t0 = COS6_1 * (in[11] + in[15] - in[3]);
+      tmp[12] = (t3 - t2) * tfcos36[17-12];
+
+      t4 -= t1 + t7;
+
+      tmp[16] = (t5 - t0) * tfcos36[17-16];
+      tmp[10] = (t5 + t0) * tfcos36[17-10];
+      tmp[15] = (t6 + t4) * tfcos36[17-15];
+      tmp[11] = (t6 - t4) * tfcos36[17-11];
+   }
+
+#define MACRO(v) { \
+    real tmpval; \
+    real sum0 = tmp[(v)]; \
+    real sum1 = tmp[17-(v)]; \
+    out2[9+(v)] = (tmpval = sum0 + sum1) * w[27+(v)]; \
+    out2[8-(v)] = tmpval * w[26-(v)]; \
+    sum0 -= sum1; \
+    ts[SBLIMIT*(8-(v))] = out1[8-(v)] + sum0 * w[8-(v)]; \
+    ts[SBLIMIT*(9+(v))] = out1[9+(v)] + sum0 * w[9+(v)]; }
+
+{
+   register real *out2 = o2;
+   register real *w = wintab;
+   register real *out1 = o1;
+   register real *ts = tsbuf;
+
+   MACRO(0);
+   MACRO(1);
+   MACRO(2);
+   MACRO(3);
+   MACRO(4);
+   MACRO(5);
+   MACRO(6);
+   MACRO(7);
+   MACRO(8);
+}
+
+#else
+
+  {
+
+#define MACRO0(v) { \
+    real tmp; \
+    out2[9+(v)] = (tmp = sum0 + sum1) * w[27+(v)]; \
+    out2[8-(v)] = tmp * w[26-(v)];  } \
+    sum0 -= sum1; \
+    ts[SBLIMIT*(8-(v))] = out1[8-(v)] + sum0 * w[8-(v)]; \
+    ts[SBLIMIT*(9+(v))] = out1[9+(v)] + sum0 * w[9+(v)]; 
+#define MACRO1(v) { \
+	real sum0,sum1; \
+    sum0 = tmp1a + tmp2a; \
+	sum1 = (tmp1b + tmp2b) * tfcos36[(v)]; \
+	MACRO0(v); }
+#define MACRO2(v) { \
+    real sum0,sum1; \
+    sum0 = tmp2a - tmp1a; \
+    sum1 = (tmp2b - tmp1b) * tfcos36[(v)]; \
+	MACRO0(v); }
+
+    register const real *c = nCOS9;
+    register real *out2 = o2;
+	register real *w = wintab;
+	register real *out1 = o1;
+	register real *ts = tsbuf;
+
+    real ta33,ta66,tb33,tb66;
+
+    ta33 = in[2*3+0] * c[3];
+    ta66 = in[2*6+0] * c[6];
+    tb33 = in[2*3+1] * c[3];
+    tb66 = in[2*6+1] * c[6];
+
+    { 
+      real tmp1a,tmp2a,tmp1b,tmp2b;
+      tmp1a =             in[2*1+0] * c[1] + ta33 + in[2*5+0] * c[5] + in[2*7+0] * c[7];
+      tmp1b =             in[2*1+1] * c[1] + tb33 + in[2*5+1] * c[5] + in[2*7+1] * c[7];
+      tmp2a = in[2*0+0] + in[2*2+0] * c[2] + in[2*4+0] * c[4] + ta66 + in[2*8+0] * c[8];
+      tmp2b = in[2*0+1] + in[2*2+1] * c[2] + in[2*4+1] * c[4] + tb66 + in[2*8+1] * c[8];
+
+      MACRO1(0);
+      MACRO2(8);
+    }
+
+    {
+      real tmp1a,tmp2a,tmp1b,tmp2b;
+      tmp1a = ( in[2*1+0] - in[2*5+0] - in[2*7+0] ) * c[3];
+      tmp1b = ( in[2*1+1] - in[2*5+1] - in[2*7+1] ) * c[3];
+      tmp2a = ( in[2*2+0] - in[2*4+0] - in[2*8+0] ) * c[6] - in[2*6+0] + in[2*0+0];
+      tmp2b = ( in[2*2+1] - in[2*4+1] - in[2*8+1] ) * c[6] - in[2*6+1] + in[2*0+1];
+
+      MACRO1(1);
+      MACRO2(7);
+    }
+
+    {
+      real tmp1a,tmp2a,tmp1b,tmp2b;
+      tmp1a =             in[2*1+0] * c[5] - ta33 - in[2*5+0] * c[7] + in[2*7+0] * c[1];
+      tmp1b =             in[2*1+1] * c[5] - tb33 - in[2*5+1] * c[7] + in[2*7+1] * c[1];
+      tmp2a = in[2*0+0] - in[2*2+0] * c[8] - in[2*4+0] * c[2] + ta66 + in[2*8+0] * c[4];
+      tmp2b = in[2*0+1] - in[2*2+1] * c[8] - in[2*4+1] * c[2] + tb66 + in[2*8+1] * c[4];
+
+      MACRO1(2);
+      MACRO2(6);
+    }
+
+    {
+      real tmp1a,tmp2a,tmp1b,tmp2b;
+      tmp1a =             in[2*1+0] * c[7] - ta33 + in[2*5+0] * c[1] - in[2*7+0] * c[5];
+      tmp1b =             in[2*1+1] * c[7] - tb33 + in[2*5+1] * c[1] - in[2*7+1] * c[5];
+      tmp2a = in[2*0+0] - in[2*2+0] * c[4] + in[2*4+0] * c[8] + ta66 - in[2*8+0] * c[2];
+      tmp2b = in[2*0+1] - in[2*2+1] * c[4] + in[2*4+1] * c[8] + tb66 - in[2*8+1] * c[2];
+
+      MACRO1(3);
+      MACRO2(5);
+    }
+
+	{
+		real sum0,sum1;
+    	sum0 =  in[2*0+0] - in[2*2+0] + in[2*4+0] - in[2*6+0] + in[2*8+0];
+    	sum1 = (in[2*0+1] - in[2*2+1] + in[2*4+1] - in[2*6+1] + in[2*8+1] ) * tfcos36[4];
+		MACRO0(4);
+	}
+  }
+#endif
+
+  }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/dct36_3dnow.s	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,499 @@
+/
+/ dct36_3dnow.s - 3DNow! optimized dct36()
+/
+/ This code based 'dct36_3dnow.s' by Syuuhei Kashiyama
+/ <squash@mb.kcom.ne.jp>,only two types of changes have been made:
+/
+/ - remove PREFETCH instruction for speedup
+/ - change function name for support 3DNow! automatic detect
+/
+/ You can find Kashiyama's original 3dnow! support patch
+/ (for mpg123-0.59o) at
+/ http://user.ecc.u-tokyo.ac.jp/~g810370/linux-simd/ (Japanese).
+/
+/ by KIMURA Takuhiro <kim@hannah.ipc.miyakyo-u.ac.jp> - until 31.Mar.1999
+/                    <kim@comtec.co.jp>               - after  1.Apr.1999
+/
+	
+///
+/// Replacement of dct36() with AMD's 3DNow! SIMD operations support
+/// 
+/// Syuuhei Kashiyama <squash@mb.kcom.ne.jp>
+/// 
+/// The author of this program disclaim whole expressed or implied
+/// warranties with regard to this program, and in no event shall the
+/// author of this program liable to whatever resulted from the use of
+/// this program. Use it at your own risk.
+/// 
+
+	.globl dct36_3dnow
+	.type	 dct36_3dnow,@function
+dct36_3dnow:
+	pushl %ebp
+	movl %esp,%ebp
+	subl $120,%esp
+	pushl %esi
+	pushl %ebx
+	movl 8(%ebp),%eax
+	movl 12(%ebp),%esi
+	movl 16(%ebp),%ecx
+	movl 20(%ebp),%edx
+	movl 24(%ebp),%ebx
+	leal -128(%ebp),%esp
+
+	femms
+	movq (%eax),%mm0
+	movq 4(%eax),%mm1
+	pfadd %mm1,%mm0
+	movq %mm0,4(%eax)
+	psrlq $32,%mm1
+	movq 12(%eax),%mm2
+	punpckldq %mm2,%mm1
+	pfadd %mm2,%mm1
+	movq %mm1,12(%eax)
+	psrlq $32,%mm2
+	movq 20(%eax),%mm3
+	punpckldq %mm3,%mm2
+	pfadd %mm3,%mm2
+	movq %mm2,20(%eax)
+	psrlq $32,%mm3
+	movq 28(%eax),%mm4
+	punpckldq %mm4,%mm3
+	pfadd %mm4,%mm3
+	movq %mm3,28(%eax)
+	psrlq $32,%mm4
+	movq 36(%eax),%mm5
+	punpckldq %mm5,%mm4
+	pfadd %mm5,%mm4
+	movq %mm4,36(%eax)
+	psrlq $32,%mm5
+	movq 44(%eax),%mm6
+	punpckldq %mm6,%mm5
+	pfadd %mm6,%mm5
+	movq %mm5,44(%eax)
+	psrlq $32,%mm6
+	movq 52(%eax),%mm7
+	punpckldq %mm7,%mm6
+	pfadd %mm7,%mm6
+	movq %mm6,52(%eax)
+	psrlq $32,%mm7
+	movq 60(%eax),%mm0
+	punpckldq %mm0,%mm7
+	pfadd %mm0,%mm7
+	movq %mm7,60(%eax)
+	psrlq $32,%mm0
+	movd 68(%eax),%mm1
+	pfadd %mm1,%mm0
+	movd %mm0,68(%eax)
+	movd 4(%eax),%mm0
+	movd 12(%eax),%mm1
+	punpckldq %mm1,%mm0
+	punpckldq 20(%eax),%mm1
+	pfadd %mm1,%mm0
+	movd %mm0,12(%eax)
+	psrlq $32,%mm0
+	movd %mm0,20(%eax)
+	psrlq $32,%mm1
+	movd 28(%eax),%mm2
+	punpckldq %mm2,%mm1
+	punpckldq 36(%eax),%mm2
+	pfadd %mm2,%mm1
+	movd %mm1,28(%eax)
+	psrlq $32,%mm1
+	movd %mm1,36(%eax)
+	psrlq $32,%mm2
+	movd 44(%eax),%mm3
+	punpckldq %mm3,%mm2
+	punpckldq 52(%eax),%mm3
+	pfadd %mm3,%mm2
+	movd %mm2,44(%eax)
+	psrlq $32,%mm2
+	movd %mm2,52(%eax)
+	psrlq $32,%mm3
+	movd 60(%eax),%mm4
+	punpckldq %mm4,%mm3
+	punpckldq 68(%eax),%mm4
+	pfadd %mm4,%mm3
+	movd %mm3,60(%eax)
+	psrlq $32,%mm3
+	movd %mm3,68(%eax)
+
+	movq 24(%eax),%mm0
+	movq 48(%eax),%mm1
+	movd COS9+12,%mm2
+	punpckldq %mm2,%mm2
+	movd COS9+24,%mm3
+	punpckldq %mm3,%mm3
+	pfmul %mm2,%mm0
+	pfmul %mm3,%mm1
+	pushl %eax
+	movl $1,%eax
+	movd %eax,%mm7
+	pi2fd %mm7,%mm7
+	popl %eax
+	movq 8(%eax),%mm2
+	movd COS9+4,%mm3
+	punpckldq %mm3,%mm3
+	pfmul %mm3,%mm2
+	pfadd %mm0,%mm2
+	movq 40(%eax),%mm3
+	movd COS9+20,%mm4
+	punpckldq %mm4,%mm4
+	pfmul %mm4,%mm3
+	pfadd %mm3,%mm2
+	movq 56(%eax),%mm3
+	movd COS9+28,%mm4
+	punpckldq %mm4,%mm4
+	pfmul %mm4,%mm3
+	pfadd %mm3,%mm2
+	movq (%eax),%mm3
+	movq 16(%eax),%mm4
+	movd COS9+8,%mm5
+	punpckldq %mm5,%mm5
+	pfmul %mm5,%mm4
+	pfadd %mm4,%mm3
+	movq 32(%eax),%mm4
+	movd COS9+16,%mm5
+	punpckldq %mm5,%mm5
+	pfmul %mm5,%mm4
+	pfadd %mm4,%mm3
+	pfadd %mm1,%mm3
+	movq 64(%eax),%mm4
+	movd COS9+32,%mm5
+	punpckldq %mm5,%mm5
+	pfmul %mm5,%mm4
+	pfadd %mm4,%mm3
+	movq %mm2,%mm4
+	pfadd %mm3,%mm4
+	movq %mm7,%mm5
+	punpckldq tfcos36+0,%mm5
+	pfmul %mm5,%mm4
+	movq %mm4,%mm5
+	pfacc %mm5,%mm5
+	movd 108(%edx),%mm6
+	punpckldq 104(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd %mm5,36(%ecx)
+	psrlq $32,%mm5
+	movd %mm5,32(%ecx)
+	movq %mm4,%mm6
+	punpckldq %mm6,%mm5
+	pfsub %mm6,%mm5
+	punpckhdq %mm5,%mm5
+	movd 32(%edx),%mm6
+	punpckldq 36(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd 32(%esi),%mm6
+	punpckldq 36(%esi),%mm6
+	pfadd %mm6,%mm5
+	movd %mm5,1024(%ebx)
+	psrlq $32,%mm5
+	movd %mm5,1152(%ebx)
+	movq %mm3,%mm4
+	pfsub %mm2,%mm4
+	movq %mm7,%mm5
+	punpckldq tfcos36+32,%mm5
+	pfmul %mm5,%mm4
+	movq %mm4,%mm5
+	pfacc %mm5,%mm5
+	movd 140(%edx),%mm6
+	punpckldq 72(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd %mm5,68(%ecx)
+	psrlq $32,%mm5
+	movd %mm5,0(%ecx)
+	movq %mm4,%mm6
+	punpckldq %mm6,%mm5
+	pfsub %mm6,%mm5
+	punpckhdq %mm5,%mm5
+	movd 0(%edx),%mm6
+	punpckldq 68(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd 0(%esi),%mm6
+	punpckldq 68(%esi),%mm6
+	pfadd %mm6,%mm5
+	movd %mm5,0(%ebx)
+	psrlq $32,%mm5
+	movd %mm5,2176(%ebx)
+	movq 8(%eax),%mm2
+	movq 40(%eax),%mm3
+	pfsub %mm3,%mm2
+	movq 56(%eax),%mm3
+	pfsub %mm3,%mm2
+	movd COS9+12,%mm3
+	punpckldq %mm3,%mm3
+	pfmul %mm3,%mm2
+	movq 16(%eax),%mm3
+	movq 32(%eax),%mm4
+	pfsub %mm4,%mm3
+	movq 64(%eax),%mm4
+	pfsub %mm4,%mm3
+	movd COS9+24,%mm4
+	punpckldq %mm4,%mm4
+	pfmul %mm4,%mm3
+	movq 48(%eax),%mm4
+	pfsub %mm4,%mm3
+	movq (%eax),%mm4
+	pfadd %mm4,%mm3
+	movq %mm2,%mm4
+	pfadd %mm3,%mm4
+	movq %mm7,%mm5
+	punpckldq tfcos36+4,%mm5
+	pfmul %mm5,%mm4
+	movq %mm4,%mm5
+	pfacc %mm5,%mm5
+	movd 112(%edx),%mm6
+	punpckldq 100(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd %mm5,40(%ecx)
+	psrlq $32,%mm5
+	movd %mm5,28(%ecx)
+	movq %mm4,%mm6
+	punpckldq %mm6,%mm5
+	pfsub %mm6,%mm5
+	punpckhdq %mm5,%mm5
+	movd 28(%edx),%mm6
+	punpckldq 40(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd 28(%esi),%mm6
+	punpckldq 40(%esi),%mm6
+	pfadd %mm6,%mm5
+	movd %mm5,896(%ebx)
+	psrlq $32,%mm5
+	movd %mm5,1280(%ebx)
+	movq %mm3,%mm4
+	pfsub %mm2,%mm4
+	movq %mm7,%mm5
+	punpckldq tfcos36+28,%mm5
+	pfmul %mm5,%mm4
+	movq %mm4,%mm5
+	pfacc %mm5,%mm5
+	movd 136(%edx),%mm6
+	punpckldq 76(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd %mm5,64(%ecx)
+	psrlq $32,%mm5
+	movd %mm5,4(%ecx)
+	movq %mm4,%mm6
+	punpckldq %mm6,%mm5
+	pfsub %mm6,%mm5
+	punpckhdq %mm5,%mm5
+	movd 4(%edx),%mm6
+	punpckldq 64(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd 4(%esi),%mm6
+	punpckldq 64(%esi),%mm6
+	pfadd %mm6,%mm5
+	movd %mm5,128(%ebx)
+	psrlq $32,%mm5
+	movd %mm5,2048(%ebx)
+
+	movq 8(%eax),%mm2
+	movd COS9+20,%mm3
+	punpckldq %mm3,%mm3
+	pfmul %mm3,%mm2
+	pfsub %mm0,%mm2
+	movq 40(%eax),%mm3
+	movd COS9+28,%mm4
+	punpckldq %mm4,%mm4
+	pfmul %mm4,%mm3
+	pfsub %mm3,%mm2
+	movq 56(%eax),%mm3
+	movd COS9+4,%mm4
+	punpckldq %mm4,%mm4
+	pfmul %mm4,%mm3
+	pfadd %mm3,%mm2
+	movq (%eax),%mm3
+	movq 16(%eax),%mm4
+	movd COS9+32,%mm5
+	punpckldq %mm5,%mm5
+	pfmul %mm5,%mm4
+	pfsub %mm4,%mm3
+	movq 32(%eax),%mm4
+	movd COS9+8,%mm5
+	punpckldq %mm5,%mm5
+	pfmul %mm5,%mm4
+	pfsub %mm4,%mm3
+	pfadd %mm1,%mm3
+	movq 64(%eax),%mm4
+	movd COS9+16,%mm5
+	punpckldq %mm5,%mm5
+	pfmul %mm5,%mm4
+	pfadd %mm4,%mm3
+	movq %mm2,%mm4
+	pfadd %mm3,%mm4
+	movq %mm7,%mm5
+	punpckldq tfcos36+8,%mm5
+	pfmul %mm5,%mm4
+	movq %mm4,%mm5
+	pfacc %mm5,%mm5
+	movd 116(%edx),%mm6
+	punpckldq 96(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd %mm5,44(%ecx)
+	psrlq $32,%mm5
+	movd %mm5,24(%ecx)
+	movq %mm4,%mm6
+	punpckldq %mm6,%mm5
+	pfsub %mm6,%mm5
+	punpckhdq %mm5,%mm5
+	movd 24(%edx),%mm6
+	punpckldq 44(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd 24(%esi),%mm6
+	punpckldq 44(%esi),%mm6
+	pfadd %mm6,%mm5
+	movd %mm5,768(%ebx)
+	psrlq $32,%mm5
+	movd %mm5,1408(%ebx)
+	movq %mm3,%mm4
+	pfsub %mm2,%mm4
+	movq %mm7,%mm5
+	punpckldq tfcos36+24,%mm5
+	pfmul %mm5,%mm4
+	movq %mm4,%mm5
+	pfacc %mm5,%mm5
+	movd 132(%edx),%mm6
+	punpckldq 80(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd %mm5,60(%ecx)
+	psrlq $32,%mm5
+	movd %mm5,8(%ecx)
+	movq %mm4,%mm6
+	punpckldq %mm6,%mm5
+	pfsub %mm6,%mm5
+	punpckhdq %mm5,%mm5
+	movd 8(%edx),%mm6
+	punpckldq 60(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd 8(%esi),%mm6
+	punpckldq 60(%esi),%mm6
+	pfadd %mm6,%mm5
+	movd %mm5,256(%ebx)
+	psrlq $32,%mm5
+	movd %mm5,1920(%ebx)
+	movq 8(%eax),%mm2
+	movd COS9+28,%mm3
+	punpckldq %mm3,%mm3
+	pfmul %mm3,%mm2
+	pfsub %mm0,%mm2
+	movq 40(%eax),%mm3
+	movd COS9+4,%mm4
+	punpckldq %mm4,%mm4
+	pfmul %mm4,%mm3
+	pfadd %mm3,%mm2
+	movq 56(%eax),%mm3
+	movd COS9+20,%mm4
+	punpckldq %mm4,%mm4
+	pfmul %mm4,%mm3
+	pfsub %mm3,%mm2
+	movq (%eax),%mm3
+	movq 16(%eax),%mm4
+	movd COS9+16,%mm5
+	punpckldq %mm5,%mm5
+	pfmul %mm5,%mm4
+	pfsub %mm4,%mm3
+	movq 32(%eax),%mm4
+	movd COS9+32,%mm5
+	punpckldq %mm5,%mm5
+	pfmul %mm5,%mm4
+	pfadd %mm4,%mm3
+	pfadd %mm1,%mm3
+	movq 64(%eax),%mm4
+	movd COS9+8,%mm5
+	punpckldq %mm5,%mm5
+	pfmul %mm5,%mm4
+	pfsub %mm4,%mm3
+	movq %mm2,%mm4
+	pfadd %mm3,%mm4
+	movq %mm7,%mm5
+	punpckldq tfcos36+12,%mm5
+	pfmul %mm5,%mm4
+	movq %mm4,%mm5
+	pfacc %mm5,%mm5
+	movd 120(%edx),%mm6
+	punpckldq 92(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd %mm5,48(%ecx)
+	psrlq $32,%mm5
+	movd %mm5,20(%ecx)
+	movq %mm4,%mm6
+	punpckldq %mm6,%mm5
+	pfsub %mm6,%mm5
+	punpckhdq %mm5,%mm5
+	movd 20(%edx),%mm6
+	punpckldq 48(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd 20(%esi),%mm6
+	punpckldq 48(%esi),%mm6
+	pfadd %mm6,%mm5
+	movd %mm5,640(%ebx)
+	psrlq $32,%mm5
+	movd %mm5,1536(%ebx)
+	movq %mm3,%mm4
+	pfsub %mm2,%mm4
+	movq %mm7,%mm5
+	punpckldq tfcos36+20,%mm5
+	pfmul %mm5,%mm4
+	movq %mm4,%mm5
+	pfacc %mm5,%mm5
+	movd 128(%edx),%mm6
+	punpckldq 84(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd %mm5,56(%ecx)
+	psrlq $32,%mm5
+	movd %mm5,12(%ecx)
+	movq %mm4,%mm6
+	punpckldq %mm6,%mm5
+	pfsub %mm6,%mm5
+	punpckhdq %mm5,%mm5
+	movd 12(%edx),%mm6
+	punpckldq 56(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd 12(%esi),%mm6
+	punpckldq 56(%esi),%mm6
+	pfadd %mm6,%mm5
+	movd %mm5,384(%ebx)
+	psrlq $32,%mm5
+	movd %mm5,1792(%ebx)
+
+	movq (%eax),%mm4
+	movq 16(%eax),%mm3
+	pfsub %mm3,%mm4
+	movq 32(%eax),%mm3
+	pfadd %mm3,%mm4
+	movq 48(%eax),%mm3
+	pfsub %mm3,%mm4
+	movq 64(%eax),%mm3
+	pfadd %mm3,%mm4
+	movq %mm7,%mm5
+	punpckldq tfcos36+16,%mm5
+	pfmul %mm5,%mm4
+	movq %mm4,%mm5
+	pfacc %mm5,%mm5
+	movd 124(%edx),%mm6
+	punpckldq 88(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd %mm5,52(%ecx)
+	psrlq $32,%mm5
+	movd %mm5,16(%ecx)
+	movq %mm4,%mm6
+	punpckldq %mm6,%mm5
+	pfsub %mm6,%mm5
+	punpckhdq %mm5,%mm5
+	movd 16(%edx),%mm6
+	punpckldq 52(%edx),%mm6
+	pfmul %mm6,%mm5
+	movd 16(%esi),%mm6
+	punpckldq 52(%esi),%mm6
+	pfadd %mm6,%mm5
+	movd %mm5,512(%ebx)
+	psrlq $32,%mm5
+	movd %mm5,1664(%ebx)
+
+	femms
+	popl %ebx
+	popl %esi
+	movl %ebp,%esp
+	popl %ebp
+	ret
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/dct64.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,313 @@
+
+/*
+ * Discrete Cosine Tansform (DCT) for subband synthesis
+ * optimized for machines with no auto-increment.
+ * The performance is highly compiler dependend. Maybe
+ * the dct64.c version for 'normal' processor may be faster
+ * even for Intel processors.
+ */
+
+static void dct64_1(real *out0,real *out1,real *b1,real *b2,real *samples)
+{
+
+ {
+  register real *costab = pnts[0];
+
+  b1[0x00] = samples[0x00] + samples[0x1F];
+  b1[0x1F] = (samples[0x00] - samples[0x1F]) * costab[0x0];
+
+  b1[0x01] = samples[0x01] + samples[0x1E];
+  b1[0x1E] = (samples[0x01] - samples[0x1E]) * costab[0x1];
+
+  b1[0x02] = samples[0x02] + samples[0x1D];
+  b1[0x1D] = (samples[0x02] - samples[0x1D]) * costab[0x2];
+
+  b1[0x03] = samples[0x03] + samples[0x1C];
+  b1[0x1C] = (samples[0x03] - samples[0x1C]) * costab[0x3];
+
+  b1[0x04] = samples[0x04] + samples[0x1B];
+  b1[0x1B] = (samples[0x04] - samples[0x1B]) * costab[0x4];
+
+  b1[0x05] = samples[0x05] + samples[0x1A];
+  b1[0x1A] = (samples[0x05] - samples[0x1A]) * costab[0x5];
+
+  b1[0x06] = samples[0x06] + samples[0x19];
+  b1[0x19] = (samples[0x06] - samples[0x19]) * costab[0x6];
+
+  b1[0x07] = samples[0x07] + samples[0x18];
+  b1[0x18] = (samples[0x07] - samples[0x18]) * costab[0x7];
+
+  b1[0x08] = samples[0x08] + samples[0x17];
+  b1[0x17] = (samples[0x08] - samples[0x17]) * costab[0x8];
+
+  b1[0x09] = samples[0x09] + samples[0x16];
+  b1[0x16] = (samples[0x09] - samples[0x16]) * costab[0x9];
+
+  b1[0x0A] = samples[0x0A] + samples[0x15];
+  b1[0x15] = (samples[0x0A] - samples[0x15]) * costab[0xA];
+
+  b1[0x0B] = samples[0x0B] + samples[0x14];
+  b1[0x14] = (samples[0x0B] - samples[0x14]) * costab[0xB];
+
+  b1[0x0C] = samples[0x0C] + samples[0x13];
+  b1[0x13] = (samples[0x0C] - samples[0x13]) * costab[0xC];
+
+  b1[0x0D] = samples[0x0D] + samples[0x12];
+  b1[0x12] = (samples[0x0D] - samples[0x12]) * costab[0xD];
+
+  b1[0x0E] = samples[0x0E] + samples[0x11];
+  b1[0x11] = (samples[0x0E] - samples[0x11]) * costab[0xE];
+
+  b1[0x0F] = samples[0x0F] + samples[0x10];
+  b1[0x10] = (samples[0x0F] - samples[0x10]) * costab[0xF];
+ }
+
+
+ {
+  register real *costab = pnts[1];
+
+  b2[0x00] = b1[0x00] + b1[0x0F];
+  b2[0x0F] = (b1[0x00] - b1[0x0F]) * costab[0];
+  b2[0x01] = b1[0x01] + b1[0x0E];
+  b2[0x0E] = (b1[0x01] - b1[0x0E]) * costab[1];
+  b2[0x02] = b1[0x02] + b1[0x0D];
+  b2[0x0D] = (b1[0x02] - b1[0x0D]) * costab[2];
+  b2[0x03] = b1[0x03] + b1[0x0C];
+  b2[0x0C] = (b1[0x03] - b1[0x0C]) * costab[3];
+  b2[0x04] = b1[0x04] + b1[0x0B];
+  b2[0x0B] = (b1[0x04] - b1[0x0B]) * costab[4];
+  b2[0x05] = b1[0x05] + b1[0x0A];
+  b2[0x0A] = (b1[0x05] - b1[0x0A]) * costab[5];
+  b2[0x06] = b1[0x06] + b1[0x09];
+  b2[0x09] = (b1[0x06] - b1[0x09]) * costab[6];
+  b2[0x07] = b1[0x07] + b1[0x08];
+  b2[0x08] = (b1[0x07] - b1[0x08]) * costab[7];
+
+  b2[0x10] = b1[0x10] + b1[0x1F];
+  b2[0x1F] = (b1[0x1F] - b1[0x10]) * costab[0];
+  b2[0x11] = b1[0x11] + b1[0x1E];
+  b2[0x1E] = (b1[0x1E] - b1[0x11]) * costab[1];
+  b2[0x12] = b1[0x12] + b1[0x1D];
+  b2[0x1D] = (b1[0x1D] - b1[0x12]) * costab[2];
+  b2[0x13] = b1[0x13] + b1[0x1C];
+  b2[0x1C] = (b1[0x1C] - b1[0x13]) * costab[3];
+  b2[0x14] = b1[0x14] + b1[0x1B];
+  b2[0x1B] = (b1[0x1B] - b1[0x14]) * costab[4];
+  b2[0x15] = b1[0x15] + b1[0x1A];
+  b2[0x1A] = (b1[0x1A] - b1[0x15]) * costab[5];
+  b2[0x16] = b1[0x16] + b1[0x19];
+  b2[0x19] = (b1[0x19] - b1[0x16]) * costab[6];
+  b2[0x17] = b1[0x17] + b1[0x18];
+  b2[0x18] = (b1[0x18] - b1[0x17]) * costab[7];
+ }
+
+ {
+  register real *costab = pnts[2];
+
+  b1[0x00] = b2[0x00] + b2[0x07];
+  b1[0x07] = (b2[0x00] - b2[0x07]) * costab[0];
+  b1[0x01] = b2[0x01] + b2[0x06];
+  b1[0x06] = (b2[0x01] - b2[0x06]) * costab[1];
+  b1[0x02] = b2[0x02] + b2[0x05];
+  b1[0x05] = (b2[0x02] - b2[0x05]) * costab[2];
+  b1[0x03] = b2[0x03] + b2[0x04];
+  b1[0x04] = (b2[0x03] - b2[0x04]) * costab[3];
+
+  b1[0x08] = b2[0x08] + b2[0x0F];
+  b1[0x0F] = (b2[0x0F] - b2[0x08]) * costab[0];
+  b1[0x09] = b2[0x09] + b2[0x0E];
+  b1[0x0E] = (b2[0x0E] - b2[0x09]) * costab[1];
+  b1[0x0A] = b2[0x0A] + b2[0x0D];
+  b1[0x0D] = (b2[0x0D] - b2[0x0A]) * costab[2];
+  b1[0x0B] = b2[0x0B] + b2[0x0C];
+  b1[0x0C] = (b2[0x0C] - b2[0x0B]) * costab[3];
+
+  b1[0x10] = b2[0x10] + b2[0x17];
+  b1[0x17] = (b2[0x10] - b2[0x17]) * costab[0];
+  b1[0x11] = b2[0x11] + b2[0x16];
+  b1[0x16] = (b2[0x11] - b2[0x16]) * costab[1];
+  b1[0x12] = b2[0x12] + b2[0x15];
+  b1[0x15] = (b2[0x12] - b2[0x15]) * costab[2];
+  b1[0x13] = b2[0x13] + b2[0x14];
+  b1[0x14] = (b2[0x13] - b2[0x14]) * costab[3];
+
+  b1[0x18] = b2[0x18] + b2[0x1F];
+  b1[0x1F] = (b2[0x1F] - b2[0x18]) * costab[0];
+  b1[0x19] = b2[0x19] + b2[0x1E];
+  b1[0x1E] = (b2[0x1E] - b2[0x19]) * costab[1];
+  b1[0x1A] = b2[0x1A] + b2[0x1D];
+  b1[0x1D] = (b2[0x1D] - b2[0x1A]) * costab[2];
+  b1[0x1B] = b2[0x1B] + b2[0x1C];
+  b1[0x1C] = (b2[0x1C] - b2[0x1B]) * costab[3];
+ }
+
+ {
+  register real const cos0 = pnts[3][0];
+  register real const cos1 = pnts[3][1];
+
+  b2[0x00] = b1[0x00] + b1[0x03];
+  b2[0x03] = (b1[0x00] - b1[0x03]) * cos0;
+  b2[0x01] = b1[0x01] + b1[0x02];
+  b2[0x02] = (b1[0x01] - b1[0x02]) * cos1;
+
+  b2[0x04] = b1[0x04] + b1[0x07];
+  b2[0x07] = (b1[0x07] - b1[0x04]) * cos0;
+  b2[0x05] = b1[0x05] + b1[0x06];
+  b2[0x06] = (b1[0x06] - b1[0x05]) * cos1;
+
+  b2[0x08] = b1[0x08] + b1[0x0B];
+  b2[0x0B] = (b1[0x08] - b1[0x0B]) * cos0;
+  b2[0x09] = b1[0x09] + b1[0x0A];
+  b2[0x0A] = (b1[0x09] - b1[0x0A]) * cos1;
+
+  b2[0x0C] = b1[0x0C] + b1[0x0F];
+  b2[0x0F] = (b1[0x0F] - b1[0x0C]) * cos0;
+  b2[0x0D] = b1[0x0D] + b1[0x0E];
+  b2[0x0E] = (b1[0x0E] - b1[0x0D]) * cos1;
+
+  b2[0x10] = b1[0x10] + b1[0x13];
+  b2[0x13] = (b1[0x10] - b1[0x13]) * cos0;
+  b2[0x11] = b1[0x11] + b1[0x12];
+  b2[0x12] = (b1[0x11] - b1[0x12]) * cos1;
+
+  b2[0x14] = b1[0x14] + b1[0x17];
+  b2[0x17] = (b1[0x17] - b1[0x14]) * cos0;
+  b2[0x15] = b1[0x15] + b1[0x16];
+  b2[0x16] = (b1[0x16] - b1[0x15]) * cos1;
+
+  b2[0x18] = b1[0x18] + b1[0x1B];
+  b2[0x1B] = (b1[0x18] - b1[0x1B]) * cos0;
+  b2[0x19] = b1[0x19] + b1[0x1A];
+  b2[0x1A] = (b1[0x19] - b1[0x1A]) * cos1;
+
+  b2[0x1C] = b1[0x1C] + b1[0x1F];
+  b2[0x1F] = (b1[0x1F] - b1[0x1C]) * cos0;
+  b2[0x1D] = b1[0x1D] + b1[0x1E];
+  b2[0x1E] = (b1[0x1E] - b1[0x1D]) * cos1;
+ }
+
+ {
+  register real const cos0 = pnts[4][0];
+
+  b1[0x00] = b2[0x00] + b2[0x01];
+  b1[0x01] = (b2[0x00] - b2[0x01]) * cos0;
+  b1[0x02] = b2[0x02] + b2[0x03];
+  b1[0x03] = (b2[0x03] - b2[0x02]) * cos0;
+  b1[0x02] += b1[0x03];
+
+  b1[0x04] = b2[0x04] + b2[0x05];
+  b1[0x05] = (b2[0x04] - b2[0x05]) * cos0;
+  b1[0x06] = b2[0x06] + b2[0x07];
+  b1[0x07] = (b2[0x07] - b2[0x06]) * cos0;
+  b1[0x06] += b1[0x07];
+  b1[0x04] += b1[0x06];
+  b1[0x06] += b1[0x05];
+  b1[0x05] += b1[0x07];
+
+  b1[0x08] = b2[0x08] + b2[0x09];
+  b1[0x09] = (b2[0x08] - b2[0x09]) * cos0;
+  b1[0x0A] = b2[0x0A] + b2[0x0B];
+  b1[0x0B] = (b2[0x0B] - b2[0x0A]) * cos0;
+  b1[0x0A] += b1[0x0B];
+
+  b1[0x0C] = b2[0x0C] + b2[0x0D];
+  b1[0x0D] = (b2[0x0C] - b2[0x0D]) * cos0;
+  b1[0x0E] = b2[0x0E] + b2[0x0F];
+  b1[0x0F] = (b2[0x0F] - b2[0x0E]) * cos0;
+  b1[0x0E] += b1[0x0F];
+  b1[0x0C] += b1[0x0E];
+  b1[0x0E] += b1[0x0D];
+  b1[0x0D] += b1[0x0F];
+
+  b1[0x10] = b2[0x10] + b2[0x11];
+  b1[0x11] = (b2[0x10] - b2[0x11]) * cos0;
+  b1[0x12] = b2[0x12] + b2[0x13];
+  b1[0x13] = (b2[0x13] - b2[0x12]) * cos0;
+  b1[0x12] += b1[0x13];
+
+  b1[0x14] = b2[0x14] + b2[0x15];
+  b1[0x15] = (b2[0x14] - b2[0x15]) * cos0;
+  b1[0x16] = b2[0x16] + b2[0x17];
+  b1[0x17] = (b2[0x17] - b2[0x16]) * cos0;
+  b1[0x16] += b1[0x17];
+  b1[0x14] += b1[0x16];
+  b1[0x16] += b1[0x15];
+  b1[0x15] += b1[0x17];
+
+  b1[0x18] = b2[0x18] + b2[0x19];
+  b1[0x19] = (b2[0x18] - b2[0x19]) * cos0;
+  b1[0x1A] = b2[0x1A] + b2[0x1B];
+  b1[0x1B] = (b2[0x1B] - b2[0x1A]) * cos0;
+  b1[0x1A] += b1[0x1B];
+
+  b1[0x1C] = b2[0x1C] + b2[0x1D];
+  b1[0x1D] = (b2[0x1C] - b2[0x1D]) * cos0;
+  b1[0x1E] = b2[0x1E] + b2[0x1F];
+  b1[0x1F] = (b2[0x1F] - b2[0x1E]) * cos0;
+  b1[0x1E] += b1[0x1F];
+  b1[0x1C] += b1[0x1E];
+  b1[0x1E] += b1[0x1D];
+  b1[0x1D] += b1[0x1F];
+ }
+
+ out0[0x10*16] = b1[0x00];
+ out0[0x10*12] = b1[0x04];
+ out0[0x10* 8] = b1[0x02];
+ out0[0x10* 4] = b1[0x06];
+ out0[0x10* 0] = b1[0x01];
+ out1[0x10* 0] = b1[0x01];
+ out1[0x10* 4] = b1[0x05];
+ out1[0x10* 8] = b1[0x03];
+ out1[0x10*12] = b1[0x07];
+
+ b1[0x08] += b1[0x0C];
+ out0[0x10*14] = b1[0x08];
+ b1[0x0C] += b1[0x0a];
+ out0[0x10*10] = b1[0x0C];
+ b1[0x0A] += b1[0x0E];
+ out0[0x10* 6] = b1[0x0A];
+ b1[0x0E] += b1[0x09];
+ out0[0x10* 2] = b1[0x0E];
+ b1[0x09] += b1[0x0D];
+ out1[0x10* 2] = b1[0x09];
+ b1[0x0D] += b1[0x0B];
+ out1[0x10* 6] = b1[0x0D];
+ b1[0x0B] += b1[0x0F];
+ out1[0x10*10] = b1[0x0B];
+ out1[0x10*14] = b1[0x0F];
+
+ b1[0x18] += b1[0x1C];
+ out0[0x10*15] = b1[0x10] + b1[0x18];
+ out0[0x10*13] = b1[0x18] + b1[0x14];
+ b1[0x1C] += b1[0x1a];
+ out0[0x10*11] = b1[0x14] + b1[0x1C];
+ out0[0x10* 9] = b1[0x1C] + b1[0x12];
+ b1[0x1A] += b1[0x1E];
+ out0[0x10* 7] = b1[0x12] + b1[0x1A];
+ out0[0x10* 5] = b1[0x1A] + b1[0x16];
+ b1[0x1E] += b1[0x19];
+ out0[0x10* 3] = b1[0x16] + b1[0x1E];
+ out0[0x10* 1] = b1[0x1E] + b1[0x11];
+ b1[0x19] += b1[0x1D];
+ out1[0x10* 1] = b1[0x11] + b1[0x19];
+ out1[0x10* 3] = b1[0x19] + b1[0x15];
+ b1[0x1D] += b1[0x1B];
+ out1[0x10* 5] = b1[0x15] + b1[0x1D];
+ out1[0x10* 7] = b1[0x1D] + b1[0x13];
+ b1[0x1B] += b1[0x1F];
+ out1[0x10* 9] = b1[0x13] + b1[0x1B];
+ out1[0x10*11] = b1[0x1B] + b1[0x17];
+ out1[0x10*13] = b1[0x17] + b1[0x1F];
+ out1[0x10*15] = b1[0x1F];
+}
+
+/*
+ * the call via dct64 is a trick to force GCC to use
+ * (new) registers for the b1,b2 pointer to the bufs[xx] field
+ */
+void dct64(real *a,real *b,real *c)
+{
+  real bufs[0x40];
+  dct64_1(a,b,bufs,bufs+0x20,c);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/dct64_3dnow.s	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,706 @@
+///
+/// Replacement of dct64() with AMD's 3DNow! SIMD operations support
+///
+/// Syuuhei Kashiyama <squash@mb.kcom.ne.jp>
+///
+/// The author of this program disclaim whole expressed or implied
+/// warranties with regard to this program, and in no event shall the
+/// author of this program liable to whatever resulted from the use of
+/// this program. Use it at your own risk.
+///
+
+        .globl dct64_3dnow
+        .type    dct64_3dnow,@function
+dct64_3dnow:
+        subl $256,%esp
+        pushl %ebp
+        pushl %edi
+        pushl %esi
+        pushl %ebx
+        leal 16(%esp),%ebx
+        movl 284(%esp),%edi
+        movl 276(%esp),%ebp
+        movl 280(%esp),%edx
+        leal 128(%ebx),%esi
+
+        / femms
+
+        // 1
+        movl pnts,%eax
+        movq 0(%edi),%mm0
+        movq %mm0,%mm1
+        movd 124(%edi),%mm2
+        punpckldq 120(%edi),%mm2
+        movq 0(%eax),%mm3
+        pfadd %mm2,%mm0
+        movq %mm0,0(%ebx)
+        pfsub %mm2,%mm1
+        pfmul %mm3,%mm1
+        movd %mm1,124(%ebx)
+        psrlq $32,%mm1
+        movd %mm1,120(%ebx)
+        movq 8(%edi),%mm4
+        movq %mm4,%mm5
+        movd 116(%edi),%mm6
+        punpckldq 112(%edi),%mm6
+        movq 8(%eax),%mm7
+        pfadd %mm6,%mm4
+        movq %mm4,8(%ebx)
+        pfsub %mm6,%mm5
+        pfmul %mm7,%mm5
+        movd %mm5,116(%ebx)
+        psrlq $32,%mm5
+        movd %mm5,112(%ebx)
+        movq 16(%edi),%mm0
+        movq %mm0,%mm1
+        movd 108(%edi),%mm2
+        punpckldq 104(%edi),%mm2
+        movq 16(%eax),%mm3
+        pfadd %mm2,%mm0
+        movq %mm0,16(%ebx)
+        pfsub %mm2,%mm1
+        pfmul %mm3,%mm1
+        movd %mm1,108(%ebx)
+        psrlq $32,%mm1
+        movd %mm1,104(%ebx)
+        movq 24(%edi),%mm4
+        movq %mm4,%mm5
+        movd 100(%edi),%mm6
+        punpckldq 96(%edi),%mm6
+        movq 24(%eax),%mm7
+        pfadd %mm6,%mm4
+        movq %mm4,24(%ebx)
+        pfsub %mm6,%mm5
+        pfmul %mm7,%mm5
+        movd %mm5,100(%ebx)
+        psrlq $32,%mm5
+        movd %mm5,96(%ebx)
+        movq 32(%edi),%mm0
+        movq %mm0,%mm1
+        movd 92(%edi),%mm2
+        punpckldq 88(%edi),%mm2
+        movq 32(%eax),%mm3
+        pfadd %mm2,%mm0
+        movq %mm0,32(%ebx)
+        pfsub %mm2,%mm1
+        pfmul %mm3,%mm1
+        movd %mm1,92(%ebx)
+        psrlq $32,%mm1
+        movd %mm1,88(%ebx)
+        movq 40(%edi),%mm4
+        movq %mm4,%mm5
+        movd 84(%edi),%mm6
+        punpckldq 80(%edi),%mm6
+        movq 40(%eax),%mm7
+        pfadd %mm6,%mm4
+        movq %mm4,40(%ebx)
+        pfsub %mm6,%mm5
+        pfmul %mm7,%mm5
+        movd %mm5,84(%ebx)
+        psrlq $32,%mm5
+        movd %mm5,80(%ebx)
+        movq 48(%edi),%mm0
+        movq %mm0,%mm1
+        movd 76(%edi),%mm2
+        punpckldq 72(%edi),%mm2
+        movq 48(%eax),%mm3
+        pfadd %mm2,%mm0
+        movq %mm0,48(%ebx)
+        pfsub %mm2,%mm1
+        pfmul %mm3,%mm1
+        movd %mm1,76(%ebx)
+        psrlq $32,%mm1
+        movd %mm1,72(%ebx)
+        movq 56(%edi),%mm4
+        movq %mm4,%mm5
+        movd 68(%edi),%mm6
+        punpckldq 64(%edi),%mm6
+        movq 56(%eax),%mm7
+        pfadd %mm6,%mm4
+        movq %mm4,56(%ebx)
+        pfsub %mm6,%mm5
+        pfmul %mm7,%mm5
+        movd %mm5,68(%ebx)
+        psrlq $32,%mm5
+        movd %mm5,64(%ebx)
+
+        // 2
+        movl pnts+4,%eax
+        / 0, 14
+        movq 0(%ebx),%mm0
+        movq %mm0,%mm1
+        movd 60(%ebx),%mm2
+        punpckldq 56(%ebx),%mm2
+        movq 0(%eax),%mm3
+        pfadd %mm2,%mm0
+        movq %mm0,0(%esi)
+        pfsub %mm2,%mm1
+        pfmul %mm3,%mm1
+        movd %mm1,60(%esi)
+        psrlq $32,%mm1
+        movd %mm1,56(%esi)
+        / 16, 30
+        movq 64(%ebx),%mm0
+        movq %mm0,%mm1
+        movd 124(%ebx),%mm2
+        punpckldq 120(%ebx),%mm2
+        pfadd %mm2,%mm0
+        movq %mm0,64(%esi)
+        pfsubr %mm2,%mm1
+        pfmul %mm3,%mm1
+        movd %mm1,124(%esi)
+        psrlq $32,%mm1
+        movd %mm1,120(%esi)
+        movq 8(%ebx),%mm4
+        / 2, 12
+        movq %mm4,%mm5
+        movd 52(%ebx),%mm6
+        punpckldq 48(%ebx),%mm6
+        movq 8(%eax),%mm7
+        pfadd %mm6,%mm4
+        movq %mm4,8(%esi)
+        pfsub %mm6,%mm5
+        pfmul %mm7,%mm5
+        movd %mm5,52(%esi)
+        psrlq $32,%mm5
+        movd %mm5,48(%esi)
+        movq 72(%ebx),%mm4
+        / 18, 28
+        movq %mm4,%mm5
+        movd 116(%ebx),%mm6
+        punpckldq 112(%ebx),%mm6
+        pfadd %mm6,%mm4
+        movq %mm4,72(%esi)
+        pfsubr %mm6,%mm5
+        pfmul %mm7,%mm5
+        movd %mm5,116(%esi)
+        psrlq $32,%mm5
+        movd %mm5,112(%esi)
+        movq 16(%ebx),%mm0
+        / 4, 10
+        movq %mm0,%mm1
+        movd 44(%ebx),%mm2
+        punpckldq 40(%ebx),%mm2
+        movq 16(%eax),%mm3
+        pfadd %mm2,%mm0
+        movq %mm0,16(%esi)
+        pfsub %mm2,%mm1
+        pfmul %mm3,%mm1
+        movd %mm1,44(%esi)
+        psrlq $32,%mm1
+        movd %mm1,40(%esi)
+        movq 80(%ebx),%mm0
+        / 20, 26
+        movq %mm0,%mm1
+        movd 108(%ebx),%mm2
+        punpckldq 104(%ebx),%mm2
+        pfadd %mm2,%mm0
+        movq %mm0,80(%esi)
+        pfsubr %mm2,%mm1
+        pfmul %mm3,%mm1
+        movd %mm1,108(%esi)
+        psrlq $32,%mm1
+        movd %mm1,104(%esi)
+        movq 24(%ebx),%mm4
+        / 6, 8
+        movq %mm4,%mm5
+        movd 36(%ebx),%mm6
+        punpckldq 32(%ebx),%mm6
+        movq 24(%eax),%mm7
+        pfadd %mm6,%mm4
+        movq %mm4,24(%esi)
+        pfsub %mm6,%mm5
+        pfmul %mm7,%mm5
+        movd %mm5,36(%esi)
+        psrlq $32,%mm5
+        movd %mm5,32(%esi)
+        movq 88(%ebx),%mm4
+        / 22, 24
+        movq %mm4,%mm5
+        movd 100(%ebx),%mm6
+        punpckldq 96(%ebx),%mm6
+        pfadd %mm6,%mm4
+        movq %mm4,88(%esi)
+        pfsubr %mm6,%mm5
+        pfmul %mm7,%mm5
+        movd %mm5,100(%esi)
+        psrlq $32,%mm5
+        movd %mm5,96(%esi)
+
+        // 3
+        movl pnts+8,%eax
+        movq 0(%eax),%mm0
+        movq 8(%eax),%mm1
+        movq 0(%esi),%mm2
+        / 0, 6
+        movq %mm2,%mm3
+        movd 28(%esi),%mm4
+        punpckldq 24(%esi),%mm4
+        pfadd %mm4,%mm2
+        pfsub %mm4,%mm3
+        pfmul %mm0,%mm3
+        movq %mm2,0(%ebx)
+        movd %mm3,28(%ebx)
+        psrlq $32,%mm3
+        movd %mm3,24(%ebx)
+        movq 8(%esi),%mm5
+        / 2, 4
+        movq %mm5,%mm6
+        movd 20(%esi),%mm7
+        punpckldq 16(%esi),%mm7
+        pfadd %mm7,%mm5
+        pfsub %mm7,%mm6
+        pfmul %mm1,%mm6
+        movq %mm5,8(%ebx)
+        movd %mm6,20(%ebx)
+        psrlq $32,%mm6
+        movd %mm6,16(%ebx)
+        movq 32(%esi),%mm2
+        / 8, 14
+        movq %mm2,%mm3
+        movd 60(%esi),%mm4
+        punpckldq 56(%esi),%mm4
+        pfadd %mm4,%mm2
+        pfsubr %mm4,%mm3
+        pfmul %mm0,%mm3
+        movq %mm2,32(%ebx)
+        movd %mm3,60(%ebx)
+        psrlq $32,%mm3
+        movd %mm3,56(%ebx)
+        movq 40(%esi),%mm5
+        / 10, 12
+        movq %mm5,%mm6
+        movd 52(%esi),%mm7
+        punpckldq 48(%esi),%mm7
+        pfadd %mm7,%mm5
+        pfsubr %mm7,%mm6
+        pfmul %mm1,%mm6
+        movq %mm5,40(%ebx)
+        movd %mm6,52(%ebx)
+        psrlq $32,%mm6
+        movd %mm6,48(%ebx)
+        movq 64(%esi),%mm2
+        / 16, 22
+        movq %mm2,%mm3
+        movd 92(%esi),%mm4
+        punpckldq 88(%esi),%mm4
+        pfadd %mm4,%mm2
+        pfsub %mm4,%mm3
+        pfmul %mm0,%mm3
+        movq %mm2,64(%ebx)
+        movd %mm3,92(%ebx)
+        psrlq $32,%mm3
+        movd %mm3,88(%ebx)
+        movq 72(%esi),%mm5
+        / 18, 20
+        movq %mm5,%mm6
+        movd 84(%esi),%mm7
+        punpckldq 80(%esi),%mm7
+        pfadd %mm7,%mm5
+        pfsub %mm7,%mm6
+        pfmul %mm1,%mm6
+        movq %mm5,72(%ebx)
+        movd %mm6,84(%ebx)
+        psrlq $32,%mm6
+        movd %mm6,80(%ebx)
+        movq 96(%esi),%mm2
+        / 24, 30
+        movq %mm2,%mm3
+        movd 124(%esi),%mm4
+        punpckldq 120(%esi),%mm4
+        pfadd %mm4,%mm2
+        pfsubr %mm4,%mm3
+        pfmul %mm0,%mm3
+        movq %mm2,96(%ebx)
+        movd %mm3,124(%ebx)
+        psrlq $32,%mm3
+        movd %mm3,120(%ebx)
+        movq 104(%esi),%mm5
+        / 26, 28
+        movq %mm5,%mm6
+        movd 116(%esi),%mm7
+        punpckldq 112(%esi),%mm7
+        pfadd %mm7,%mm5
+        pfsubr %mm7,%mm6
+        pfmul %mm1,%mm6
+        movq %mm5,104(%ebx)
+        movd %mm6,116(%ebx)
+        psrlq $32,%mm6
+        movd %mm6,112(%ebx)
+
+        // 4
+        movl pnts+12,%eax
+        movq 0(%eax),%mm0
+        movq 0(%ebx),%mm1
+        / 0
+        movq %mm1,%mm2
+        movd 12(%ebx),%mm3
+        punpckldq 8(%ebx),%mm3
+        pfadd %mm3,%mm1
+        pfsub %mm3,%mm2
+        pfmul %mm0,%mm2
+        movq %mm1,0(%esi)
+        movd %mm2,12(%esi)
+        psrlq $32,%mm2
+        movd %mm2,8(%esi)
+        movq 16(%ebx),%mm4
+        / 4
+        movq %mm4,%mm5
+        movd 28(%ebx),%mm6
+        punpckldq 24(%ebx),%mm6
+        pfadd %mm6,%mm4
+        pfsubr %mm6,%mm5
+        pfmul %mm0,%mm5
+        movq %mm4,16(%esi)
+        movd %mm5,28(%esi)
+        psrlq $32,%mm5
+        movd %mm5,24(%esi)
+        movq 32(%ebx),%mm1
+        / 8
+        movq %mm1,%mm2
+        movd 44(%ebx),%mm3
+        punpckldq 40(%ebx),%mm3
+        pfadd %mm3,%mm1
+        pfsub %mm3,%mm2
+        pfmul %mm0,%mm2
+        movq %mm1,32(%esi)
+        movd %mm2,44(%esi)
+        psrlq $32,%mm2
+        movd %mm2,40(%esi)
+        movq 48(%ebx),%mm4
+        / 12
+        movq %mm4,%mm5
+        movd 60(%ebx),%mm6
+        punpckldq 56(%ebx),%mm6
+        pfadd %mm6,%mm4
+        pfsubr %mm6,%mm5
+        pfmul %mm0,%mm5
+        movq %mm4,48(%esi)
+        movd %mm5,60(%esi)
+        psrlq $32,%mm5
+        movd %mm5,56(%esi)
+        movq 64(%ebx),%mm1
+        / 16
+        movq %mm1,%mm2
+        movd 76(%ebx),%mm3
+        punpckldq 72(%ebx),%mm3
+        pfadd %mm3,%mm1
+        pfsub %mm3,%mm2
+        pfmul %mm0,%mm2
+        movq %mm1,64(%esi)
+        movd %mm2,76(%esi)
+        psrlq $32,%mm2
+        movd %mm2,72(%esi)
+        movq 80(%ebx),%mm4
+        / 20
+        movq %mm4,%mm5
+        movd 92(%ebx),%mm6
+        punpckldq 88(%ebx),%mm6
+        pfadd %mm6,%mm4
+        pfsubr %mm6,%mm5
+        pfmul %mm0,%mm5
+        movq %mm4,80(%esi)
+        movd %mm5,92(%esi)
+        psrlq $32,%mm5
+        movd %mm5,88(%esi)
+        movq 96(%ebx),%mm1
+        / 24
+        movq %mm1,%mm2
+        movd 108(%ebx),%mm3
+        punpckldq 104(%ebx),%mm3
+        pfadd %mm3,%mm1
+        pfsub %mm3,%mm2
+        pfmul %mm0,%mm2
+        movq %mm1,96(%esi)
+        movd %mm2,108(%esi)
+        psrlq $32,%mm2
+        movd %mm2,104(%esi)
+        movq 112(%ebx),%mm4
+        / 28
+        movq %mm4,%mm5
+        movd 124(%ebx),%mm6
+        punpckldq 120(%ebx),%mm6
+        pfadd %mm6,%mm4
+        pfsubr %mm6,%mm5
+        pfmul %mm0,%mm5
+        movq %mm4,112(%esi)
+        movd %mm5,124(%esi)
+        psrlq $32,%mm5
+        movd %mm5,120(%esi)
+
+        // 5
+        movl $-1,%eax
+        movd %eax,%mm1
+        movl $1,%eax
+        movd %eax,%mm0
+        / L | H
+        punpckldq %mm1,%mm0
+        pi2fd %mm0,%mm0
+        / 1.0 | -1.0
+        movd %eax,%mm1
+        pi2fd %mm1,%mm1
+        movl pnts+16,%eax
+        movd 0(%eax),%mm2
+        punpckldq %mm2,%mm1
+        / 1.0 | cos0
+        movq 0(%esi),%mm2
+        / 0
+        movq %mm2,%mm3
+        pfmul %mm0,%mm3
+        pfacc %mm3,%mm2
+        pfmul %mm1,%mm2
+        movq %mm2,0(%ebx)
+        movq 8(%esi),%mm4
+        movq %mm4,%mm5
+        pfmul %mm0,%mm5
+        pfacc %mm5,%mm4
+        pfmul %mm0,%mm4
+        pfmul %mm1,%mm4
+        movq %mm4,%mm5
+        psrlq $32,%mm5
+        pfacc %mm5,%mm4
+        movq %mm4,8(%ebx)
+        movq 16(%esi),%mm2
+        / 4
+        movq %mm2,%mm3
+        pfmul %mm0,%mm3
+        pfacc %mm3,%mm2
+        pfmul %mm1,%mm2
+        movq 24(%esi),%mm4
+        movq %mm4,%mm5
+        pfmul %mm0,%mm5
+        pfacc %mm5,%mm4
+        pfmul %mm0,%mm4
+        pfmul %mm1,%mm4
+        movq %mm4,%mm5
+        psrlq $32,%mm5
+        pfacc %mm5,%mm4
+        movq %mm2,%mm3
+        psrlq $32,%mm3
+        pfadd %mm4,%mm2
+        pfadd %mm3,%mm4
+        movq %mm2,16(%ebx)
+        movq %mm4,24(%ebx)
+        movq 32(%esi),%mm2
+        / 8
+        movq %mm2,%mm3
+        pfmul %mm0,%mm3
+        pfacc %mm3,%mm2
+        pfmul %mm1,%mm2
+        movq %mm2,32(%ebx)
+        movq 40(%esi),%mm4
+        movq %mm4,%mm5
+        pfmul %mm0,%mm5
+        pfacc %mm5,%mm4
+        pfmul %mm0,%mm4
+        pfmul %mm1,%mm4
+        movq %mm4,%mm5
+        psrlq $32,%mm5
+        pfacc %mm5,%mm4
+        movq %mm4,40(%ebx)
+        movq 48(%esi),%mm2
+        / 12
+        movq %mm2,%mm3
+        pfmul %mm0,%mm3
+        pfacc %mm3,%mm2
+        pfmul %mm1,%mm2
+        movq 56(%esi),%mm4
+        movq %mm4,%mm5
+        pfmul %mm0,%mm5
+        pfacc %mm5,%mm4
+        pfmul %mm0,%mm4
+        pfmul %mm1,%mm4
+        movq %mm4,%mm5
+        psrlq $32,%mm5
+        pfacc %mm5,%mm4
+        movq %mm2,%mm3
+        psrlq $32,%mm3
+        pfadd %mm4,%mm2
+        pfadd %mm3,%mm4
+        movq %mm2,48(%ebx)
+        movq %mm4,56(%ebx)
+        movq 64(%esi),%mm2
+        / 16
+        movq %mm2,%mm3
+        pfmul %mm0,%mm3
+        pfacc %mm3,%mm2
+        pfmul %mm1,%mm2
+        movq %mm2,64(%ebx)
+        movq 72(%esi),%mm4
+        movq %mm4,%mm5
+        pfmul %mm0,%mm5
+        pfacc %mm5,%mm4
+        pfmul %mm0,%mm4
+        pfmul %mm1,%mm4
+        movq %mm4,%mm5
+        psrlq $32,%mm5
+        pfacc %mm5,%mm4
+        movq %mm4,72(%ebx)
+        movq 80(%esi),%mm2
+        / 20
+        movq %mm2,%mm3
+        pfmul %mm0,%mm3
+        pfacc %mm3,%mm2
+        pfmul %mm1,%mm2
+        movq 88(%esi),%mm4
+        movq %mm4,%mm5
+        pfmul %mm0,%mm5
+        pfacc %mm5,%mm4
+        pfmul %mm0,%mm4
+        pfmul %mm1,%mm4
+        movq %mm4,%mm5
+        psrlq $32,%mm5
+        pfacc %mm5,%mm4
+        movq %mm2,%mm3
+        psrlq $32,%mm3
+        pfadd %mm4,%mm2
+        pfadd %mm3,%mm4
+        movq %mm2,80(%ebx)
+        movq %mm4,88(%ebx)
+        movq 96(%esi),%mm2
+        / 24
+        movq %mm2,%mm3
+        pfmul %mm0,%mm3
+        pfacc %mm3,%mm2
+        pfmul %mm1,%mm2
+        movq %mm2,96(%ebx)
+        movq 104(%esi),%mm4
+        movq %mm4,%mm5
+        pfmul %mm0,%mm5
+        pfacc %mm5,%mm4
+        pfmul %mm0,%mm4
+        pfmul %mm1,%mm4
+        movq %mm4,%mm5
+        psrlq $32,%mm5
+        pfacc %mm5,%mm4
+        movq %mm4,104(%ebx)
+        movq 112(%esi),%mm2
+        / 28
+        movq %mm2,%mm3
+        pfmul %mm0,%mm3
+        pfacc %mm3,%mm2
+        pfmul %mm1,%mm2
+        movq 120(%esi),%mm4
+        movq %mm4,%mm5
+        pfmul %mm0,%mm5
+        pfacc %mm5,%mm4
+        pfmul %mm0,%mm4
+        pfmul %mm1,%mm4
+        movq %mm4,%mm5
+        psrlq $32,%mm5
+        pfacc %mm5,%mm4
+        movq %mm2,%mm3
+        psrlq $32,%mm3
+        pfadd %mm4,%mm2
+        pfadd %mm3,%mm4
+        movq %mm2,112(%ebx)
+        movq %mm4,120(%ebx)
+
+        // Phase6
+        movl 0(%ebx),%eax
+        movl %eax,1024(%ebp)
+        movl 4(%ebx),%eax
+        movl %eax,0(%ebp)
+        movl %eax,0(%edx)
+        movl 8(%ebx),%eax
+        movl %eax,512(%ebp)
+        movl 12(%ebx),%eax
+        movl %eax,512(%edx)
+
+        movl 16(%ebx),%eax
+        movl %eax,768(%ebp)
+        movl 20(%ebx),%eax
+        movl %eax,256(%edx)
+
+        movl 24(%ebx),%eax
+        movl %eax,256(%ebp)
+        movl 28(%ebx),%eax
+        movl %eax,768(%edx)
+
+        movq 32(%ebx),%mm0
+        movq 48(%ebx),%mm1
+        pfadd %mm1,%mm0
+        movd %mm0,896(%ebp)
+        psrlq $32,%mm0
+        movd %mm0,128(%edx)
+        movq 40(%ebx),%mm2
+        pfadd %mm2,%mm1
+        movd %mm1,640(%ebp)
+        psrlq $32,%mm1
+        movd %mm1,384(%edx)
+
+        movq 56(%ebx),%mm3
+        pfadd %mm3,%mm2
+        movd %mm2,384(%ebp)
+        psrlq $32,%mm2
+        movd %mm2,640(%edx)
+
+        movd 36(%ebx),%mm4
+        pfadd %mm4,%mm3
+        movd %mm3,128(%ebp)
+        psrlq $32,%mm3
+        movd %mm3,896(%edx)
+        movq 96(%ebx),%mm0
+        movq 64(%ebx),%mm1
+
+        movq 112(%ebx),%mm2
+        pfadd %mm2,%mm0
+        movq %mm0,%mm3
+        pfadd %mm1,%mm3
+        movd %mm3,960(%ebp)
+        psrlq $32,%mm3
+        movd %mm3,64(%edx)
+        movq 80(%ebx),%mm1
+        pfadd %mm1,%mm0
+        movd %mm0,832(%ebp)
+        psrlq $32,%mm0
+        movd %mm0,192(%edx)
+        movq 104(%ebx),%mm3
+        pfadd %mm3,%mm2
+        movq %mm2,%mm4
+        pfadd %mm1,%mm4
+        movd %mm4,704(%ebp)
+        psrlq $32,%mm4
+        movd %mm4,320(%edx)
+        movq 72(%ebx),%mm1
+        pfadd %mm1,%mm2
+        movd %mm2,576(%ebp)
+        psrlq $32,%mm2
+        movd %mm2,448(%edx)
+
+        movq 120(%ebx),%mm4
+        pfadd %mm4,%mm3
+        movq %mm3,%mm5
+        pfadd %mm1,%mm5
+        movd %mm5,448(%ebp)
+        psrlq $32,%mm5
+        movd %mm5,576(%edx)
+        movq 88(%ebx),%mm1
+        pfadd %mm1,%mm3
+        movd %mm3,320(%ebp)
+        psrlq $32,%mm3
+        movd %mm3,704(%edx)
+
+        movd 100(%ebx),%mm5
+        pfadd %mm5,%mm4
+        movq %mm4,%mm6
+        pfadd %mm1,%mm6
+        movd %mm6,192(%ebp)
+        psrlq $32,%mm6
+        movd %mm6,832(%edx)
+        movd 68(%ebx),%mm1
+        pfadd %mm1,%mm4
+        movd %mm4,64(%ebp)
+        psrlq $32,%mm4
+        movd %mm4,960(%edx)
+
+        / femms
+
+        popl %ebx
+        popl %esi
+        popl %edi
+        popl %ebp
+        addl $256,%esp
+
+        ret
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/dct64_i386.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,314 @@
+
+/*
+ * Discrete Cosine Tansform (DCT) for subband synthesis
+ * optimized for machines with no auto-increment.
+ * The performance is highly compiler dependend. Maybe
+ * the mpg123_dct64.c version for 'normal' processor may be faster
+ * even for Intel processors.
+ */
+
+#include "mpg123.h"
+
+static void mpg123_dct64_1(real * out0, real * out1, real * b1, real * b2, real * samples)
+{
+
+        {
+                register real *costab = pnts[0];
+
+                b1[0x00] = samples[0x00] + samples[0x1F];
+                b1[0x1F] = (samples[0x00] - samples[0x1F]) * costab[0x0];
+
+                b1[0x01] = samples[0x01] + samples[0x1E];
+                b1[0x1E] = (samples[0x01] - samples[0x1E]) * costab[0x1];
+
+                b1[0x02] = samples[0x02] + samples[0x1D];
+                b1[0x1D] = (samples[0x02] - samples[0x1D]) * costab[0x2];
+
+                b1[0x03] = samples[0x03] + samples[0x1C];
+                b1[0x1C] = (samples[0x03] - samples[0x1C]) * costab[0x3];
+
+                b1[0x04] = samples[0x04] + samples[0x1B];
+                b1[0x1B] = (samples[0x04] - samples[0x1B]) * costab[0x4];
+
+                b1[0x05] = samples[0x05] + samples[0x1A];
+                b1[0x1A] = (samples[0x05] - samples[0x1A]) * costab[0x5];
+
+                b1[0x06] = samples[0x06] + samples[0x19];
+                b1[0x19] = (samples[0x06] - samples[0x19]) * costab[0x6];
+
+                b1[0x07] = samples[0x07] + samples[0x18];
+                b1[0x18] = (samples[0x07] - samples[0x18]) * costab[0x7];
+
+                b1[0x08] = samples[0x08] + samples[0x17];
+                b1[0x17] = (samples[0x08] - samples[0x17]) * costab[0x8];
+
+                b1[0x09] = samples[0x09] + samples[0x16];
+                b1[0x16] = (samples[0x09] - samples[0x16]) * costab[0x9];
+
+                b1[0x0A] = samples[0x0A] + samples[0x15];
+                b1[0x15] = (samples[0x0A] - samples[0x15]) * costab[0xA];
+
+                b1[0x0B] = samples[0x0B] + samples[0x14];
+                b1[0x14] = (samples[0x0B] - samples[0x14]) * costab[0xB];
+
+                b1[0x0C] = samples[0x0C] + samples[0x13];
+                b1[0x13] = (samples[0x0C] - samples[0x13]) * costab[0xC];
+
+                b1[0x0D] = samples[0x0D] + samples[0x12];
+                b1[0x12] = (samples[0x0D] - samples[0x12]) * costab[0xD];
+
+                b1[0x0E] = samples[0x0E] + samples[0x11];
+                b1[0x11] = (samples[0x0E] - samples[0x11]) * costab[0xE];
+
+                b1[0x0F] = samples[0x0F] + samples[0x10];
+                b1[0x10] = (samples[0x0F] - samples[0x10]) * costab[0xF];
+        }
+
+        {
+                register real *costab = pnts[1];
+
+                b2[0x00] = b1[0x00] + b1[0x0F];
+                b2[0x0F] = (b1[0x00] - b1[0x0F]) * costab[0];
+                b2[0x01] = b1[0x01] + b1[0x0E];
+                b2[0x0E] = (b1[0x01] - b1[0x0E]) * costab[1];
+                b2[0x02] = b1[0x02] + b1[0x0D];
+                b2[0x0D] = (b1[0x02] - b1[0x0D]) * costab[2];
+                b2[0x03] = b1[0x03] + b1[0x0C];
+                b2[0x0C] = (b1[0x03] - b1[0x0C]) * costab[3];
+                b2[0x04] = b1[0x04] + b1[0x0B];
+                b2[0x0B] = (b1[0x04] - b1[0x0B]) * costab[4];
+                b2[0x05] = b1[0x05] + b1[0x0A];
+                b2[0x0A] = (b1[0x05] - b1[0x0A]) * costab[5];
+                b2[0x06] = b1[0x06] + b1[0x09];
+                b2[0x09] = (b1[0x06] - b1[0x09]) * costab[6];
+                b2[0x07] = b1[0x07] + b1[0x08];
+                b2[0x08] = (b1[0x07] - b1[0x08]) * costab[7];
+
+                b2[0x10] = b1[0x10] + b1[0x1F];
+                b2[0x1F] = (b1[0x1F] - b1[0x10]) * costab[0];
+                b2[0x11] = b1[0x11] + b1[0x1E];
+                b2[0x1E] = (b1[0x1E] - b1[0x11]) * costab[1];
+                b2[0x12] = b1[0x12] + b1[0x1D];
+                b2[0x1D] = (b1[0x1D] - b1[0x12]) * costab[2];
+                b2[0x13] = b1[0x13] + b1[0x1C];
+                b2[0x1C] = (b1[0x1C] - b1[0x13]) * costab[3];
+                b2[0x14] = b1[0x14] + b1[0x1B];
+                b2[0x1B] = (b1[0x1B] - b1[0x14]) * costab[4];
+                b2[0x15] = b1[0x15] + b1[0x1A];
+                b2[0x1A] = (b1[0x1A] - b1[0x15]) * costab[5];
+                b2[0x16] = b1[0x16] + b1[0x19];
+                b2[0x19] = (b1[0x19] - b1[0x16]) * costab[6];
+                b2[0x17] = b1[0x17] + b1[0x18];
+                b2[0x18] = (b1[0x18] - b1[0x17]) * costab[7];
+        }
+
+        {
+                register real *costab = pnts[2];
+
+                b1[0x00] = b2[0x00] + b2[0x07];
+                b1[0x07] = (b2[0x00] - b2[0x07]) * costab[0];
+                b1[0x01] = b2[0x01] + b2[0x06];
+                b1[0x06] = (b2[0x01] - b2[0x06]) * costab[1];
+                b1[0x02] = b2[0x02] + b2[0x05];
+                b1[0x05] = (b2[0x02] - b2[0x05]) * costab[2];
+                b1[0x03] = b2[0x03] + b2[0x04];
+                b1[0x04] = (b2[0x03] - b2[0x04]) * costab[3];
+
+                b1[0x08] = b2[0x08] + b2[0x0F];
+                b1[0x0F] = (b2[0x0F] - b2[0x08]) * costab[0];
+                b1[0x09] = b2[0x09] + b2[0x0E];
+                b1[0x0E] = (b2[0x0E] - b2[0x09]) * costab[1];
+                b1[0x0A] = b2[0x0A] + b2[0x0D];
+                b1[0x0D] = (b2[0x0D] - b2[0x0A]) * costab[2];
+                b1[0x0B] = b2[0x0B] + b2[0x0C];
+                b1[0x0C] = (b2[0x0C] - b2[0x0B]) * costab[3];
+
+                b1[0x10] = b2[0x10] + b2[0x17];
+                b1[0x17] = (b2[0x10] - b2[0x17]) * costab[0];
+                b1[0x11] = b2[0x11] + b2[0x16];
+                b1[0x16] = (b2[0x11] - b2[0x16]) * costab[1];
+                b1[0x12] = b2[0x12] + b2[0x15];
+                b1[0x15] = (b2[0x12] - b2[0x15]) * costab[2];
+                b1[0x13] = b2[0x13] + b2[0x14];
+                b1[0x14] = (b2[0x13] - b2[0x14]) * costab[3];
+
+                b1[0x18] = b2[0x18] + b2[0x1F];
+                b1[0x1F] = (b2[0x1F] - b2[0x18]) * costab[0];
+                b1[0x19] = b2[0x19] + b2[0x1E];
+                b1[0x1E] = (b2[0x1E] - b2[0x19]) * costab[1];
+                b1[0x1A] = b2[0x1A] + b2[0x1D];
+                b1[0x1D] = (b2[0x1D] - b2[0x1A]) * costab[2];
+                b1[0x1B] = b2[0x1B] + b2[0x1C];
+                b1[0x1C] = (b2[0x1C] - b2[0x1B]) * costab[3];
+        }
+
+        {
+                register real const cos0 = pnts[3][0];
+                register real const cos1 = pnts[3][1];
+
+                b2[0x00] = b1[0x00] + b1[0x03];
+                b2[0x03] = (b1[0x00] - b1[0x03]) * cos0;
+                b2[0x01] = b1[0x01] + b1[0x02];
+                b2[0x02] = (b1[0x01] - b1[0x02]) * cos1;
+
+                b2[0x04] = b1[0x04] + b1[0x07];
+                b2[0x07] = (b1[0x07] - b1[0x04]) * cos0;
+                b2[0x05] = b1[0x05] + b1[0x06];
+                b2[0x06] = (b1[0x06] - b1[0x05]) * cos1;
+
+                b2[0x08] = b1[0x08] + b1[0x0B];
+                b2[0x0B] = (b1[0x08] - b1[0x0B]) * cos0;
+                b2[0x09] = b1[0x09] + b1[0x0A];
+                b2[0x0A] = (b1[0x09] - b1[0x0A]) * cos1;
+
+                b2[0x0C] = b1[0x0C] + b1[0x0F];
+                b2[0x0F] = (b1[0x0F] - b1[0x0C]) * cos0;
+                b2[0x0D] = b1[0x0D] + b1[0x0E];
+                b2[0x0E] = (b1[0x0E] - b1[0x0D]) * cos1;
+
+                b2[0x10] = b1[0x10] + b1[0x13];
+                b2[0x13] = (b1[0x10] - b1[0x13]) * cos0;
+                b2[0x11] = b1[0x11] + b1[0x12];
+                b2[0x12] = (b1[0x11] - b1[0x12]) * cos1;
+
+                b2[0x14] = b1[0x14] + b1[0x17];
+                b2[0x17] = (b1[0x17] - b1[0x14]) * cos0;
+                b2[0x15] = b1[0x15] + b1[0x16];
+                b2[0x16] = (b1[0x16] - b1[0x15]) * cos1;
+
+                b2[0x18] = b1[0x18] + b1[0x1B];
+                b2[0x1B] = (b1[0x18] - b1[0x1B]) * cos0;
+                b2[0x19] = b1[0x19] + b1[0x1A];
+                b2[0x1A] = (b1[0x19] - b1[0x1A]) * cos1;
+
+                b2[0x1C] = b1[0x1C] + b1[0x1F];
+                b2[0x1F] = (b1[0x1F] - b1[0x1C]) * cos0;
+                b2[0x1D] = b1[0x1D] + b1[0x1E];
+                b2[0x1E] = (b1[0x1E] - b1[0x1D]) * cos1;
+        }
+
+        {
+                register real const cos0 = pnts[4][0];
+
+                b1[0x00] = b2[0x00] + b2[0x01];
+                b1[0x01] = (b2[0x00] - b2[0x01]) * cos0;
+                b1[0x02] = b2[0x02] + b2[0x03];
+                b1[0x03] = (b2[0x03] - b2[0x02]) * cos0;
+                b1[0x02] += b1[0x03];
+
+                b1[0x04] = b2[0x04] + b2[0x05];
+                b1[0x05] = (b2[0x04] - b2[0x05]) * cos0;
+                b1[0x06] = b2[0x06] + b2[0x07];
+                b1[0x07] = (b2[0x07] - b2[0x06]) * cos0;
+                b1[0x06] += b1[0x07];
+                b1[0x04] += b1[0x06];
+                b1[0x06] += b1[0x05];
+                b1[0x05] += b1[0x07];
+
+                b1[0x08] = b2[0x08] + b2[0x09];
+                b1[0x09] = (b2[0x08] - b2[0x09]) * cos0;
+                b1[0x0A] = b2[0x0A] + b2[0x0B];
+                b1[0x0B] = (b2[0x0B] - b2[0x0A]) * cos0;
+                b1[0x0A] += b1[0x0B];
+
+                b1[0x0C] = b2[0x0C] + b2[0x0D];
+                b1[0x0D] = (b2[0x0C] - b2[0x0D]) * cos0;
+                b1[0x0E] = b2[0x0E] + b2[0x0F];
+                b1[0x0F] = (b2[0x0F] - b2[0x0E]) * cos0;
+                b1[0x0E] += b1[0x0F];
+                b1[0x0C] += b1[0x0E];
+                b1[0x0E] += b1[0x0D];
+                b1[0x0D] += b1[0x0F];
+
+                b1[0x10] = b2[0x10] + b2[0x11];
+                b1[0x11] = (b2[0x10] - b2[0x11]) * cos0;
+                b1[0x12] = b2[0x12] + b2[0x13];
+                b1[0x13] = (b2[0x13] - b2[0x12]) * cos0;
+                b1[0x12] += b1[0x13];
+
+                b1[0x14] = b2[0x14] + b2[0x15];
+                b1[0x15] = (b2[0x14] - b2[0x15]) * cos0;
+                b1[0x16] = b2[0x16] + b2[0x17];
+                b1[0x17] = (b2[0x17] - b2[0x16]) * cos0;
+                b1[0x16] += b1[0x17];
+                b1[0x14] += b1[0x16];
+                b1[0x16] += b1[0x15];
+                b1[0x15] += b1[0x17];
+
+                b1[0x18] = b2[0x18] + b2[0x19];
+                b1[0x19] = (b2[0x18] - b2[0x19]) * cos0;
+                b1[0x1A] = b2[0x1A] + b2[0x1B];
+                b1[0x1B] = (b2[0x1B] - b2[0x1A]) * cos0;
+                b1[0x1A] += b1[0x1B];
+
+                b1[0x1C] = b2[0x1C] + b2[0x1D];
+                b1[0x1D] = (b2[0x1C] - b2[0x1D]) * cos0;
+                b1[0x1E] = b2[0x1E] + b2[0x1F];
+                b1[0x1F] = (b2[0x1F] - b2[0x1E]) * cos0;
+                b1[0x1E] += b1[0x1F];
+                b1[0x1C] += b1[0x1E];
+                b1[0x1E] += b1[0x1D];
+                b1[0x1D] += b1[0x1F];
+        }
+
+        out0[0x10 * 16] = b1[0x00];
+        out0[0x10 * 12] = b1[0x04];
+        out0[0x10 * 8] = b1[0x02];
+        out0[0x10 * 4] = b1[0x06];
+        out0[0x10 * 0] = b1[0x01];
+        out1[0x10 * 0] = b1[0x01];
+        out1[0x10 * 4] = b1[0x05];
+        out1[0x10 * 8] = b1[0x03];
+        out1[0x10 * 12] = b1[0x07];
+
+        b1[0x08] += b1[0x0C];
+        out0[0x10 * 14] = b1[0x08];
+        b1[0x0C] += b1[0x0a];
+        out0[0x10 * 10] = b1[0x0C];
+        b1[0x0A] += b1[0x0E];
+        out0[0x10 * 6] = b1[0x0A];
+        b1[0x0E] += b1[0x09];
+        out0[0x10 * 2] = b1[0x0E];
+        b1[0x09] += b1[0x0D];
+        out1[0x10 * 2] = b1[0x09];
+        b1[0x0D] += b1[0x0B];
+        out1[0x10 * 6] = b1[0x0D];
+        b1[0x0B] += b1[0x0F];
+        out1[0x10 * 10] = b1[0x0B];
+        out1[0x10 * 14] = b1[0x0F];
+
+        b1[0x18] += b1[0x1C];
+        out0[0x10 * 15] = b1[0x10] + b1[0x18];
+        out0[0x10 * 13] = b1[0x18] + b1[0x14];
+        b1[0x1C] += b1[0x1a];
+        out0[0x10 * 11] = b1[0x14] + b1[0x1C];
+        out0[0x10 * 9] = b1[0x1C] + b1[0x12];
+        b1[0x1A] += b1[0x1E];
+        out0[0x10 * 7] = b1[0x12] + b1[0x1A];
+        out0[0x10 * 5] = b1[0x1A] + b1[0x16];
+        b1[0x1E] += b1[0x19];
+        out0[0x10 * 3] = b1[0x16] + b1[0x1E];
+        out0[0x10 * 1] = b1[0x1E] + b1[0x11];
+        b1[0x19] += b1[0x1D];
+        out1[0x10 * 1] = b1[0x11] + b1[0x19];
+        out1[0x10 * 3] = b1[0x19] + b1[0x15];
+        b1[0x1D] += b1[0x1B];
+        out1[0x10 * 5] = b1[0x15] + b1[0x1D];
+        out1[0x10 * 7] = b1[0x1D] + b1[0x13];
+        b1[0x1B] += b1[0x1F];
+        out1[0x10 * 9] = b1[0x13] + b1[0x1B];
+        out1[0x10 * 11] = b1[0x1B] + b1[0x17];
+        out1[0x10 * 13] = b1[0x17] + b1[0x1F];
+        out1[0x10 * 15] = b1[0x1F];
+}
+
+/*
+ * the call via mpg123_dct64 is a trick to force GCC to use
+ * (new) registers for the b1,b2 pointer to the bufs[xx] field
+ */
+void mpg123_dct64(real * a, real * b, real * c)
+{
+        real bufs[0x40];
+
+        mpg123_dct64_1(a, b, bufs, bufs + 0x20, c);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/decod386.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,194 @@
+/*
+ * Mpeg Layer-1,2,3 audio decoder
+ * ------------------------------
+ * copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved.
+ * See also 'README'
+ *
+ * slighlty optimized for machines without autoincrement/decrement.
+ * The performance is highly compiler dependend. Maybe
+ * the decode.c version for 'normal' processor may be faster
+ * even for Intel processors.
+ */
+
+
+
+ /* new WRITE_SAMPLE */
+   /* sizeof(int) == 4 */
+#define WRITE_SAMPLE(samples,sum,clip) { \
+  double dtemp; long v;                  \
+  dtemp = ((((65536.0 * 65536.0 * 16)+(65536.0 * 0.5))* 65536.0)) + (sum);\
+  v = ((*(int *)&dtemp) - 0x80000000); \
+  if( v > 32767) { *(samples) = 0x7fff; (clip)++; } \
+  else if( v < -32768) { *(samples) = -0x8000; (clip)++; } \
+  else { *(samples) = v; } \
+}
+
+
+/*
+#define WRITE_SAMPLE(samples,sum,clip) { \
+  double dtemp; int v;                    \
+  dtemp = ((((65536.0 * 65536.0 * 16)+(65536.0 * 0.5))* 65536.0)) + (sum);\
+  v = ((*(int *)&dtemp) - 0x80000000); \
+  if( v > 32767) { *(samples) = 0x7fff; (clip)++; } \
+  else if( v < -32768) { *(samples) = -0x8000; (clip)++; } \
+  else { *(samples) = v; } \
+}
+*/
+
+static int synth_1to1_mono(real *bandPtr,unsigned char *samples,int *pnt)
+{
+  short samples_tmp[64];
+  short *tmp1 = samples_tmp;
+  int i,ret;
+  int pnt1 = 0;
+
+  ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
+  samples += *pnt;
+
+  for(i=0;i<32;i++) {
+    *( (short *) samples) = *tmp1;
+    samples += 2;
+    tmp1 += 2;
+  }
+  *pnt += 64;
+
+  return ret;
+}
+
+
+static int synth_1to1_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt)
+{
+  int i,ret;
+
+  ret = synth_1to1(bandPtr,0,samples,pnt);
+  samples = samples + *pnt - 128;
+
+  for(i=0;i<32;i++) {
+    ((short *)samples)[1] = ((short *)samples)[0];
+    samples+=4;
+  }
+
+  return ret;
+}
+
+
+static int synth_1to1(real *bandPtr,int channel,unsigned char *out,int *pnt)
+{
+  static real buffs[2][2][0x110];
+  static const int step = 2;
+  static int bo = 1;
+  short *samples = (short *) (out + *pnt);
+
+  real *b0,(*buf)[0x110];
+  int clip = 0;
+  int bo1;
+
+  #ifdef HAVE_3DNOW
+  if ( _3dnow )
+   {
+    int ret;
+    ret=synth_1to1_3dnow( bandPtr,channel,out+*pnt );
+    *pnt+=128;
+    return ret;
+   }
+  #endif
+  if ( _i586 )
+   {
+     int ret;
+     ret=synth_1to1_pent( bandPtr,channel,out+*pnt );
+     *pnt+=128;
+     return ret;
+   }
+
+  if(!channel) {     /* channel=0 */
+    bo--;
+    bo &= 0xf;
+    buf = buffs[0];
+  }
+  else {
+    samples++;
+    buf = buffs[1];
+  }
+
+  if(bo & 0x1) {
+    b0 = buf[0];
+    bo1 = bo;
+    dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
+  }
+  else {
+    b0 = buf[1];
+    bo1 = bo+1;
+    dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
+  }
+
+  {
+    register int j;
+    real *window = decwin + 16 - bo1;
+
+    for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step)
+    {
+      real sum;
+      sum  = window[0x0] * b0[0x0];
+      sum -= window[0x1] * b0[0x1];
+      sum += window[0x2] * b0[0x2];
+      sum -= window[0x3] * b0[0x3];
+      sum += window[0x4] * b0[0x4];
+      sum -= window[0x5] * b0[0x5];
+      sum += window[0x6] * b0[0x6];
+      sum -= window[0x7] * b0[0x7];
+      sum += window[0x8] * b0[0x8];
+      sum -= window[0x9] * b0[0x9];
+      sum += window[0xA] * b0[0xA];
+      sum -= window[0xB] * b0[0xB];
+      sum += window[0xC] * b0[0xC];
+      sum -= window[0xD] * b0[0xD];
+      sum += window[0xE] * b0[0xE];
+      sum -= window[0xF] * b0[0xF];
+
+      WRITE_SAMPLE(samples,sum,clip);
+    }
+
+    {
+      real sum;
+      sum  = window[0x0] * b0[0x0];
+      sum += window[0x2] * b0[0x2];
+      sum += window[0x4] * b0[0x4];
+      sum += window[0x6] * b0[0x6];
+      sum += window[0x8] * b0[0x8];
+      sum += window[0xA] * b0[0xA];
+      sum += window[0xC] * b0[0xC];
+      sum += window[0xE] * b0[0xE];
+      WRITE_SAMPLE(samples,sum,clip);
+      b0-=0x10,window-=0x20,samples+=step;
+    }
+    window += bo1<<1;
+
+    for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step)
+    {
+      real sum;
+      sum = -window[-0x1] * b0[0x0];
+      sum -= window[-0x2] * b0[0x1];
+      sum -= window[-0x3] * b0[0x2];
+      sum -= window[-0x4] * b0[0x3];
+      sum -= window[-0x5] * b0[0x4];
+      sum -= window[-0x6] * b0[0x5];
+      sum -= window[-0x7] * b0[0x6];
+      sum -= window[-0x8] * b0[0x7];
+      sum -= window[-0x9] * b0[0x8];
+      sum -= window[-0xA] * b0[0x9];
+      sum -= window[-0xB] * b0[0xA];
+      sum -= window[-0xC] * b0[0xB];
+      sum -= window[-0xD] * b0[0xC];
+      sum -= window[-0xE] * b0[0xD];
+      sum -= window[-0xF] * b0[0xE];
+      sum -= window[-0x0] * b0[0xF];
+
+      WRITE_SAMPLE(samples,sum,clip);
+    }
+  }
+  *pnt += 128;
+
+  return clip;
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/decode_3dnow.s	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,265 @@
+/ synth_1to1_3dnow works the same way as the c version of
+/ synth_1to1. this assembler code based 'decode-i586.s'
+/ (by Stefan Bieschewski <stb@acm.org>), two types of changes
+/ have been made:
+/ - use {MMX,3DNow!} instruction for reduce cpu
+/ - remove unused(?) local symbols
+/
+/ useful sources of information on optimizing 3DNow! code include:
+/ AMD 3DNow! Technology Manual (Publication #21928)
+/     English:  http://www.amd.com/K6/k6docs/pdf/21928d.pdf
+/    (Japanese: http://www.amd.com/japan/K6/k6docs/j21928c.pdf)
+/ AMD-K6-2 Processor Code Optimization Application Note (Publication #21924)
+/     English:  http://www.amd.com/K6/k6docs/pdf/21924b.pdf
+/
+/ This code was tested only AMD-K6-2 processor Linux systems,
+/ please tell me:
+/ - whether this code works on other 3DNow! capable processors
+/  (ex.IDT-C6-2) or not
+/ - whether this code works on other OSes or not
+/
+/ by KIMURA Takuhiro <kim@hannah.ipc.miyakyo-u.ac.jp> - until 31.Mar.1998
+/                    <kim@comtec.co.jp>               - after  1.Apr.1998
+
+/ Enhancments for q-word operation by Michael Hipp
+
+.bss
+        .comm   buffs,4352,4
+.data
+        .align 4
+bo:
+        .long 1
+.text
+.globl synth_1to1_3dnow
+synth_1to1_3dnow:
+        subl  $12,%esp
+        pushl %ebp
+        pushl %edi
+        pushl %esi
+        pushl %ebx
+        movl  32(%esp),%eax
+        movl  40(%esp),%esi
+        movl  $0,%edi
+        movl  bo,%ebp
+        cmpl  %edi,36(%esp)
+        jne   .L48
+        decl  %ebp
+        andl  $15,%ebp
+        movl  %ebp,bo
+        movl  $buffs,%ecx
+        jmp   .L49
+.L48:
+        addl  $2,%esi
+        movl  $buffs+2176,%ecx
+.L49:
+        testl $1,%ebp
+        je    .L50
+        movl  %ecx,%ebx
+        movl  %ebp,16(%esp)
+        pushl %eax
+        movl  20(%esp),%edx
+        leal  (%ebx,%edx,4),%eax
+        pushl %eax
+        movl  24(%esp),%eax
+        incl  %eax
+        andl  $15,%eax
+        leal  1088(,%eax,4),%eax
+        addl  %ebx,%eax
+        jmp   .L74
+.L50:
+        leal  1088(%ecx),%ebx
+        leal  1(%ebp),%edx
+        movl  %edx,16(%esp)
+        pushl %eax
+        leal  1092(%ecx,%ebp,4),%eax
+        pushl %eax
+        leal  (%ecx,%ebp,4),%eax
+.L74:
+        pushl %eax
+        call  dct64_3dnow
+        addl  $12,%esp
+        movl  16(%esp),%edx
+        leal  0(,%edx,4),%edx
+        movl  $decwin+64,%eax
+        movl  %eax,%ecx
+        subl  %edx,%ecx
+        movl  $16,%ebp
+
+.L55:
+        movq  (%ecx),%mm4
+        movq  (%ebx),%mm3
+        movq  8(%ecx),%mm0
+        movq  8(%ebx),%mm1
+        pfmul %mm3,%mm4
+
+        movq  16(%ecx),%mm2
+        pfmul %mm1,%mm0
+        movq  16(%ebx),%mm3
+        pfadd %mm0,%mm4
+
+        movq  24(%ecx),%mm0
+        pfmul %mm2,%mm3
+        movq  24(%ebx),%mm1
+        pfadd %mm3,%mm4
+
+        movq  32(%ecx),%mm2
+        pfmul %mm1,%mm0
+        movq  32(%ebx),%mm3
+        pfadd %mm0,%mm4
+
+        movq  40(%ecx),%mm0
+        pfmul %mm2,%mm3
+        movq  40(%ebx),%mm1
+        pfadd %mm3,%mm4
+
+        movq  48(%ecx),%mm2
+        pfmul %mm1,%mm0
+        movq  48(%ebx),%mm3
+        pfadd %mm0,%mm4
+
+        movq  56(%ecx),%mm0
+        pfmul %mm2,%mm3
+        movq  56(%ebx),%mm1
+        pfadd %mm3,%mm4
+
+        pfmul %mm1,%mm0
+        pfadd %mm0,%mm4
+
+        movq  %mm4,%mm0
+        psrlq $32,%mm0
+        pfsub %mm0,%mm4
+
+        pf2id %mm4,%mm4
+        movd  %mm4,%eax
+
+        sar   $16,%eax
+        movw  %ax,(%esi)
+
+        addl  $64,%ebx
+        subl  $-128,%ecx
+        addl  $4,%esi
+        decl  %ebp
+        jnz  .L55
+
+/ --- end of  loop 1 ---
+
+        movd  (%ecx),%mm2
+        movd  (%ebx),%mm1
+        pfmul %mm1,%mm2
+
+        movd  8(%ecx),%mm0
+        movd  8(%ebx),%mm1
+        pfmul %mm0,%mm1
+        pfadd %mm1,%mm2
+
+        movd  16(%ecx),%mm0
+        movd  16(%ebx),%mm1
+        pfmul %mm0,%mm1
+        pfadd %mm1,%mm2
+
+        movd  24(%ecx),%mm0
+        movd  24(%ebx),%mm1
+        pfmul %mm0,%mm1
+        pfadd %mm1,%mm2
+
+        movd  32(%ecx),%mm0
+        movd  32(%ebx),%mm1
+        pfmul %mm0,%mm1
+        pfadd %mm1,%mm2
+
+        movd  40(%ecx),%mm0
+        movd  40(%ebx),%mm1
+        pfmul %mm0,%mm1
+        pfadd %mm1,%mm2
+
+        movd  48(%ecx),%mm0
+        movd  48(%ebx),%mm1
+        pfmul %mm0,%mm1
+        pfadd %mm1,%mm2
+
+        movd  56(%ecx),%mm0
+        movd  56(%ebx),%mm1
+        pfmul %mm0,%mm1
+        pfadd %mm1,%mm2
+
+        pf2id %mm2,%mm2
+        movd  %mm2,%eax
+
+        sar   $16,%eax
+
+        movw  %ax,(%esi)
+
+        addl  $-64,%ebx
+        addl  $4,%esi
+        addl  $256,%ecx
+        movl  $15,%ebp
+
+.L68:
+        psubd %mm0,%mm0
+
+        movq  (%ebx),%mm1
+        movq  (%ecx),%mm2
+        pfmul %mm1,%mm2
+        pfsub %mm2,%mm0
+
+        movq  8(%ebx),%mm3
+        movq  8(%ecx),%mm4
+        pfmul %mm3,%mm4
+        pfsub %mm4,%mm0
+
+        movq  16(%ebx),%mm1
+        movq  16(%ecx),%mm2
+        pfmul %mm1,%mm2
+        pfsub %mm2,%mm0
+
+        movq  24(%ebx),%mm3
+        movq  24(%ecx),%mm4
+        pfmul %mm3,%mm4
+        pfsub %mm4,%mm0
+
+        movq  32(%ebx),%mm1
+        movq  32(%ecx),%mm2
+        pfmul %mm1,%mm2
+        pfsub %mm2,%mm0
+
+        movq  40(%ebx),%mm3
+        movq  40(%ecx),%mm4
+        pfmul %mm3,%mm4
+        pfsub %mm4,%mm0
+
+        movq  48(%ebx),%mm1
+        movq  48(%ecx),%mm2
+        pfmul %mm1,%mm2
+        pfsub %mm2,%mm0
+
+        movq  56(%ebx),%mm3
+        movq  56(%ecx),%mm4
+        pfmul %mm3,%mm4
+        pfsub %mm4,%mm0
+
+        pfacc %mm0,%mm0
+
+        pf2id %mm0,%mm0
+        movd  %mm0,%eax
+
+        sar   $16,%eax
+
+        movw  %ax,(%esi)
+
+        addl  $-64,%ebx
+        subl  $-128,%ecx
+        addl  $4,%esi
+        decl  %ebp
+        jnz   .L68
+
+/ --- end of loop 2
+
+        femms
+
+        movl  %edi,%eax
+        popl  %ebx
+        popl  %esi
+        popl  %edi
+        popl  %ebp
+        addl  $12,%esp
+        ret
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/decode_i586.s	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,321 @@
+/
+/ mpg123_synth_1to1 works the same way as the c version of this
+/ file.  only two types of changes have been made:
+/ - reordered floating point instructions to
+/   prevent pipline stalls
+/ - made WRITE_SAMPLE use integer instead of
+/   (slower) floating point
+/ all kinds of x86 processors should benefit from these
+/ modifications.
+/
+/ useful sources of information on optimizing x86 code include:
+/
+/     Intel Architecture Optimization Manual
+/     http://www.intel.com/design/pentium/manuals/242816.htm
+/
+/     Cyrix 6x86 Instruction Set Summary
+/     ftp://ftp.cyrix.com/6x86/6x-dbch6.pdf
+/
+/     AMD-K5 Processor Software Development
+/     http://www.amd.com/products/cpg/techdocs/appnotes/20007e.pdf
+/
+/ Stefan Bieschewski <stb@acm.org>
+/
+/ $Id$
+/
+.bss
+        .comm   buffs,4352,4
+.data
+        .align 4
+bo:
+        .long 1
+.section .rodata
+        .align 8
+.LC0:
+        .long 0x0,0x40dfffc0
+        .align 8
+.LC1:
+        .long 0x0,0xc0e00000
+        .align 8
+.text
+.globl synth_1to1_pent
+synth_1to1_pent:
+        subl $12,%esp
+        pushl %ebp
+        pushl %edi
+        pushl %esi
+        pushl %ebx
+        movl 32(%esp),%eax
+        movl 40(%esp),%esi
+        xorl %edi,%edi
+        movl bo,%ebp
+        cmpl %edi,36(%esp)
+        jne .L48
+        decl %ebp
+        andl $15,%ebp
+        movl %ebp,bo
+        movl $buffs,%ecx
+        jmp .L49
+.L48:
+        addl $2,%esi
+        movl $buffs+2176,%ecx
+.L49:
+        testl $1,%ebp
+        je .L50
+        movl %ecx,%ebx
+        movl %ebp,16(%esp)
+        pushl %eax
+        movl 20(%esp),%edx
+        leal (%ebx,%edx,4),%eax
+        pushl %eax
+        movl 24(%esp),%eax
+        incl %eax
+        andl $15,%eax
+        leal 1088(,%eax,4),%eax
+        addl %ebx,%eax
+        jmp .L74
+.L50:
+        leal 1088(%ecx),%ebx
+        leal 1(%ebp),%edx
+        movl %edx,16(%esp)
+        pushl %eax
+        leal 1092(%ecx,%ebp,4),%eax
+        pushl %eax
+        leal (%ecx,%ebp,4),%eax
+.L74:
+        pushl %eax
+        call dct64
+        addl $12,%esp
+        movl 16(%esp),%edx
+        leal 0(,%edx,4),%edx
+        movl $decwin+64,%eax
+        movl %eax,%ecx
+        subl %edx,%ecx
+        movl $16,%ebp
+.L55:
+        flds (%ecx)
+        fmuls (%ebx)
+        flds 4(%ecx)
+        fmuls 4(%ebx)
+        fxch %st(1)
+        flds 8(%ecx)
+        fmuls 8(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds 12(%ecx)
+        fmuls 12(%ebx)
+        fxch %st(2)
+        faddp %st,%st(1)
+        flds 16(%ecx)
+        fmuls 16(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds 20(%ecx)
+        fmuls 20(%ebx)
+        fxch %st(2)
+        faddp %st,%st(1)
+        flds 24(%ecx)
+        fmuls 24(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds 28(%ecx)
+        fmuls 28(%ebx)
+        fxch %st(2)
+        faddp %st,%st(1)
+        flds 32(%ecx)
+        fmuls 32(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds 36(%ecx)
+        fmuls 36(%ebx)
+        fxch %st(2)
+        faddp %st,%st(1)
+        flds 40(%ecx)
+        fmuls 40(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds 44(%ecx)
+        fmuls 44(%ebx)
+        fxch %st(2)
+        faddp %st,%st(1)
+        flds 48(%ecx)
+        fmuls 48(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds 52(%ecx)
+        fmuls 52(%ebx)
+        fxch %st(2)
+        faddp %st,%st(1)
+        flds 56(%ecx)
+        fmuls 56(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds 60(%ecx)
+        fmuls 60(%ebx)
+        fxch %st(2)
+        subl $4,%esp
+        faddp %st,%st(1)
+        fxch %st(1)
+        fsubrp %st,%st(1)
+        fistpl (%esp)
+        popl %eax
+        cmpl $32767,%eax
+        jg 1f
+        cmpl $-32768,%eax
+        jl 2f
+        movw %ax,(%esi)
+        jmp 4f
+1:      movw $32767,(%esi)
+        jmp 3f
+2:      movw $-32768,(%esi)
+3:      incl %edi
+4:
+.L54:
+        addl $64,%ebx
+        subl $-128,%ecx
+        addl $4,%esi
+        decl %ebp
+        jnz .L55
+        flds (%ecx)
+        fmuls (%ebx)
+        flds 8(%ecx)
+        fmuls 8(%ebx)
+        flds 16(%ecx)
+        fmuls 16(%ebx)
+        fxch %st(2)
+        faddp %st,%st(1)
+        flds 24(%ecx)
+        fmuls 24(%ebx)
+        fxch %st(2)
+        faddp %st,%st(1)
+        flds 32(%ecx)
+        fmuls 32(%ebx)
+        fxch %st(2)
+        faddp %st,%st(1)
+        flds 40(%ecx)
+        fmuls 40(%ebx)
+        fxch %st(2)
+        faddp %st,%st(1)
+        flds 48(%ecx)
+        fmuls 48(%ebx)
+        fxch %st(2)
+        faddp %st,%st(1)
+        flds 56(%ecx)
+        fmuls 56(%ebx)
+        fxch %st(2)
+        subl $4,%esp
+        faddp %st,%st(1)
+        fxch %st(1)
+        faddp %st,%st(1)
+        fistpl (%esp)
+        popl %eax
+        cmpl $32767,%eax
+        jg 1f
+        cmpl $-32768,%eax
+        jl 2f
+        movw %ax,(%esi)
+        jmp 4f
+1:      movw $32767,(%esi)
+        jmp 3f
+2:      movw $-32768,(%esi)
+3:      incl %edi
+4:
+.L62:
+        addl $-64,%ebx
+        addl $4,%esi
+        movl 16(%esp),%edx
+        leal -128(%ecx,%edx,8),%ecx
+        movl $15,%ebp
+.L68:
+        flds -4(%ecx)
+        fchs
+        fmuls (%ebx)
+        flds -8(%ecx)
+        fmuls 4(%ebx)
+        fxch %st(1)
+        flds -12(%ecx)
+        fmuls 8(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds -16(%ecx)
+        fmuls 12(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds -20(%ecx)
+        fmuls 16(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds -24(%ecx)
+        fmuls 20(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds -28(%ecx)
+        fmuls 24(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds -32(%ecx)
+        fmuls 28(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds -36(%ecx)
+        fmuls 32(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds -40(%ecx)
+        fmuls 36(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds -44(%ecx)
+        fmuls 40(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds -48(%ecx)
+        fmuls 44(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds -52(%ecx)
+        fmuls 48(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds -56(%ecx)
+        fmuls 52(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds -60(%ecx)
+        fmuls 56(%ebx)
+        fxch %st(2)
+        fsubrp %st,%st(1)
+        flds (%ecx)
+        fmuls 60(%ebx)
+        fxch %st(2)
+        subl $4,%esp
+        fsubrp %st,%st(1)
+        fxch %st(1)
+        fsubrp %st,%st(1)
+        fistpl (%esp)
+        popl %eax
+        cmpl $32767,%eax
+        jg 1f
+        cmpl $-32768,%eax
+        jl 2f
+        movw %ax,(%esi)
+        jmp 4f
+1:      movw $32767,(%esi)
+        jmp 3f
+2:      movw $-32768,(%esi)
+3:      incl %edi
+4:
+.L67:
+        addl $-64,%ebx
+        addl $-128,%ecx
+        addl $4,%esi
+        decl %ebp
+        jnz .L68
+        movl %edi,%eax
+        popl %ebx
+        popl %esi
+        popl %edi
+        popl %ebp
+        addl $12,%esp
+        ret
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/equalizer.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,79 @@
+#include "mpg123.h"
+
+void init_spline(float *x, float *y, int n, float *y2)
+{
+
+	int i, k;
+	float p, qn, sig, un, *u;
+	u = (float *) malloc(n * sizeof (float));
+
+	y2[0] = u[0] = 0.0;
+
+	for (i = 1; i < n - 1; i++)
+	{
+		sig = ((float) x[i] - x[i - 1]) / ((float) x[i + 1] - x[i - 1]);
+		p = sig * y2[i - 1] + 2.0;
+		y2[i] = (sig - 1.0) / p;
+		u[i] = (((float) y[i + 1] - y[i]) / (x[i + 1] - x[i])) -
+			(((float) y[i] - y[i - 1]) / (x[i] - x[i - 1]));
+		u[i] = (6.0 * u[i] / (x[i + 1] - x[i - 1]) - sig * u[i - 1]) / p;
+	}
+	qn = un = 0.0;
+
+	y2[n - 1] = (un - qn * u[n - 2]) / (qn * y2[n - 2] + 1.0);
+	for (k = n - 2; k >= 0; k--)
+		y2[k] = y2[k] * y2[k + 1] + u[k];
+	free(u);
+}
+
+float eval_spline(float xa[], float ya[], float y2a[], int n, float x)
+{
+	int klo, khi, k;
+	float h, b, a;
+
+	klo = 0;
+	khi = n - 1;
+	while (khi - klo > 1)
+	{
+		k = (khi + klo) >> 1;
+		if (xa[k] > x)
+			khi = k;
+		else
+			klo = k;
+	}
+	h = xa[khi] - xa[klo];
+	a = (xa[khi] - x) / h;
+	b = (x - xa[klo]) / h;
+	return (a * ya[klo] + b * ya[khi] + ((a * a * a - a) * y2a[klo] + (b * b * b - b) * y2a[khi])
+		* (h * h) / 6.0);
+}
+
+void mpg123_set_eq(int on, float preamp, float *b)
+{
+	float x[] =
+	{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, yf[10], val, band[10];
+	int bands[] =
+	{0, 4, 8, 16, 26, 78, 157, 313, 366, 418};
+	int i, j;
+
+	mpg123_info->eq_active = on;
+	if (mpg123_info->eq_active)
+	{
+		for (i = 0; i < 10; i++)
+		{
+			band[i] = b[i] + preamp;
+		}
+
+		init_spline(x, band, 10, yf);
+		for (i = 0; i < 9; i++)
+		{
+			for (j = bands[i]; j < bands[i + 1]; j++)
+			{
+				val = eval_spline(x, band, yf, 10, i + ((float) (j - bands[i]) * (1.0 / (bands[i + 1] - bands[i]))));
+				mpg123_info->eq_mul[j] = pow(2, val / 10.0);
+			}
+		}
+		for (i = bands[9]; i < 576; i++)
+			mpg123_info->eq_mul[i] = mpg123_info->eq_mul[bands[9] - 1];
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/huffman.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,332 @@
+/*
+ * huffman tables ... recalcualted to work with my optimzed
+ * decoder scheme (MH)
+ * 
+ * probably we could save a few bytes of memory, because the 
+ * smaller tables are often the part of a bigger table
+ */
+
+struct newhuff 
+{
+  unsigned int linbits;
+  short *table;
+};
+
+static short tab0[] = 
+{ 
+   0
+};
+
+static short tab1[] =
+{
+  -5,  -3,  -1,  17,   1,  16,   0
+};
+
+static short tab2[] =
+{
+ -15, -11,  -9,  -5,  -3,  -1,  34,   2,  18,  -1,  33,  32,  17,  -1,   1,
+  16,   0
+};
+
+static short tab3[] =
+{
+ -13, -11,  -9,  -5,  -3,  -1,  34,   2,  18,  -1,  33,  32,  16,  17,  -1,
+   1,   0
+};
+
+static short tab5[] =
+{
+ -29, -25, -23, -15,  -7,  -5,  -3,  -1,  51,  35,  50,  49,  -3,  -1,  19,
+   3,  -1,  48,  34,  -3,  -1,  18,  33,  -1,   2,  32,  17,  -1,   1,  16,
+   0
+};
+
+static short tab6[] =
+{
+ -25, -19, -13,  -9,  -5,  -3,  -1,  51,   3,  35,  -1,  50,  48,  -1,  19,
+  49,  -3,  -1,  34,   2,  18,  -3,  -1,  33,  32,   1,  -1,  17,  -1,  16,
+   0
+};
+
+static short tab7[] =
+{
+ -69, -65, -57, -39, -29, -17, -11,  -7,  -3,  -1,  85,  69,  -1,  84,  83,
+  -1,  53,  68,  -3,  -1,  37,  82,  21,  -5,  -1,  81,  -1,   5,  52,  -1,
+  80,  -1,  67,  51,  -5,  -3,  -1,  36,  66,  20,  -1,  65,  64, -11,  -7,
+  -3,  -1,   4,  35,  -1,  50,   3,  -1,  19,  49,  -3,  -1,  48,  34,  18,
+  -5,  -1,  33,  -1,   2,  32,  17,  -1,   1,  16,   0
+};
+
+static short tab8[] =
+{
+ -65, -63, -59, -45, -31, -19, -13,  -7,  -5,  -3,  -1,  85,  84,  69,  83,
+  -3,  -1,  53,  68,  37,  -3,  -1,  82,   5,  21,  -5,  -1,  81,  -1,  52,
+  67,  -3,  -1,  80,  51,  36,  -5,  -3,  -1,  66,  20,  65,  -3,  -1,   4,
+  64,  -1,  35,  50,  -9,  -7,  -3,  -1,  19,  49,  -1,   3,  48,  34,  -1,
+   2,  32,  -1,  18,  33,  17,  -3,  -1,   1,  16,   0
+};
+
+static short tab9[] =
+{
+ -63, -53, -41, -29, -19, -11,  -5,  -3,  -1,  85,  69,  53,  -1,  83,  -1,
+  84,   5,  -3,  -1,  68,  37,  -1,  82,  21,  -3,  -1,  81,  52,  -1,  67,
+  -1,  80,   4,  -7,  -3,  -1,  36,  66,  -1,  51,  64,  -1,  20,  65,  -5,
+  -3,  -1,  35,  50,  19,  -1,  49,  -1,   3,  48,  -5,  -3,  -1,  34,   2,
+  18,  -1,  33,  32,  -3,  -1,  17,   1,  -1,  16,   0
+};
+
+static short tab10[] =
+{
+-125,-121,-111, -83, -55, -35, -21, -13,  -7,  -3,  -1, 119, 103,  -1, 118,
+  87,  -3,  -1, 117, 102,  71,  -3,  -1, 116,  86,  -1, 101,  55,  -9,  -3,
+  -1, 115,  70,  -3,  -1,  85,  84,  99,  -1,  39, 114, -11,  -5,  -3,  -1,
+ 100,   7, 112,  -1,  98,  -1,  69,  53,  -5,  -1,   6,  -1,  83,  68,  23,
+ -17,  -5,  -1, 113,  -1,  54,  38,  -5,  -3,  -1,  37,  82,  21,  -1,  81,
+  -1,  52,  67,  -3,  -1,  22,  97,  -1,  96,  -1,   5,  80, -19, -11,  -7,
+  -3,  -1,  36,  66,  -1,  51,   4,  -1,  20,  65,  -3,  -1,  64,  35,  -1,
+  50,   3,  -3,  -1,  19,  49,  -1,  48,  34,  -7,  -3,  -1,  18,  33,  -1,
+   2,  32,  17,  -1,   1,  16,   0
+};
+
+static short tab11[] =
+{
+-121,-113, -89, -59, -43, -27, -17,  -7,  -3,  -1, 119, 103,  -1, 118, 117,
+  -3,  -1, 102,  71,  -1, 116,  -1,  87,  85,  -5,  -3,  -1,  86, 101,  55,
+  -1, 115,  70,  -9,  -7,  -3,  -1,  69,  84,  -1,  53,  83,  39,  -1, 114,
+  -1, 100,   7,  -5,  -1, 113,  -1,  23, 112,  -3,  -1,  54,  99,  -1,  96,
+  -1,  68,  37, -13,  -7,  -5,  -3,  -1,  82,   5,  21,  98,  -3,  -1,  38,
+   6,  22,  -5,  -1,  97,  -1,  81,  52,  -5,  -1,  80,  -1,  67,  51,  -1,
+  36,  66, -15, -11,  -7,  -3,  -1,  20,  65,  -1,   4,  64,  -1,  35,  50,
+  -1,  19,  49,  -5,  -3,  -1,   3,  48,  34,  33,  -5,  -1,  18,  -1,   2,
+  32,  17,  -3,  -1,   1,  16,   0
+};
+
+static short tab12[] =
+{
+-115, -99, -73, -45, -27, -17,  -9,  -5,  -3,  -1, 119, 103, 118,  -1,  87,
+ 117,  -3,  -1, 102,  71,  -1, 116, 101,  -3,  -1,  86,  55,  -3,  -1, 115,
+  85,  39,  -7,  -3,  -1, 114,  70,  -1, 100,  23,  -5,  -1, 113,  -1,   7,
+ 112,  -1,  54,  99, -13,  -9,  -3,  -1,  69,  84,  -1,  68,  -1,   6,   5,
+  -1,  38,  98,  -5,  -1,  97,  -1,  22,  96,  -3,  -1,  53,  83,  -1,  37,
+  82, -17,  -7,  -3,  -1,  21,  81,  -1,  52,  67,  -5,  -3,  -1,  80,   4,
+  36,  -1,  66,  20,  -3,  -1,  51,  65,  -1,  35,  50, -11,  -7,  -5,  -3,
+  -1,  64,   3,  48,  19,  -1,  49,  34,  -1,  18,  33,  -7,  -5,  -3,  -1,
+   2,  32,   0,  17,  -1,   1,  16
+};
+
+static short tab13[] =
+{
+-509,-503,-475,-405,-333,-265,-205,-153,-115, -83, -53, -35, -21, -13,  -9,
+  -7,  -5,  -3,  -1, 254, 252, 253, 237, 255,  -1, 239, 223,  -3,  -1, 238,
+ 207,  -1, 222, 191,  -9,  -3,  -1, 251, 206,  -1, 220,  -1, 175, 233,  -1,
+ 236, 221,  -9,  -5,  -3,  -1, 250, 205, 190,  -1, 235, 159,  -3,  -1, 249,
+ 234,  -1, 189, 219, -17,  -9,  -3,  -1, 143, 248,  -1, 204,  -1, 174, 158,
+  -5,  -1, 142,  -1, 127, 126, 247,  -5,  -1, 218,  -1, 173, 188,  -3,  -1,
+ 203, 246, 111, -15,  -7,  -3,  -1, 232,  95,  -1, 157, 217,  -3,  -1, 245,
+ 231,  -1, 172, 187,  -9,  -3,  -1,  79, 244,  -3,  -1, 202, 230, 243,  -1,
+  63,  -1, 141, 216, -21,  -9,  -3,  -1,  47, 242,  -3,  -1, 110, 156,  15,
+  -5,  -3,  -1, 201,  94, 171,  -3,  -1, 125, 215,  78, -11,  -5,  -3,  -1,
+ 200, 214,  62,  -1, 185,  -1, 155, 170,  -1,  31, 241, -23, -13,  -5,  -1,
+ 240,  -1, 186, 229,  -3,  -1, 228, 140,  -1, 109, 227,  -5,  -1, 226,  -1,
+  46,  14,  -1,  30, 225, -15,  -7,  -3,  -1, 224,  93,  -1, 213, 124,  -3,
+  -1, 199,  77,  -1, 139, 184,  -7,  -3,  -1, 212, 154,  -1, 169, 108,  -1,
+ 198,  61, -37, -21,  -9,  -5,  -3,  -1, 211, 123,  45,  -1, 210,  29,  -5,
+  -1, 183,  -1,  92, 197,  -3,  -1, 153, 122, 195,  -7,  -5,  -3,  -1, 167,
+ 151,  75, 209,  -3,  -1,  13, 208,  -1, 138, 168, -11,  -7,  -3,  -1,  76,
+ 196,  -1, 107, 182,  -1,  60,  44,  -3,  -1, 194,  91,  -3,  -1, 181, 137,
+  28, -43, -23, -11,  -5,  -1, 193,  -1, 152,  12,  -1, 192,  -1, 180, 106,
+  -5,  -3,  -1, 166, 121,  59,  -1, 179,  -1, 136,  90, -11,  -5,  -1,  43,
+  -1, 165, 105,  -1, 164,  -1, 120, 135,  -5,  -1, 148,  -1, 119, 118, 178,
+ -11,  -3,  -1,  27, 177,  -3,  -1,  11, 176,  -1, 150,  74,  -7,  -3,  -1,
+  58, 163,  -1,  89, 149,  -1,  42, 162, -47, -23,  -9,  -3,  -1,  26, 161,
+  -3,  -1,  10, 104, 160,  -5,  -3,  -1, 134,  73, 147,  -3,  -1,  57,  88,
+  -1, 133, 103,  -9,  -3,  -1,  41, 146,  -3,  -1,  87, 117,  56,  -5,  -1,
+ 131,  -1, 102,  71,  -3,  -1, 116,  86,  -1, 101, 115, -11,  -3,  -1,  25,
+ 145,  -3,  -1,   9, 144,  -1,  72, 132,  -7,  -5,  -1, 114,  -1,  70, 100,
+  40,  -1, 130,  24, -41, -27, -11,  -5,  -3,  -1,  55,  39,  23,  -1, 113,
+  -1,  85,   7,  -7,  -3,  -1, 112,  54,  -1,  99,  69,  -3,  -1,  84,  38,
+  -1,  98,  53,  -5,  -1, 129,  -1,   8, 128,  -3,  -1,  22,  97,  -1,   6,
+  96, -13,  -9,  -5,  -3,  -1,  83,  68,  37,  -1,  82,   5,  -1,  21,  81,
+  -7,  -3,  -1,  52,  67,  -1,  80,  36,  -3,  -1,  66,  51,  20, -19, -11,
+  -5,  -1,  65,  -1,   4,  64,  -3,  -1,  35,  50,  19,  -3,  -1,  49,   3,
+  -1,  48,  34,  -3,  -1,  18,  33,  -1,   2,  32,  -3,  -1,  17,   1,  16,
+   0
+};
+
+static short tab15[] =
+{
+-495,-445,-355,-263,-183,-115, -77, -43, -27, -13,  -7,  -3,  -1, 255, 239,
+  -1, 254, 223,  -1, 238,  -1, 253, 207,  -7,  -3,  -1, 252, 222,  -1, 237,
+ 191,  -1, 251,  -1, 206, 236,  -7,  -3,  -1, 221, 175,  -1, 250, 190,  -3,
+  -1, 235, 205,  -1, 220, 159, -15,  -7,  -3,  -1, 249, 234,  -1, 189, 219,
+  -3,  -1, 143, 248,  -1, 204, 158,  -7,  -3,  -1, 233, 127,  -1, 247, 173,
+  -3,  -1, 218, 188,  -1, 111,  -1, 174,  15, -19, -11,  -3,  -1, 203, 246,
+  -3,  -1, 142, 232,  -1,  95, 157,  -3,  -1, 245, 126,  -1, 231, 172,  -9,
+  -3,  -1, 202, 187,  -3,  -1, 217, 141,  79,  -3,  -1, 244,  63,  -1, 243,
+ 216, -33, -17,  -9,  -3,  -1, 230,  47,  -1, 242,  -1, 110, 240,  -3,  -1,
+  31, 241,  -1, 156, 201,  -7,  -3,  -1,  94, 171,  -1, 186, 229,  -3,  -1,
+ 125, 215,  -1,  78, 228, -15,  -7,  -3,  -1, 140, 200,  -1,  62, 109,  -3,
+  -1, 214, 227,  -1, 155, 185,  -7,  -3,  -1,  46, 170,  -1, 226,  30,  -5,
+  -1, 225,  -1,  14, 224,  -1,  93, 213, -45, -25, -13,  -7,  -3,  -1, 124,
+ 199,  -1,  77, 139,  -1, 212,  -1, 184, 154,  -7,  -3,  -1, 169, 108,  -1,
+ 198,  61,  -1, 211, 210,  -9,  -5,  -3,  -1,  45,  13,  29,  -1, 123, 183,
+  -5,  -1, 209,  -1,  92, 208,  -1, 197, 138, -17,  -7,  -3,  -1, 168,  76,
+  -1, 196, 107,  -5,  -1, 182,  -1, 153,  12,  -1,  60, 195,  -9,  -3,  -1,
+ 122, 167,  -1, 166,  -1, 192,  11,  -1, 194,  -1,  44,  91, -55, -29, -15,
+  -7,  -3,  -1, 181,  28,  -1, 137, 152,  -3,  -1, 193,  75,  -1, 180, 106,
+  -5,  -3,  -1,  59, 121, 179,  -3,  -1, 151, 136,  -1,  43,  90, -11,  -5,
+  -1, 178,  -1, 165,  27,  -1, 177,  -1, 176, 105,  -7,  -3,  -1, 150,  74,
+  -1, 164, 120,  -3,  -1, 135,  58, 163, -17,  -7,  -3,  -1,  89, 149,  -1,
+  42, 162,  -3,  -1,  26, 161,  -3,  -1,  10, 160, 104,  -7,  -3,  -1, 134,
+  73,  -1, 148,  57,  -5,  -1, 147,  -1, 119,   9,  -1,  88, 133, -53, -29,
+ -13,  -7,  -3,  -1,  41, 103,  -1, 118, 146,  -1, 145,  -1,  25, 144,  -7,
+  -3,  -1,  72, 132,  -1,  87, 117,  -3,  -1,  56, 131,  -1, 102,  71,  -7,
+  -3,  -1,  40, 130,  -1,  24, 129,  -7,  -3,  -1, 116,   8,  -1, 128,  86,
+  -3,  -1, 101,  55,  -1, 115,  70, -17,  -7,  -3,  -1,  39, 114,  -1, 100,
+  23,  -3,  -1,  85, 113,  -3,  -1,   7, 112,  54,  -7,  -3,  -1,  99,  69,
+  -1,  84,  38,  -3,  -1,  98,  22,  -3,  -1,   6,  96,  53, -33, -19,  -9,
+  -5,  -1,  97,  -1,  83,  68,  -1,  37,  82,  -3,  -1,  21,  81,  -3,  -1,
+   5,  80,  52,  -7,  -3,  -1,  67,  36,  -1,  66,  51,  -1,  65,  -1,  20,
+   4,  -9,  -3,  -1,  35,  50,  -3,  -1,  64,   3,  19,  -3,  -1,  49,  48,
+  34,  -9,  -7,  -3,  -1,  18,  33,  -1,   2,  32,  17,  -3,  -1,   1,  16,
+   0
+};
+
+static short tab16[] =
+{
+-509,-503,-461,-323,-103, -37, -27, -15,  -7,  -3,  -1, 239, 254,  -1, 223,
+ 253,  -3,  -1, 207, 252,  -1, 191, 251,  -5,  -1, 175,  -1, 250, 159,  -3,
+  -1, 249, 248, 143,  -7,  -3,  -1, 127, 247,  -1, 111, 246, 255,  -9,  -5,
+  -3,  -1,  95, 245,  79,  -1, 244, 243, -53,  -1, 240,  -1,  63, -29, -19,
+ -13,  -7,  -5,  -1, 206,  -1, 236, 221, 222,  -1, 233,  -1, 234, 217,  -1,
+ 238,  -1, 237, 235,  -3,  -1, 190, 205,  -3,  -1, 220, 219, 174, -11,  -5,
+  -1, 204,  -1, 173, 218,  -3,  -1, 126, 172, 202,  -5,  -3,  -1, 201, 125,
+  94, 189, 242, -93,  -5,  -3,  -1,  47,  15,  31,  -1, 241, -49, -25, -13,
+  -5,  -1, 158,  -1, 188, 203,  -3,  -1, 142, 232,  -1, 157, 231,  -7,  -3,
+  -1, 187, 141,  -1, 216, 110,  -1, 230, 156, -13,  -7,  -3,  -1, 171, 186,
+  -1, 229, 215,  -1,  78,  -1, 228, 140,  -3,  -1, 200,  62,  -1, 109,  -1,
+ 214, 155, -19, -11,  -5,  -3,  -1, 185, 170, 225,  -1, 212,  -1, 184, 169,
+  -5,  -1, 123,  -1, 183, 208, 227,  -7,  -3,  -1,  14, 224,  -1,  93, 213,
+  -3,  -1, 124, 199,  -1,  77, 139, -75, -45, -27, -13,  -7,  -3,  -1, 154,
+ 108,  -1, 198,  61,  -3,  -1,  92, 197,  13,  -7,  -3,  -1, 138, 168,  -1,
+ 153,  76,  -3,  -1, 182, 122,  60, -11,  -5,  -3,  -1,  91, 137,  28,  -1,
+ 192,  -1, 152, 121,  -1, 226,  -1,  46,  30, -15,  -7,  -3,  -1, 211,  45,
+  -1, 210, 209,  -5,  -1,  59,  -1, 151, 136,  29,  -7,  -3,  -1, 196, 107,
+  -1, 195, 167,  -1,  44,  -1, 194, 181, -23, -13,  -7,  -3,  -1, 193,  12,
+  -1,  75, 180,  -3,  -1, 106, 166, 179,  -5,  -3,  -1,  90, 165,  43,  -1,
+ 178,  27, -13,  -5,  -1, 177,  -1,  11, 176,  -3,  -1, 105, 150,  -1,  74,
+ 164,  -5,  -3,  -1, 120, 135, 163,  -3,  -1,  58,  89,  42, -97, -57, -33,
+ -19, -11,  -5,  -3,  -1, 149, 104, 161,  -3,  -1, 134, 119, 148,  -5,  -3,
+  -1,  73,  87, 103, 162,  -5,  -1,  26,  -1,  10, 160,  -3,  -1,  57, 147,
+  -1,  88, 133,  -9,  -3,  -1,  41, 146,  -3,  -1, 118,   9,  25,  -5,  -1,
+ 145,  -1, 144,  72,  -3,  -1, 132, 117,  -1,  56, 131, -21, -11,  -5,  -3,
+  -1, 102,  40, 130,  -3,  -1,  71, 116,  24,  -3,  -1, 129, 128,  -3,  -1,
+   8,  86,  55,  -9,  -5,  -1, 115,  -1, 101,  70,  -1,  39, 114,  -5,  -3,
+  -1, 100,  85,   7,  23, -23, -13,  -5,  -1, 113,  -1, 112,  54,  -3,  -1,
+  99,  69,  -1,  84,  38,  -3,  -1,  98,  22,  -1,  97,  -1,   6,  96,  -9,
+  -5,  -1,  83,  -1,  53,  68,  -1,  37,  82,  -1,  81,  -1,  21,   5, -33,
+ -23, -13,  -7,  -3,  -1,  52,  67,  -1,  80,  36,  -3,  -1,  66,  51,  20,
+  -5,  -1,  65,  -1,   4,  64,  -1,  35,  50,  -3,  -1,  19,  49,  -3,  -1,
+   3,  48,  34,  -3,  -1,  18,  33,  -1,   2,  32,  -3,  -1,  17,   1,  16,
+   0
+};
+
+static short tab24[] =
+{
+-451,-117, -43, -25, -15,  -7,  -3,  -1, 239, 254,  -1, 223, 253,  -3,  -1,
+ 207, 252,  -1, 191, 251,  -5,  -1, 250,  -1, 175, 159,  -1, 249, 248,  -9,
+  -5,  -3,  -1, 143, 127, 247,  -1, 111, 246,  -3,  -1,  95, 245,  -1,  79,
+ 244, -71,  -7,  -3,  -1,  63, 243,  -1,  47, 242,  -5,  -1, 241,  -1,  31,
+ 240, -25,  -9,  -1,  15,  -3,  -1, 238, 222,  -1, 237, 206,  -7,  -3,  -1,
+ 236, 221,  -1, 190, 235,  -3,  -1, 205, 220,  -1, 174, 234, -15,  -7,  -3,
+  -1, 189, 219,  -1, 204, 158,  -3,  -1, 233, 173,  -1, 218, 188,  -7,  -3,
+  -1, 203, 142,  -1, 232, 157,  -3,  -1, 217, 126,  -1, 231, 172, 255,-235,
+-143, -77, -45, -25, -15,  -7,  -3,  -1, 202, 187,  -1, 141, 216,  -5,  -3,
+  -1,  14, 224,  13, 230,  -5,  -3,  -1, 110, 156, 201,  -1,  94, 186,  -9,
+  -5,  -1, 229,  -1, 171, 125,  -1, 215, 228,  -3,  -1, 140, 200,  -3,  -1,
+  78,  46,  62, -15,  -7,  -3,  -1, 109, 214,  -1, 227, 155,  -3,  -1, 185,
+ 170,  -1, 226,  30,  -7,  -3,  -1, 225,  93,  -1, 213, 124,  -3,  -1, 199,
+  77,  -1, 139, 184, -31, -15,  -7,  -3,  -1, 212, 154,  -1, 169, 108,  -3,
+  -1, 198,  61,  -1, 211,  45,  -7,  -3,  -1, 210,  29,  -1, 123, 183,  -3,
+  -1, 209,  92,  -1, 197, 138, -17,  -7,  -3,  -1, 168, 153,  -1,  76, 196,
+  -3,  -1, 107, 182,  -3,  -1, 208,  12,  60,  -7,  -3,  -1, 195, 122,  -1,
+ 167,  44,  -3,  -1, 194,  91,  -1, 181,  28, -57, -35, -19,  -7,  -3,  -1,
+ 137, 152,  -1, 193,  75,  -5,  -3,  -1, 192,  11,  59,  -3,  -1, 176,  10,
+  26,  -5,  -1, 180,  -1, 106, 166,  -3,  -1, 121, 151,  -3,  -1, 160,   9,
+ 144,  -9,  -3,  -1, 179, 136,  -3,  -1,  43,  90, 178,  -7,  -3,  -1, 165,
+  27,  -1, 177, 105,  -1, 150, 164, -17,  -9,  -5,  -3,  -1,  74, 120, 135,
+  -1,  58, 163,  -3,  -1,  89, 149,  -1,  42, 162,  -7,  -3,  -1, 161, 104,
+  -1, 134, 119,  -3,  -1,  73, 148,  -1,  57, 147, -63, -31, -15,  -7,  -3,
+  -1,  88, 133,  -1,  41, 103,  -3,  -1, 118, 146,  -1,  25, 145,  -7,  -3,
+  -1,  72, 132,  -1,  87, 117,  -3,  -1,  56, 131,  -1, 102,  40, -17,  -7,
+  -3,  -1, 130,  24,  -1,  71, 116,  -5,  -1, 129,  -1,   8, 128,  -1,  86,
+ 101,  -7,  -5,  -1,  23,  -1,   7, 112, 115,  -3,  -1,  55,  39, 114, -15,
+  -7,  -3,  -1,  70, 100,  -1,  85, 113,  -3,  -1,  54,  99,  -1,  69,  84,
+  -7,  -3,  -1,  38,  98,  -1,  22,  97,  -5,  -3,  -1,   6,  96,  53,  -1,
+  83,  68, -51, -37, -23, -15,  -9,  -3,  -1,  37,  82,  -1,  21,  -1,   5,
+  80,  -1,  81,  -1,  52,  67,  -3,  -1,  36,  66,  -1,  51,  20,  -9,  -5,
+  -1,  65,  -1,   4,  64,  -1,  35,  50,  -1,  19,  49,  -7,  -5,  -3,  -1,
+   3,  48,  34,  18,  -1,  33,  -1,   2,  32,  -3,  -1,  17,   1,  -1,  16,
+   0
+};
+
+static short tab_c0[] =
+{
+ -29, -21, -13,  -7,  -3,  -1,  11,  15,  -1,  13,  14,  -3,  -1,   7,   5,
+   9,  -3,  -1,   6,   3,  -1,  10,  12,  -3,  -1,   2,   1,  -1,   4,   8,
+   0
+};
+
+static short tab_c1[] =
+{
+ -15,  -7,  -3,  -1,  15,  14,  -1,  13,  12,  -3,  -1,  11,  10,  -1,   9,
+   8,  -7,  -3,  -1,   7,   6,  -1,   5,   4,  -3,  -1,   3,   2,  -1,   1,
+   0
+};
+
+
+
+static struct newhuff ht[] = 
+{
+ { /* 0 */ 0 , tab0  } ,
+ { /* 2 */ 0 , tab1  } ,
+ { /* 3 */ 0 , tab2  } ,
+ { /* 3 */ 0 , tab3  } ,
+ { /* 0 */ 0 , tab0  } ,
+ { /* 4 */ 0 , tab5  } ,
+ { /* 4 */ 0 , tab6  } ,
+ { /* 6 */ 0 , tab7  } ,
+ { /* 6 */ 0 , tab8  } ,
+ { /* 6 */ 0 , tab9  } ,
+ { /* 8 */ 0 , tab10 } ,
+ { /* 8 */ 0 , tab11 } ,
+ { /* 8 */ 0 , tab12 } ,
+ { /* 16 */ 0 , tab13 } ,
+ { /* 0  */ 0 , tab0  } ,
+ { /* 16 */ 0 , tab15 } ,
+
+ { /* 16 */ 1 , tab16 } ,
+ { /* 16 */ 2 , tab16 } ,
+ { /* 16 */ 3 , tab16 } ,
+ { /* 16 */ 4 , tab16 } ,
+ { /* 16 */ 6 , tab16 } ,
+ { /* 16 */ 8 , tab16 } ,
+ { /* 16 */ 10, tab16 } ,
+ { /* 16 */ 13, tab16 } ,
+ { /* 16 */ 4 , tab24 } ,
+ { /* 16 */ 5 , tab24 } ,
+ { /* 16 */ 6 , tab24 } ,
+ { /* 16 */ 7 , tab24 } ,
+ { /* 16 */ 8 , tab24 } ,
+ { /* 16 */ 9 , tab24 } ,
+ { /* 16 */ 11, tab24 } ,
+ { /* 16 */ 13, tab24 }
+};
+
+static struct newhuff htc[] = 
+{
+ { /* 1 , 1 , */ 0 , tab_c0 } ,
+ { /* 1 , 1 , */ 0 , tab_c1 }
+};
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/l2tables.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,154 @@
+/*
+ * Layer 2 Alloc tables .. 
+ * most other tables are calculated on program start (which is (of course)
+ * not ISO-conform) .. 
+ * Layer-3 huffman table is in huffman.h
+ */
+
+struct al_table alloc_0[] = {
+	{4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
+	{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
+	{4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
+	{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
+	{4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
+	{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+	{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+	{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+	{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+	{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+	{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+	{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+	{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+	{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{2,0},{5,3},{7,5},{16,-32767},
+	{2,0},{5,3},{7,5},{16,-32767},
+	{2,0},{5,3},{7,5},{16,-32767},
+	{2,0},{5,3},{7,5},{16,-32767} };
+
+struct al_table alloc_1[] = {
+	{4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
+	{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
+	{4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
+	{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
+	{4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
+	{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+	{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+	{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+	{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+	{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+	{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+	{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+	{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+	{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+	{2,0},{5,3},{7,5},{16,-32767},
+	{2,0},{5,3},{7,5},{16,-32767},
+	{2,0},{5,3},{7,5},{16,-32767},
+	{2,0},{5,3},{7,5},{16,-32767},
+	{2,0},{5,3},{7,5},{16,-32767},
+	{2,0},{5,3},{7,5},{16,-32767},
+	{2,0},{5,3},{7,5},{16,-32767} };
+
+struct al_table alloc_2[] = {
+	{4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
+	{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
+	{4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
+	{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63} };
+
+struct al_table alloc_3[] = {
+	{4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
+	{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
+	{4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
+	{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63} };
+
+struct al_table alloc_4[] = {
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+		{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+		{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+		{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
+	{4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+		{9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+	{2,0},{5,3},{7,5},{10,9},
+	{2,0},{5,3},{7,5},{10,9},
+	{2,0},{5,3},{7,5},{10,9},
+	{2,0},{5,3},{7,5},{10,9},
+	{2,0},{5,3},{7,5},{10,9},
+	{2,0},{5,3},{7,5},{10,9},
+	{2,0},{5,3},{7,5},{10,9},
+	{2,0},{5,3},{7,5},{10,9},
+	{2,0},{5,3},{7,5},{10,9},
+	{2,0},{5,3},{7,5},{10,9},
+	{2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9}  };
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/layer2.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,295 @@
+/* 
+ * Mpeg Layer-2 audio decoder 
+ * --------------------------
+ * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
+ *
+ */
+
+//#include "mpg123.h"
+#include "l2tables.h"
+
+static int grp_3tab[32 * 3] = { 0, };   /* used: 27 */
+static int grp_5tab[128 * 3] = { 0, };  /* used: 125 */
+static int grp_9tab[1024 * 3] = { 0, }; /* used: 729 */
+
+static real muls[27][64];	/* also used by layer 1 */
+
+static void init_layer2(void)
+{
+  static double mulmul[27] = {
+    0.0 , -2.0/3.0 , 2.0/3.0 ,
+    2.0/7.0 , 2.0/15.0 , 2.0/31.0, 2.0/63.0 , 2.0/127.0 , 2.0/255.0 ,
+    2.0/511.0 , 2.0/1023.0 , 2.0/2047.0 , 2.0/4095.0 , 2.0/8191.0 ,
+    2.0/16383.0 , 2.0/32767.0 , 2.0/65535.0 ,
+    -4.0/5.0 , -2.0/5.0 , 2.0/5.0, 4.0/5.0 ,
+    -8.0/9.0 , -4.0/9.0 , -2.0/9.0 , 2.0/9.0 , 4.0/9.0 , 8.0/9.0 };
+  static int base[3][9] = {
+     { 1 , 0, 2 , } ,
+     { 17, 18, 0 , 19, 20 , } ,
+     { 21, 1, 22, 23, 0, 24, 25, 2, 26 } };
+  int i,j,k,l,len;
+  real *table;
+  static int tablen[3] = { 3 , 5 , 9 };
+  static int *itable,*tables[3] = { grp_3tab , grp_5tab , grp_9tab };
+
+  for(i=0;i<3;i++)
+  {
+    itable = tables[i];
+    len = tablen[i];
+    for(j=0;j<len;j++)
+      for(k=0;k<len;k++)
+        for(l=0;l<len;l++)
+        {
+          *itable++ = base[i][l];
+          *itable++ = base[i][k];
+          *itable++ = base[i][j];
+        }
+  }
+
+  for(k=0;k<27;k++)
+  {
+    double m=mulmul[k];
+    table = muls[k];
+    for(j=3,i=0;i<63;i++,j--)
+      *table++ = m * pow(2.0,(double) j / 3.0);
+    *table++ = 0.0;
+  }
+}
+
+
+static void II_step_one(unsigned int *bit_alloc,int *scale,struct frame *fr)
+{
+    int stereo = fr->stereo-1;
+    int sblimit = fr->II_sblimit;
+    int jsbound = fr->jsbound;
+    int sblimit2 = fr->II_sblimit<<stereo;
+    struct al_table *alloc1 = fr->alloc;
+    int i;
+    static unsigned int scfsi_buf[64];
+    unsigned int *scfsi,*bita;
+    int sc,step;
+
+    bita = bit_alloc;
+    if(stereo)
+    {
+      for (i=jsbound;i;i--,alloc1+=(1<<step))
+      {
+        *bita++ = (char) getbits(step=alloc1->bits);
+        *bita++ = (char) getbits(step);
+      }
+      for (i=sblimit-jsbound;i;i--,alloc1+=(1<<step))
+      {
+        bita[0] = (char) getbits(step=alloc1->bits);
+        bita[1] = bita[0];
+        bita+=2;
+      }
+      bita = bit_alloc;
+      scfsi=scfsi_buf;
+      for (i=sblimit2;i;i--)
+        if (*bita++)
+          *scfsi++ = (char) getbits_fast(2);
+    }
+    else /* mono */
+    {
+      for (i=sblimit;i;i--,alloc1+=(1<<step))
+        *bita++ = (char) getbits(step=alloc1->bits);
+      bita = bit_alloc;
+      scfsi=scfsi_buf;
+      for (i=sblimit;i;i--)
+        if (*bita++)
+          *scfsi++ = (char) getbits_fast(2);
+    }
+
+    bita = bit_alloc;
+    scfsi=scfsi_buf;
+    for (i=sblimit2;i;i--) 
+      if (*bita++)
+        switch (*scfsi++) 
+        {
+          case 0: 
+                *scale++ = getbits_fast(6);
+                *scale++ = getbits_fast(6);
+                *scale++ = getbits_fast(6);
+                break;
+          case 1 : 
+                *scale++ = sc = getbits_fast(6);
+                *scale++ = sc;
+                *scale++ = getbits_fast(6);
+                break;
+          case 2: 
+                *scale++ = sc = getbits_fast(6);
+                *scale++ = sc;
+                *scale++ = sc;
+                break;
+          default:              /* case 3 */
+                *scale++ = getbits_fast(6);
+                *scale++ = sc = getbits_fast(6);
+                *scale++ = sc;
+                break;
+        }
+
+}
+
+static void II_step_two(unsigned int *bit_alloc,real fraction[2][4][SBLIMIT],int *scale,struct frame *fr,int x1)
+{
+    int i,j,k,ba;
+    int stereo = fr->stereo;
+    int sblimit = fr->II_sblimit;
+    int jsbound = fr->jsbound;
+    struct al_table *alloc2,*alloc1 = fr->alloc;
+    unsigned int *bita=bit_alloc;
+    int d1,step;
+
+    for (i=0;i<jsbound;i++,alloc1+=(1<<step))
+    {
+      step = alloc1->bits;
+      for (j=0;j<stereo;j++)
+      {
+        if ( (ba=*bita++) ) 
+        {
+          k=(alloc2 = alloc1+ba)->bits;
+          if( (d1=alloc2->d) < 0) 
+          {
+            real cm=muls[k][scale[x1]];
+            fraction[j][0][i] = ((real) ((int)getbits(k) + d1)) * cm;
+            fraction[j][1][i] = ((real) ((int)getbits(k) + d1)) * cm;
+            fraction[j][2][i] = ((real) ((int)getbits(k) + d1)) * cm;
+          }        
+          else 
+          {
+            static int *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab };
+            unsigned int idx,*tab,m=scale[x1];
+            idx = (unsigned int) getbits(k);
+            tab = (unsigned int *) (table[d1] + idx + idx + idx);
+            fraction[j][0][i] = muls[*tab++][m];
+            fraction[j][1][i] = muls[*tab++][m];
+            fraction[j][2][i] = muls[*tab][m];  
+          }
+          scale+=3;
+        }
+        else
+          fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0;
+      }
+    }
+
+    for (i=jsbound;i<sblimit;i++,alloc1+=(1<<step))
+    {
+      step = alloc1->bits;
+      bita++;	/* channel 1 and channel 2 bitalloc are the same */
+      if ( (ba=*bita++) )
+      {
+        k=(alloc2 = alloc1+ba)->bits;
+        if( (d1=alloc2->d) < 0)
+        {
+          real cm;
+          cm=muls[k][scale[x1+3]];
+          fraction[1][0][i] = (fraction[0][0][i] = (real) ((int)getbits(k) + d1) ) * cm;
+          fraction[1][1][i] = (fraction[0][1][i] = (real) ((int)getbits(k) + d1) ) * cm;
+          fraction[1][2][i] = (fraction[0][2][i] = (real) ((int)getbits(k) + d1) ) * cm;
+          cm=muls[k][scale[x1]];
+          fraction[0][0][i] *= cm; fraction[0][1][i] *= cm; fraction[0][2][i] *= cm;
+        }
+        else
+        {
+          static int *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab };
+          unsigned int idx,*tab,m1,m2;
+          m1 = scale[x1]; m2 = scale[x1+3];
+          idx = (unsigned int) getbits(k);
+          tab = (unsigned int *) (table[d1] + idx + idx + idx);
+          fraction[0][0][i] = muls[*tab][m1]; fraction[1][0][i] = muls[*tab++][m2];
+          fraction[0][1][i] = muls[*tab][m1]; fraction[1][1][i] = muls[*tab++][m2];
+          fraction[0][2][i] = muls[*tab][m1]; fraction[1][2][i] = muls[*tab][m2];
+        }
+        scale+=6;
+      }
+      else {
+        fraction[0][0][i] = fraction[0][1][i] = fraction[0][2][i] =
+        fraction[1][0][i] = fraction[1][1][i] = fraction[1][2][i] = 0.0;
+      }
+/* 
+   should we use individual scalefac for channel 2 or
+   is the current way the right one , where we just copy channel 1 to
+   channel 2 ?? 
+   The current 'strange' thing is, that we throw away the scalefac
+   values for the second channel ...!!
+-> changed .. now we use the scalefac values of channel one !! 
+*/
+    }
+
+    if(sblimit > (fr->down_sample_sblimit) )
+      sblimit = fr->down_sample_sblimit;
+
+    for(i=sblimit;i<SBLIMIT;i++)
+      for (j=0;j<stereo;j++)
+        fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0;
+
+}
+
+static void II_select_table(struct frame *fr)
+{
+  static int translate[3][2][16] =
+   { { { 0,2,2,2,2,2,2,0,0,0,1,1,1,1,1,0 } ,
+       { 0,2,2,0,0,0,1,1,1,1,1,1,1,1,1,0 } } ,
+     { { 0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0 } ,
+       { 0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0 } } ,
+     { { 0,3,3,3,3,3,3,0,0,0,1,1,1,1,1,0 } ,
+       { 0,3,3,0,0,0,1,1,1,1,1,1,1,1,1,0 } } };
+
+  int table,sblim;
+  static struct al_table *tables[5] =
+       { alloc_0, alloc_1, alloc_2, alloc_3 , alloc_4 };
+  static int sblims[5] = { 27 , 30 , 8, 12 , 30 };
+
+  if(fr->lsf)
+    table = 4;
+  else
+    table = translate[fr->sampling_frequency][2-fr->stereo][fr->bitrate_index];
+  sblim = sblims[table];
+
+  fr->alloc      = tables[table];
+  fr->II_sblimit = sblim;
+}
+
+
+int do_layer2(struct frame *fr,int outmode)
+{
+  int clip=0;
+  int i,j;
+  int stereo = fr->stereo;
+  real fraction[2][4][SBLIMIT]; /* pick_table clears unused subbands */
+  unsigned int bit_alloc[64];
+  int scale[192];
+  int single = fr->single;
+
+  II_select_table(fr);
+  fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
+     (fr->mode_ext<<2)+4 : fr->II_sblimit;
+
+  if(stereo == 1 || single == 3)
+    single = 0;
+
+  II_step_one(bit_alloc, scale, fr);
+
+  for (i=0;i<SCALE_BLOCK;i++) 
+  {
+    II_step_two(bit_alloc,fraction,scale,fr,i>>2);
+    for (j=0;j<3;j++) 
+    {
+      if(single >= 0)
+      {
+        clip += (fr->synth_mono) (fraction[single][j],pcm_sample,&pcm_point);
+      }
+      else {
+          int p1 = pcm_point;
+          clip += (fr->synth) (fraction[0][j],0,pcm_sample,&p1);
+          clip += (fr->synth) (fraction[1][j],1,pcm_sample,&pcm_point);
+      }
+
+//      if(pcm_point >= audiobufsize) audio_flush(outmode,ai);
+    }
+  }
+
+  return clip;
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/layer3.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,1703 @@
+
+/*
+ * Mpeg Layer-3 audio decoder 
+ * --------------------------
+ * copyright (c) 1995,1996,1997 by Michael Hipp.
+ * All rights reserved. See also 'README'
+ *
+ * - I'm currently working on that .. needs a few more optimizations,
+ *   though the code is now fast enough to run in realtime on a 100Mhz 486
+ * - a few personal notes are in german .. 
+ *
+ * used source: 
+ *   mpeg1_iis package
+ */ 
+
+static real ispow[8207];
+static real aa_ca[8],aa_cs[8];
+static real COS1[12][6];
+static real win[4][36];
+static real win1[4][36];
+
+#define GP2MAX (256+118+4)
+static real gainpow2[GP2MAX];
+
+static real nCOS9[9];
+static real COS6_1,COS6_2;
+static real tfcos36[9];
+static real tfcos12[3];
+#ifdef NEW_DCT9
+static real cos9[3],cos18[3];
+#endif
+
+struct bandInfoStruct {
+  int longIdx[23];
+  int longDiff[22];
+  int shortIdx[14];
+  int shortDiff[13];
+};
+
+int longLimit[9][23];
+int shortLimit[9][14];
+
+struct bandInfoStruct bandInfo[9] = {
+
+/* MPEG 1.0 */
+ { {0,4,8,12,16,20,24,30,36,44,52,62,74, 90,110,134,162,196,238,288,342,418,576},
+   {4,4,4,4,4,4,6,6,8, 8,10,12,16,20,24,28,34,42,50,54, 76,158},
+   {0,4*3,8*3,12*3,16*3,22*3,30*3,40*3,52*3,66*3, 84*3,106*3,136*3,192*3},
+   {4,4,4,4,6,8,10,12,14,18,22,30,56} } ,
+
+ { {0,4,8,12,16,20,24,30,36,42,50,60,72, 88,106,128,156,190,230,276,330,384,576},
+   {4,4,4,4,4,4,6,6,6, 8,10,12,16,18,22,28,34,40,46,54, 54,192},
+   {0,4*3,8*3,12*3,16*3,22*3,28*3,38*3,50*3,64*3, 80*3,100*3,126*3,192*3},
+   {4,4,4,4,6,6,10,12,14,16,20,26,66} } ,
+
+ { {0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576} ,
+	{4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102, 26} ,
+	{0,4*3,8*3,12*3,16*3,22*3,30*3,42*3,58*3,78*3,104*3,138*3,180*3,192*3} ,
+   {4,4,4,4,6,8,12,16,20,26,34,42,12} }  ,
+
+/* MPEG 2.0 */
+ { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
+	{6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 } ,
+   {0,4*3,8*3,12*3,18*3,24*3,32*3,42*3,56*3,74*3,100*3,132*3,174*3,192*3} ,
+   {4,4,4,6,6,8,10,14,18,26,32,42,18 } } ,
+
+ { {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,330,394,464,540,576},
+   {6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,52,64,70,76,36 } ,
+   {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,136*3,180*3,192*3} ,
+   {4,4,4,6,8,10,12,14,18,24,32,44,12 } } ,
+
+ { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
+   {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 },
+   {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,134*3,174*3,192*3},
+   {4,4,4,6,8,10,12,14,18,24,30,40,18 } } ,
+
+/* MPEG 2.5 */
+ { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} ,
+	{6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54},
+   {0,12,24,36,54,78,108,144,186,240,312,402,522,576},
+   {4,4,4,6,8,10,12,14,18,24,30,40,18} },
+
+ { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} ,
+   {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54},
+	{0,12,24,36,54,78,108,144,186,240,312,402,522,576},
+   {4,4,4,6,8,10,12,14,18,24,30,40,18} },
+
+ { {0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576},
+   {12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2},
+   {0, 24, 48, 72,108,156,216,288,372,480,486,492,498,576},
+   {8,8,8,12,16,20,24,28,36,2,2,2,26} } ,
+};
+
+static int mapbuf0[9][152];
+static int mapbuf1[9][156];
+static int mapbuf2[9][44];
+static int *map[9][3];
+static int *mapend[9][3];
+
+static unsigned int n_slen2[512]; /* MPEG 2.0 slen for 'normal' mode */
+static unsigned int i_slen2[256]; /* MPEG 2.0 slen for intensity stereo */
+
+static real tan1_1[16],tan2_1[16],tan1_2[16],tan2_2[16];
+static real pow1_1[2][16],pow2_1[2][16],pow1_2[2][16],pow2_2[2][16];
+
+/*
+ * init tables for layer-3
+ */
+void init_layer3(int down_sample_sblimit)
+{
+  int i,j,k,l;
+
+  for(i=-256;i<118+4;i++)
+    gainpow2[i+256] = pow((double)2.0,-0.25 * (double) (i+210) );
+
+  for(i=0;i<8207;i++)
+    ispow[i] = pow((double)i,(double)4.0/3.0);
+
+  for (i=0;i<8;i++)
+  {
+    static double Ci[8]={-0.6,-0.535,-0.33,-0.185,-0.095,-0.041,-0.0142,-0.0037};
+    double sq=sqrt(1.0+Ci[i]*Ci[i]);
+    aa_cs[i] = 1.0/sq;
+    aa_ca[i] = Ci[i]/sq;
+  }
+
+  for(i=0;i<18;i++)
+  {
+    win[0][i]    = win[1][i]    = 0.5 * sin( M_PI / 72.0 * (double) (2*(i+0) +1) ) / cos ( M_PI * (double) (2*(i+0) +19) / 72.0 );
+    win[0][i+18] = win[3][i+18] = 0.5 * sin( M_PI / 72.0 * (double) (2*(i+18)+1) ) / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 );
+  }
+  for(i=0;i<6;i++)
+  {
+    win[1][i+18] = 0.5 / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 );
+    win[3][i+12] = 0.5 / cos ( M_PI * (double) (2*(i+12)+19) / 72.0 );
+    win[1][i+24] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+13) ) / cos ( M_PI * (double) (2*(i+24)+19) / 72.0 );
+    win[1][i+30] = win[3][i] = 0.0;
+    win[3][i+6 ] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+1) )  / cos ( M_PI * (double) (2*(i+6 )+19) / 72.0 );
+  }
+
+  for(i=0;i<9;i++)
+    nCOS9[i] = cos( M_PI / 18.0 * (double) i);
+
+  for(i=0;i<9;i++)
+    tfcos36[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 36.0 );
+  for(i=0;i<3;i++)
+    tfcos12[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 12.0 );
+
+  COS6_1 = cos( M_PI / 6.0 * (double) 1);
+  COS6_2 = cos( M_PI / 6.0 * (double) 2);
+
+#ifdef NEW_DCT9
+  cos9[0] = cos(1.0*M_PI/9.0);
+  cos9[1] = cos(5.0*M_PI/9.0);
+  cos9[2] = cos(7.0*M_PI/9.0);
+  cos18[0] = cos(1.0*M_PI/18.0);
+  cos18[1] = cos(11.0*M_PI/18.0);
+  cos18[2] = cos(13.0*M_PI/18.0);
+#endif
+
+  for(i=0;i<12;i++)
+  {
+    win[2][i]  = 0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*i+7) / 24.0 );
+    for(j=0;j<6;j++)
+      COS1[i][j] = cos( M_PI / 24.0 * (double) ((2*i+7)*(2*j+1)) );
+  }
+
+  for(j=0;j<4;j++) {
+    static int len[4] = { 36,36,12,36 };
+    for(i=0;i<len[j];i+=2)
+      win1[j][i] = + win[j][i];
+    for(i=1;i<len[j];i+=2)
+      win1[j][i] = - win[j][i];
+  }
+
+  for(i=0;i<16;i++)
+  {
+    double t = tan( (double) i * M_PI / 12.0 );
+    tan1_1[i] = t / (1.0+t);
+    tan2_1[i] = 1.0 / (1.0 + t);
+    tan1_2[i] = M_SQRT2 * t / (1.0+t);
+    tan2_2[i] = M_SQRT2 / (1.0 + t);
+
+    for(j=0;j<2;j++) {
+      double base = pow(2.0,-0.25*(j+1.0));
+      double p1=1.0,p2=1.0;
+      if(i > 0) {
+        if( i & 1 )
+          p1 = pow(base,(i+1.0)*0.5);
+        else
+          p2 = pow(base,i*0.5);
+      }
+      pow1_1[j][i] = p1;
+      pow2_1[j][i] = p2;
+      pow1_2[j][i] = M_SQRT2 * p1;
+      pow2_2[j][i] = M_SQRT2 * p2;
+    }
+  }
+
+  for(j=0;j<9;j++)
+  {
+   struct bandInfoStruct *bi = &bandInfo[j];
+   int *mp;
+   int cb,lwin;
+   int *bdf;
+
+   mp = map[j][0] = mapbuf0[j];
+   bdf = bi->longDiff;
+   for(i=0,cb = 0; cb < 8 ; cb++,i+=*bdf++) {
+     *mp++ = (*bdf) >> 1;
+     *mp++ = i;
+     *mp++ = 3;
+     *mp++ = cb;
+   }
+   bdf = bi->shortDiff+3;
+   for(cb=3;cb<13;cb++) {
+     int l = (*bdf++) >> 1;
+     for(lwin=0;lwin<3;lwin++) {
+       *mp++ = l;
+       *mp++ = i + lwin;
+       *mp++ = lwin;
+       *mp++ = cb;
+     }
+     i += 6*l;
+   }
+   mapend[j][0] = mp;
+
+   mp = map[j][1] = mapbuf1[j];
+   bdf = bi->shortDiff+0;
+   for(i=0,cb=0;cb<13;cb++) {
+     int l = (*bdf++) >> 1;
+     for(lwin=0;lwin<3;lwin++) {
+       *mp++ = l;
+       *mp++ = i + lwin;
+       *mp++ = lwin;
+       *mp++ = cb;
+     }
+     i += 6*l;
+   }
+   mapend[j][1] = mp;
+
+   mp = map[j][2] = mapbuf2[j];
+   bdf = bi->longDiff;
+   for(cb = 0; cb < 22 ; cb++) {
+     *mp++ = (*bdf++) >> 1;
+     *mp++ = cb;
+   }
+   mapend[j][2] = mp;
+
+  }
+
+  for(j=0;j<9;j++) {
+    for(i=0;i<23;i++) {
+      longLimit[j][i] = (bandInfo[j].longIdx[i] - 1 + 8) / 18 + 1;
+      if(longLimit[j][i] > (down_sample_sblimit) )
+        longLimit[j][i] = down_sample_sblimit;
+    }
+    for(i=0;i<14;i++) {
+      shortLimit[j][i] = (bandInfo[j].shortIdx[i] - 1) / 18 + 1;
+      if(shortLimit[j][i] > (down_sample_sblimit) )
+        shortLimit[j][i] = down_sample_sblimit;
+    }
+  }
+
+  for(i=0;i<5;i++) {
+    for(j=0;j<6;j++) {
+      for(k=0;k<6;k++) {
+        int n = k + j * 6 + i * 36;
+        i_slen2[n] = i|(j<<3)|(k<<6)|((long)3<<12);
+      }
+    }
+  }
+  for(i=0;i<4;i++) {
+    for(j=0;j<4;j++) {
+      for(k=0;k<4;k++) {
+        int n = k + j * 4 + i * 16;
+        i_slen2[n+180] = i|(j<<3)|(k<<6)|((long)4<<12);
+      }
+    }
+  }
+  for(i=0;i<4;i++) {
+    for(j=0;j<3;j++) {
+      int n = j + i * 3;
+      i_slen2[n+244] = i|(j<<3) | ((long)5<<12);
+      n_slen2[n+500] = i|(j<<3) | ((long)2<<12) | ((long)1<<15);
+    }
+  }
+
+  for(i=0;i<5;i++) {
+    for(j=0;j<5;j++) {
+      for(k=0;k<4;k++) {
+        for(l=0;l<4;l++) {
+          int n = l + k * 4 + j * 16 + i * 80;
+          n_slen2[n] = i|(j<<3)|(k<<6)|(l<<9)|((long)0<<12);
+        }
+      }
+    }
+  }
+  for(i=0;i<5;i++) {
+    for(j=0;j<5;j++) {
+      for(k=0;k<4;k++) {
+        int n = k + j * 4 + i * 20;
+        n_slen2[n+400] = i|(j<<3)|(k<<6)|((long)1<<12);
+      }
+    }
+  }
+} /* init_layer3() */
+
+/* ========================== READ FRAME DATA ========================= */
+
+#if 1
+LOCAL real Gainpow2(int i){
+//  if(i<0) i=0; else
+//  if(i>=GP2MAX) i=GP2MAX-1;
+//  return gainpow2[i];
+  return gainpow2[((i)<0)?0:( ((i)<GP2MAX)?(i):(GP2MAX-1) )];
+}
+#else
+#define Gainpow2(i) gainpow2[((i)<0)?0:( ((i)<GP2MAX)?(i):(GP2MAX-1) )]
+#endif
+
+/*
+ * read additional side information
+ */
+static void III_get_side_info_1(struct III_sideinfo *si,int stereo,
+ int ms_stereo,long sfreq,int single)
+{
+   int ch, gr;
+   int powdiff = (single == 3) ? 4 : 0;
+
+   si->main_data_begin = getbits(9);
+
+   if (stereo == 1)
+     si->private_bits = getbits_fast(5);
+   else 
+     si->private_bits = getbits_fast(3);
+
+   for (ch=0; ch<stereo; ch++) {
+       si->ch[ch].gr[0].scfsi = -1;
+       si->ch[ch].gr[1].scfsi = getbits_fast(4);
+   }
+
+   for (gr=0; gr<2; gr++) {
+     for (ch=0; ch<stereo; ch++) {
+       register struct gr_info_s *gr_info = &(si->ch[ch].gr[gr]);
+
+       gr_info->part2_3_length = getbits(12);
+       gr_info->big_values = getbits(9);
+       if(gr_info->big_values > 288) {
+          printf("\rbig_values too large!                                                        \n");
+          gr_info->big_values = 288;
+       }
+       gr_info->pow2gain = 256 - getbits_fast(8) + powdiff;
+       if(ms_stereo) gr_info->pow2gain += 2;
+       gr_info->scalefac_compress = getbits_fast(4);
+
+       if(get1bit()) {
+         /* window-switching flag==1  (block_Type!=0)  */
+         int i;
+         gr_info->block_type = getbits_fast(2);
+         gr_info->mixed_block_flag = get1bit();
+         gr_info->table_select[0] = getbits_fast(5);
+         gr_info->table_select[1] = getbits_fast(5);
+         /*
+          * table_select[2] not needed, because there is no region2,
+          * but to satisfy some verifications tools we set it either.
+          */
+         gr_info->table_select[2] = 0;
+         for(i=0;i<3;i++)
+           gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(3)<<3);
+
+         if(gr_info->block_type == 0) {
+           printf("\rBlocktype == 0 and window-switching == 1 not allowed.                        \n");
+           return;
+         }
+         /* region_count/start parameters are implicit in this case. */
+         gr_info->region1start = 36>>1;
+         gr_info->region2start = 576>>1;
+       } else {
+         /* window-switching flag==0  (block_Type==0)  */
+         int i,r0c,r1c;
+         for (i=0; i<3; i++)
+           gr_info->table_select[i] = getbits_fast(5);
+         r0c = getbits_fast(4);
+         r1c = getbits_fast(3);
+         gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
+         gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
+         gr_info->block_type = 0;
+         gr_info->mixed_block_flag = 0;
+       }
+       gr_info->preflag = get1bit();
+       gr_info->scalefac_scale = get1bit();
+       gr_info->count1table_select = get1bit();
+     }
+   }
+}
+
+/*
+ * Side Info for MPEG 2.0 / LSF
+ */
+static void III_get_side_info_2(struct III_sideinfo *si,int stereo,
+ int ms_stereo,long sfreq,int single)
+{
+   int ch;
+   int powdiff = (single == 3) ? 4 : 0;
+
+   si->main_data_begin = getbits(8);
+   if (stereo == 1)
+     si->private_bits = get1bit();
+   else 
+     si->private_bits = getbits_fast(2);
+
+   for (ch=0; ch<stereo; ch++) {
+       register struct gr_info_s *gr_info = &(si->ch[ch].gr[0]);
+
+       gr_info->part2_3_length = getbits(12);
+       gr_info->big_values = getbits(9);
+       if(gr_info->big_values > 288) {
+         printf("\rbig_values too large!                                                        \n");
+         gr_info->big_values = 288;
+       }
+       gr_info->pow2gain = 256 - getbits_fast(8) + powdiff;
+       if(ms_stereo)
+         gr_info->pow2gain += 2;
+       gr_info->scalefac_compress = getbits(9);
+
+       if(get1bit()) {
+         /* window-switching flag==1  (block_Type!=0)  */
+         int i;
+         gr_info->block_type = getbits_fast(2);
+         gr_info->mixed_block_flag = get1bit();
+         gr_info->table_select[0] = getbits_fast(5);
+         gr_info->table_select[1] = getbits_fast(5);
+         /*
+          * table_select[2] not needed, because there is no region2,
+          * but to satisfy some verifications tools we set it either.
+          */
+         gr_info->table_select[2] = 0;
+         for(i=0;i<3;i++)
+           gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(3)<<3);
+
+         if(gr_info->block_type == 0) {
+           printf("\rBlocktype == 0 and window-switching == 1 not allowed.                        \n");
+           return;
+         }
+         /* region_count/start parameters are implicit in this case. */       
+/* check this again! */
+         if(gr_info->block_type == 2)
+           gr_info->region1start = 36>>1;
+         else if(sfreq == 8)
+/* check this for 2.5 and sfreq=8 */
+           gr_info->region1start = 108>>1;
+         else
+           gr_info->region1start = 54>>1;
+         gr_info->region2start = 576>>1;
+       } else {
+         /* window-switching flag==0  (block_Type==0)  */
+         int i,r0c,r1c;
+         for (i=0; i<3; i++)
+           gr_info->table_select[i] = getbits_fast(5);
+         r0c = getbits_fast(4);
+         r1c = getbits_fast(3);
+         gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
+         gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
+         gr_info->block_type = 0;
+         gr_info->mixed_block_flag = 0;
+       }
+       gr_info->scalefac_scale = get1bit();
+       gr_info->count1table_select = get1bit();
+   }
+}
+
+/*
+ * read scalefactors
+ */
+static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
+{
+   static unsigned char slen[2][16] = {
+     {0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4},
+     {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3}
+   };
+   int numbits;
+   int num0 = slen[0][gr_info->scalefac_compress];
+   int num1 = slen[1][gr_info->scalefac_compress];
+
+    if (gr_info->block_type == 2) {
+      int i=18;
+      numbits = (num0 + num1) * 18;
+      if (gr_info->mixed_block_flag) {
+         for (i=8;i;i--) *scf++ = getbits(num0);
+         i = 9;
+         numbits -= num0; /* num0 * 17 + num1 * 18 */
+      }
+      for (;i;i--) *scf++ = getbits(num0);
+      for (i = 18; i; i--) *scf++ = getbits(num1);
+      *scf++ = 0; *scf++ = 0; *scf++ = 0; /* short[13][0..2] = 0 */
+    } else {
+      int i;
+      int scfsi = gr_info->scfsi;
+
+      if(scfsi < 0) { /* scfsi < 0 => granule == 0 */
+         for(i=11;i;i--) *scf++ = getbits(num0);
+         for(i=10;i;i--) *scf++ = getbits(num1);
+         numbits = (num0 + num1) * 10 + num0;
+      } else {
+        numbits = 0;
+        if(!(scfsi & 0x8)) {
+          for (i=6;i;i--) *scf++ = getbits(num0);
+          numbits += num0 * 6;
+        } else {
+          scf += 6;
+        }
+        if(!(scfsi & 0x4)) {
+          for (i=5;i;i--) *scf++ = getbits(num0);
+          numbits += num0 * 5;
+        } else {
+          scf += 5;
+        }
+        if(!(scfsi & 0x2)) {
+          for(i=5;i;i--) *scf++ = getbits(num1);
+          numbits += num1 * 5;
+        } else {
+          scf += 5;
+        }
+        if(!(scfsi & 0x1)) {
+          for (i=5;i;i--) *scf++ = getbits(num1);
+          numbits += num1 * 5;
+        } else {
+          scf += 5;
+        }
+      }
+
+      *scf++ = 0;  /* no l[21] in original sources */
+    }
+    return numbits;
+}
+
+static int III_get_scale_factors_2(int *scf,struct gr_info_s *gr_info,int i_stereo)
+{
+  unsigned char *pnt;
+  int i,j;
+  unsigned int slen;
+  int n = 0;
+  int numbits = 0;
+
+  static unsigned char stab[3][6][4] = {
+   { { 6, 5, 5,5 } , { 6, 5, 7,3 } , { 11,10,0,0} ,
+     { 7, 7, 7,0 } , { 6, 6, 6,3 } , {  8, 8,5,0} } ,
+   { { 9, 9, 9,9 } , { 9, 9,12,6 } , { 18,18,0,0} ,
+     {12,12,12,0 } , {12, 9, 9,6 } , { 15,12,9,0} } ,
+   { { 6, 9, 9,9 } , { 6, 9,12,6 } , { 15,18,0,0} ,
+     { 6,15,12,0 } , { 6,12, 9,6 } , {  6,18,9,0} } }; 
+
+  if(i_stereo) /* i_stereo AND second channel -> do_layer3() checks this */
+    slen = i_slen2[gr_info->scalefac_compress>>1];
+  else
+    slen = n_slen2[gr_info->scalefac_compress];
+
+  gr_info->preflag = (slen>>15) & 0x1;
+
+  n = 0;  
+  if( gr_info->block_type == 2 ) {
+    n++;
+    if(gr_info->mixed_block_flag) n++;
+  }
+
+  pnt = stab[n][(slen>>12)&0x7];
+
+  for(i=0;i<4;i++) {
+    int num = slen & 0x7;
+    slen >>= 3;
+    if(num) {
+      for(j=0;j<(int)(pnt[i]);j++) *scf++ = getbits_fast(num);
+      numbits += pnt[i] * num;
+    }
+    else {
+      for(j=0;j<(int)(pnt[i]);j++) *scf++ = 0;
+    }
+  }
+  
+  n = (n << 1) + 1;
+  for(i=0;i<n;i++) *scf++ = 0;
+
+  return numbits;
+}
+
+static int pretab1[22] = {0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0};
+static int pretab2[22] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+
+/*
+ * don't forget to apply the same changes to III_dequantize_sample_ms() !!!
+ */
+static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
+   struct gr_info_s *gr_info,int sfreq,int part2bits)
+{
+  int shift = 1 + gr_info->scalefac_scale;
+  real *xrpnt = (real *) xr;
+  int l[3],l3;
+  int part2remain = gr_info->part2_3_length - part2bits;
+  int *me;
+
+  { int bv       = gr_info->big_values;
+    int region1  = gr_info->region1start;
+    int region2  = gr_info->region2start;
+
+    l3 = ((576>>1)-bv)>>1;
+/*
+ * we may lose the 'odd' bit here !!
+ * check this later again 
+ */
+    if(bv <= region1) {
+      l[0] = bv; l[1] = 0; l[2] = 0;
+    } else {
+      l[0] = region1;
+      if(bv <= region2) {
+        l[1] = bv - l[0];  l[2] = 0;
+      } else {
+        l[1] = region2 - l[0]; l[2] = bv - region2;
+      }
+    }
+  }
+
+  if(gr_info->block_type == 2) {
+    /*
+     * decoding with short or mixed mode BandIndex table 
+     */
+    int i,max[4];
+    int step=0,lwin=0,cb=0;
+    register real v = 0.0;
+    register int *m,mc;
+
+    if(gr_info->mixed_block_flag) {
+      max[3] = -1;
+      max[0] = max[1] = max[2] = 2;
+      m = map[sfreq][0];
+      me = mapend[sfreq][0];
+    } else {
+      max[0] = max[1] = max[2] = max[3] = -1;
+      /* max[3] not really needed in this case */
+      m = map[sfreq][1];
+      me = mapend[sfreq][1];
+    }
+
+    mc = 0;
+    for(i=0;i<2;i++) {
+      int lp = l[i];
+      struct newhuff *h = ht+gr_info->table_select[i];
+      for(;lp;lp--,mc--) {
+        register int x,y;
+        if( (!mc) ) {
+          mc = *m++;
+          xrpnt = ((real *) xr) + (*m++);
+          lwin = *m++;
+          cb = *m++;
+          if(lwin == 3) {
+            v = Gainpow2(gr_info->pow2gain + ((*scf++) << shift));
+            step = 1;
+          } else {
+            v = Gainpow2(gr_info->full_gain[lwin] + ((*scf++) << shift));
+            step = 3;
+          }
+        }
+        { register short *val = h->table;
+          while((y=*val++)<0) {
+            part2remain--;
+            if(part2remain < 0) return 0;
+            if (get1bit()) val-=y;
+          }
+          x = y >> 4;
+          y &= 0xf;
+        }
+        if(x == 15) {
+          max[lwin] = cb;
+          part2remain -= h->linbits+1;
+          x += getbits(h->linbits);
+          if(get1bit())
+            *xrpnt = -ispow[x] * v;
+          else
+            *xrpnt =  ispow[x] * v;
+        } else if(x) {
+          max[lwin] = cb;
+          if(get1bit())
+            *xrpnt = -ispow[x] * v;
+          else
+            *xrpnt =  ispow[x] * v;
+          part2remain--;
+        } else
+          *xrpnt = 0.0;
+        xrpnt += step;
+        if(y == 15) {
+          max[lwin] = cb;
+          part2remain -= h->linbits+1;
+          y += getbits(h->linbits);
+          if(get1bit())
+            *xrpnt = -ispow[y] * v;
+          else
+            *xrpnt =  ispow[y] * v;
+        } else if(y) {
+          max[lwin] = cb;
+          if(get1bit())
+            *xrpnt = -ispow[y] * v;
+          else
+            *xrpnt =  ispow[y] * v;
+          part2remain--;
+        } else
+          *xrpnt = 0.0;
+        xrpnt += step;
+      }
+    }
+    
+    for(;l3 && (part2remain > 0);l3--) {
+      struct newhuff *h = htc+gr_info->count1table_select;
+      register short *val = h->table,a;
+
+      while((a=*val++)<0) {
+        part2remain--;
+        if(part2remain < 0) {
+          part2remain++;
+          a = 0;
+          break;
+        }
+        if (get1bit()) val-=a;
+      }
+
+      for(i=0;i<4;i++) {
+        if(!(i & 1)) {
+          if(!mc) {
+            mc = *m++;
+            xrpnt = ((real *) xr) + (*m++);
+            lwin = *m++;
+            cb = *m++;
+            if(lwin == 3) {
+              v = Gainpow2(gr_info->pow2gain + ((*scf++) << shift));
+              step = 1;
+            } else {
+              v = Gainpow2(gr_info->full_gain[lwin] + ((*scf++) << shift));
+              step = 3;
+            }
+          }
+          mc--;
+        }
+        if( (a & (0x8>>i)) ) {
+          max[lwin] = cb;
+          part2remain--;
+          if(part2remain < 0) {
+            part2remain++;
+            break;
+          }
+          if(get1bit())
+            *xrpnt = -v;
+          else
+            *xrpnt = v;
+        } else
+          *xrpnt = 0.0;
+        xrpnt += step;
+      }
+    } // for(;l3 && (part2remain > 0);l3--)
+ 
+    while( m < me ) {
+      if(!mc) {
+        mc = *m++;
+        xrpnt = ((real *) xr) + *m++;
+        if( (*m++) == 3)
+          step = 1;
+        else
+          step = 3;
+        m++; /* cb */
+      }
+      mc--;
+      *xrpnt = 0.0; xrpnt += step;
+      *xrpnt = 0.0; xrpnt += step;
+/* we could add a little opt. here:
+ * if we finished a band for window 3 or a long band
+ * further bands could copied in a simple loop without a
+ * special 'map' decoding
+ */
+    }
+
+    gr_info->maxband[0] = max[0]+1;
+    gr_info->maxband[1] = max[1]+1;
+    gr_info->maxband[2] = max[2]+1;
+    gr_info->maxbandl = max[3]+1;
+
+    { int rmax = max[0] > max[1] ? max[0] : max[1];
+      rmax = (rmax > max[2] ? rmax : max[2]) + 1;
+      gr_info->maxb = rmax ? shortLimit[sfreq][rmax] : longLimit[sfreq][max[3]+1];
+    }
+
+  } else {
+    /*
+     * decoding with 'long' BandIndex table (block_type != 2)
+     */
+    int *pretab = gr_info->preflag ? pretab1 : pretab2;
+    int i,max = -1;
+    int cb = 0;
+    register int *m = map[sfreq][2];
+    register real v = 0.0;
+    register int mc = 0;
+#if 0
+    me = mapend[sfreq][2];
+#endif
+
+     /*
+     * long hash table values
+     */
+    for(i=0;i<3;i++) {
+      int lp = l[i];
+      struct newhuff *h = ht+gr_info->table_select[i];
+
+      for(;lp;lp--,mc--) {
+        int x,y;
+
+        if(!mc) {
+          mc = *m++;
+          v = Gainpow2(gr_info->pow2gain + (((*scf++) + (*pretab++)) << shift));
+          cb = *m++;
+        }
+        { register short *val = h->table;
+          while((y=*val++)<0) {
+            part2remain--;
+            if(part2remain < 0) return 0;
+            if (get1bit()) val -= y;
+//            if(part2remain<=0) return 0; // Arpi
+          }
+          x = y >> 4;
+          y &= 0xf;
+        }
+        if (x == 15) {
+          max = cb;
+          part2remain -= h->linbits+1;
+          x += getbits(h->linbits);
+          if(get1bit())
+            *xrpnt++ = -ispow[x] * v;
+          else
+            *xrpnt++ =  ispow[x] * v;
+        } else if(x) {
+          max = cb;
+          if(get1bit())
+            *xrpnt++ = -ispow[x] * v;
+          else
+            *xrpnt++ =  ispow[x] * v;
+          part2remain--;
+        } else
+          *xrpnt++ = 0.0;
+
+        if (y == 15) {
+          max = cb;
+          part2remain -= h->linbits+1;
+          y += getbits(h->linbits);
+          if(get1bit())
+            *xrpnt++ = -ispow[y] * v;
+          else
+            *xrpnt++ =  ispow[y] * v;
+        } else if(y) {
+          max = cb;
+          if(get1bit())
+            *xrpnt++ = -ispow[y] * v;
+          else
+            *xrpnt++ =  ispow[y] * v;
+          part2remain--;
+        } else
+          *xrpnt++ = 0.0;
+      }
+    }
+
+     /*
+     * short (count1table) values
+     */
+    for(;l3 && (part2remain > 0);l3--) {
+      struct newhuff *h = htc+gr_info->count1table_select;
+      register short *val = h->table,a;
+
+      while((a=*val++)<0) {
+        part2remain--;
+        if(part2remain < 0) {
+          part2remain++;
+          a = 0;
+          break;
+        }
+        if (get1bit()) val -= a;
+      }
+
+      for(i=0;i<4;i++) {
+        if(!(i & 1)) {
+          if(!mc) {
+            mc = *m++;
+            cb = *m++;
+            v = Gainpow2(gr_info->pow2gain + (((*scf++) + (*pretab++)) << shift));
+          }
+          mc--;
+        }
+        if ( (a & (0x8>>i)) ) {
+          max = cb;
+          part2remain--;
+          if(part2remain < 0) {
+            part2remain++;
+            break;
+          }
+          if(get1bit())
+            *xrpnt++ = -v;
+          else
+            *xrpnt++ = v;
+        } else
+          *xrpnt++ = 0.0;
+      }
+    }
+
+    /* 
+     * zero part
+     */
+    for(i=(&xr[SBLIMIT][0]-xrpnt)>>1;i;i--) {
+      *xrpnt++ = 0.0;
+      *xrpnt++ = 0.0;
+    }
+
+    gr_info->maxbandl = max+1;
+    gr_info->maxb = longLimit[sfreq][gr_info->maxbandl];
+  }
+
+  while( part2remain > 16 ) {
+    getbits(16); /* Dismiss stuffing Bits */
+    part2remain -= 16;
+  }
+  if(part2remain > 0)
+    getbits(part2remain);
+  else if(part2remain < 0) {
+    printf("\rCan't rewind stream by %d bits!                                    \n",(-part2remain));
+    return 1; /* -> error */
+  }
+  return 0;
+}
+
+static int III_dequantize_sample_ms(real xr[2][SBLIMIT][SSLIMIT],int *scf,
+   struct gr_info_s *gr_info,int sfreq,int part2bits)
+{
+  int shift = 1 + gr_info->scalefac_scale;
+  real *xrpnt = (real *) xr[1];
+  real *xr0pnt = (real *) xr[0];
+  int l[3],l3;
+  int part2remain = gr_info->part2_3_length - part2bits;
+  int *me;
+
+  {
+    int bv       = gr_info->big_values;
+    int region1  = gr_info->region1start;
+    int region2  = gr_info->region2start;
+
+    l3 = ((576>>1)-bv)>>1;   
+/*
+ * we may lose the 'odd' bit here !! 
+ * check this later gain 
+ */
+    if(bv <= region1) {
+      l[0] = bv; l[1] = 0; l[2] = 0;
+    }
+    else {
+      l[0] = region1;
+      if(bv <= region2) {
+        l[1] = bv - l[0];  l[2] = 0;
+      }
+      else {
+        l[1] = region2 - l[0]; l[2] = bv - region2;
+      }
+    }
+  }
+ 
+  if(gr_info->block_type == 2) {
+    int i,max[4];
+    int step=0,lwin=0,cb=0;
+    register real v = 0.0;
+    register int *m,mc = 0;
+
+    if(gr_info->mixed_block_flag) {
+      max[3] = -1;
+      max[0] = max[1] = max[2] = 2;
+      m = map[sfreq][0];
+      me = mapend[sfreq][0];
+    }
+    else {
+      max[0] = max[1] = max[2] = max[3] = -1;
+      /* max[3] not really needed in this case */
+      m = map[sfreq][1];
+      me = mapend[sfreq][1];
+    }
+
+    for(i=0;i<2;i++) {
+      int lp = l[i];
+      struct newhuff *h = ht+gr_info->table_select[i];
+      for(;lp;lp--,mc--) {
+        int x,y;
+
+        if(!mc) {
+          mc = *m++;
+          xrpnt = ((real *) xr[1]) + *m;
+          xr0pnt = ((real *) xr[0]) + *m++;
+          lwin = *m++;
+          cb = *m++;
+          if(lwin == 3) {
+            v = Gainpow2(gr_info->pow2gain + ((*scf++) << shift));
+            step = 1;
+          }
+          else {
+            v = Gainpow2(gr_info->full_gain[lwin] + ((*scf++) << shift));
+            step = 3;
+          }
+        }
+        {
+          register short *val = h->table;
+          while((y=*val++)<0) {
+            part2remain--;
+            if(part2remain < 0) return 0;
+            if (get1bit()) val -= y;
+//            if(part2remain<=0) return 0; // Arpi
+          }
+          x = y >> 4;
+          y &= 0xf;
+        }
+        if(x == 15) {
+          max[lwin] = cb;
+          part2remain -= h->linbits+1;
+          x += getbits(h->linbits);
+          if(get1bit()) {
+            real a = ispow[x] * v;
+            *xrpnt = *xr0pnt + a;
+            *xr0pnt -= a;
+          }
+          else {
+            real a = ispow[x] * v;
+            *xrpnt = *xr0pnt - a;
+            *xr0pnt += a;
+          }
+        }
+        else if(x) {
+          max[lwin] = cb;
+          if(get1bit()) {
+            real a = ispow[x] * v;
+            *xrpnt = *xr0pnt + a;
+            *xr0pnt -= a;
+          }
+          else {
+            real a = ispow[x] * v;
+            *xrpnt = *xr0pnt - a;
+            *xr0pnt += a;
+          }
+          part2remain--;
+        }
+        else
+          *xrpnt = *xr0pnt;
+        xrpnt += step;
+        xr0pnt += step;
+
+        if(y == 15) {
+          max[lwin] = cb;
+          part2remain -= h->linbits+1;
+          y += getbits(h->linbits);
+          if(get1bit()) {
+            real a = ispow[y] * v;
+            *xrpnt = *xr0pnt + a;
+            *xr0pnt -= a;
+          }
+          else {
+            real a = ispow[y] * v;
+            *xrpnt = *xr0pnt - a;
+            *xr0pnt += a;
+          }
+        }
+        else if(y) {
+          max[lwin] = cb;
+          if(get1bit()) {
+            real a = ispow[y] * v;
+            *xrpnt = *xr0pnt + a;
+            *xr0pnt -= a;
+          }
+          else {
+            real a = ispow[y] * v;
+            *xrpnt = *xr0pnt - a;
+            *xr0pnt += a;
+          }
+          part2remain--;
+        }
+        else
+          *xrpnt = *xr0pnt;
+        xrpnt += step;
+        xr0pnt += step;
+      }
+    }
+
+    for(;l3 && (part2remain > 0);l3--) {
+      struct newhuff *h = htc+gr_info->count1table_select;
+      register short *val = h->table,a;
+
+      while((a=*val++)<0) {
+        part2remain--;
+        if(part2remain < 0) {
+          part2remain++;
+          a = 0;
+          break;
+        }
+        if (get1bit())
+          val -= a;
+      }
+
+      for(i=0;i<4;i++) {
+        if(!(i & 1)) {
+          if(!mc) {
+            mc = *m++;
+            xrpnt = ((real *) xr[1]) + *m;
+            xr0pnt = ((real *) xr[0]) + *m++;
+            lwin = *m++;
+            cb = *m++;
+            if(lwin == 3) {
+              v = Gainpow2(gr_info->pow2gain + ((*scf++) << shift));
+              step = 1;
+            }
+            else {
+              v = Gainpow2(gr_info->full_gain[lwin] + ((*scf++) << shift));
+              step = 3;
+            }
+          }
+          mc--;
+        }
+        if( (a & (0x8>>i)) ) {
+          max[lwin] = cb;
+          part2remain--;
+          if(part2remain < 0) {
+            part2remain++;
+            break;
+          }
+          if(get1bit()) {
+            *xrpnt = *xr0pnt + v;
+            *xr0pnt -= v;
+          }
+          else {
+            *xrpnt = *xr0pnt - v;
+            *xr0pnt += v;
+          }
+        }
+        else
+          *xrpnt = *xr0pnt;
+        xrpnt += step;
+        xr0pnt += step;
+      }
+    }
+ 
+    while( m < me ) {
+      if(!mc) {
+        mc = *m++;
+        xrpnt = ((real *) xr[1]) + *m;
+        xr0pnt = ((real *) xr[0]) + *m++;
+        if(*m++ == 3)
+          step = 1;
+        else
+          step = 3;
+        m++; /* cb */
+      }
+      mc--;
+      *xrpnt = *xr0pnt;
+      xrpnt += step;
+      xr0pnt += step;
+      *xrpnt = *xr0pnt;
+      xrpnt += step;
+      xr0pnt += step;
+/* we could add a little opt. here:
+ * if we finished a band for window 3 or a long band
+ * further bands could copied in a simple loop without a
+ * special 'map' decoding
+ */
+    }
+
+    gr_info->maxband[0] = max[0]+1;
+    gr_info->maxband[1] = max[1]+1;
+    gr_info->maxband[2] = max[2]+1;
+    gr_info->maxbandl = max[3]+1;
+
+    {
+      int rmax = max[0] > max[1] ? max[0] : max[1];
+      rmax = (rmax > max[2] ? rmax : max[2]) + 1;
+      gr_info->maxb = rmax ? shortLimit[sfreq][rmax] : longLimit[sfreq][max[3]+1];
+    }
+  }
+  else {
+    int *pretab = gr_info->preflag ? pretab1 : pretab2;
+    int i,max = -1;
+    int cb = 0;
+    register int mc=0,*m = map[sfreq][2];
+    register real v = 0.0;
+#if 0
+    me = mapend[sfreq][2];
+#endif
+
+    for(i=0;i<3;i++) {
+      int lp = l[i];
+      struct newhuff *h = ht+gr_info->table_select[i];
+
+      for(;lp;lp--,mc--) {
+        int x,y;
+        if(!mc) {
+          mc = *m++;
+          cb = *m++;
+          v = Gainpow2(gr_info->pow2gain + (((*scf++) + (*pretab++)) << shift));
+        }
+        {
+          register short *val = h->table;
+          while((y=*val++)<0) {
+            part2remain--;
+            if(part2remain < 0) return 0;
+            if (get1bit()) val -= y;
+          }
+          x = y >> 4;
+          y &= 0xf;
+        }
+        if (x == 15) {
+          max = cb;
+          part2remain -= h->linbits+1;
+          x += getbits(h->linbits);
+          if(get1bit()) {
+            real a = ispow[x] * v;
+            *xrpnt++ = *xr0pnt + a;
+            *xr0pnt++ -= a;
+          }
+          else {
+            real a = ispow[x] * v;
+            *xrpnt++ = *xr0pnt - a;
+            *xr0pnt++ += a;
+          }
+        }
+        else if(x) {
+          max = cb;
+          if(get1bit()) {
+            real a = ispow[x] * v;
+            *xrpnt++ = *xr0pnt + a;
+            *xr0pnt++ -= a;
+          }
+          else {
+            real a = ispow[x] * v;
+            *xrpnt++ = *xr0pnt - a;
+            *xr0pnt++ += a;
+          }
+          part2remain--;
+        }
+        else
+          *xrpnt++ = *xr0pnt++;
+
+        if (y == 15) {
+          max = cb;
+          part2remain -= h->linbits+1;
+          y += getbits(h->linbits);
+          if(get1bit()) {
+            real a = ispow[y] * v;
+            *xrpnt++ = *xr0pnt + a;
+            *xr0pnt++ -= a;
+          }
+          else {
+            real a = ispow[y] * v;
+            *xrpnt++ = *xr0pnt - a;
+            *xr0pnt++ += a;
+          }
+        }
+        else if(y) {
+          max = cb;
+          if(get1bit()) {
+            real a = ispow[y] * v;
+            *xrpnt++ = *xr0pnt + a;
+            *xr0pnt++ -= a;
+          }
+          else {
+            real a = ispow[y] * v;
+            *xrpnt++ = *xr0pnt - a;
+            *xr0pnt++ += a;
+          }
+          part2remain--;
+        }
+        else
+          *xrpnt++ = *xr0pnt++;
+      }
+    }
+
+    for(;l3 && (part2remain > 0);l3--) {
+      struct newhuff *h = htc+gr_info->count1table_select;
+      register short *val = h->table,a;
+
+      while((a=*val++)<0) {
+        part2remain--;
+        if(part2remain < 0) {
+          part2remain++;
+          a = 0;
+          break;
+        }
+        if (get1bit()) val -= a;
+      }
+
+      for(i=0;i<4;i++) {
+        if(!(i & 1)) {
+          if(!mc) {
+            mc = *m++;
+            cb = *m++;
+            v = Gainpow2(gr_info->pow2gain + (((*scf++) + (*pretab++)) << shift));
+          }
+          mc--;
+        }
+        if ( (a & (0x8>>i)) ) {
+          max = cb;
+          part2remain--;
+          if(part2remain <= 0) {
+            part2remain++;
+            break;
+          }
+          if(get1bit()) {
+            *xrpnt++ = *xr0pnt + v;
+            *xr0pnt++ -= v;
+          }
+          else {
+            *xrpnt++ = *xr0pnt - v;
+            *xr0pnt++ += v;
+          }
+        }
+        else
+          *xrpnt++ = *xr0pnt++;
+      }
+    }
+    for(i=(&xr[1][SBLIMIT][0]-xrpnt)>>1;i;i--) {
+      *xrpnt++ = *xr0pnt++;
+      *xrpnt++ = *xr0pnt++;
+    }
+
+    gr_info->maxbandl = max+1;
+    gr_info->maxb = longLimit[sfreq][gr_info->maxbandl];
+  }
+
+  while ( part2remain > 16 ) {
+    getbits(16); /* Dismiss stuffing Bits */
+    part2remain -= 16;
+  }
+  if(part2remain > 0 )
+    getbits(part2remain);
+  else if(part2remain < 0) {
+    printf("\rCan't rewind stream by %d bits!                                    \n",(-part2remain));
+//    fprintf(stderr,"mpg123: Can't rewind stream by %d bits (left=%d)!\n",(-part2remain),bitsleft);
+//    fprintf(stderr,"mpg123_ms: Can't rewind stream by %d bits!\n",(-part2remain));
+    return 1; /* -> error */
+  }
+  return 0;
+}
+
+/* 
+ * III_stereo: calculate real channel values for Joint-I-Stereo-mode
+ */
+static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac,
+   struct gr_info_s *gr_info,int sfreq,int ms_stereo,int lsf)
+{
+      real (*xr)[SBLIMIT*SSLIMIT] = (real (*)[SBLIMIT*SSLIMIT] ) xr_buf;
+      struct bandInfoStruct *bi = &bandInfo[sfreq];
+      real *tab1,*tab2;
+
+      if(lsf) {
+        int p = gr_info->scalefac_compress & 0x1;
+	    if(ms_stereo) {
+          tab1 = pow1_2[p]; tab2 = pow2_2[p];
+        }
+        else {
+          tab1 = pow1_1[p]; tab2 = pow2_1[p];
+        }
+      }
+      else {
+        if(ms_stereo) {
+          tab1 = tan1_2; tab2 = tan2_2;
+        }
+        else {
+          tab1 = tan1_1; tab2 = tan2_1;
+        }
+      }
+
+      if (gr_info->block_type == 2)
+      {
+         int lwin,do_l = 0;
+         if( gr_info->mixed_block_flag )
+           do_l = 1;
+
+         for (lwin=0;lwin<3;lwin++) /* process each window */
+         {
+             /* get first band with zero values */
+           int is_p,sb,idx,sfb = gr_info->maxband[lwin];  /* sfb is minimal 3 for mixed mode */
+           if(sfb > 3)
+             do_l = 0;
+
+           for(;sfb<12;sfb++)
+           {
+             is_p = scalefac[sfb*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ 
+             if(is_p != 7) {
+               real t1,t2;
+               sb = bi->shortDiff[sfb];
+               idx = bi->shortIdx[sfb] + lwin;
+               t1 = tab1[is_p]; t2 = tab2[is_p];
+               for (; sb > 0; sb--,idx+=3)
+               {
+                 real v = xr[0][idx];
+                 xr[0][idx] = v * t1;
+                 xr[1][idx] = v * t2;
+               }
+             }
+           }
+
+#if 1
+/* in the original: copy 10 to 11 , here: copy 11 to 12 
+maybe still wrong??? (copy 12 to 13?) */
+           is_p = scalefac[11*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
+           sb = bi->shortDiff[12];
+           idx = bi->shortIdx[12] + lwin;
+#else
+           is_p = scalefac[10*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
+           sb = bi->shortDiff[11];
+           idx = bi->shortIdx[11] + lwin;
+#endif
+           if(is_p != 7)
+           {
+             real t1,t2;
+             t1 = tab1[is_p]; t2 = tab2[is_p];
+             for ( ; sb > 0; sb--,idx+=3 )
+             {  
+               real v = xr[0][idx];
+               xr[0][idx] = v * t1;
+               xr[1][idx] = v * t2;
+             }
+           }
+         } /* end for(lwin; .. ; . ) */
+
+         if (do_l)
+         {
+/* also check l-part, if ALL bands in the three windows are 'empty'
+ * and mode = mixed_mode 
+ */
+           int sfb = gr_info->maxbandl;
+           int idx = bi->longIdx[sfb];
+
+           for ( ; sfb<8; sfb++ )
+           {
+             int sb = bi->longDiff[sfb];
+             int is_p = scalefac[sfb]; /* scale: 0-15 */
+             if(is_p != 7) {
+               real t1,t2;
+               t1 = tab1[is_p]; t2 = tab2[is_p];
+               for ( ; sb > 0; sb--,idx++)
+               {
+                 real v = xr[0][idx];
+                 xr[0][idx] = v * t1;
+                 xr[1][idx] = v * t2;
+               }
+             }
+             else 
+               idx += sb;
+           }
+         }     
+      } 
+      else /* ((gr_info->block_type != 2)) */
+      {
+        int sfb = gr_info->maxbandl;
+        int is_p,idx = bi->longIdx[sfb];
+        for ( ; sfb<21; sfb++)
+        {
+          int sb = bi->longDiff[sfb];
+          is_p = scalefac[sfb]; /* scale: 0-15 */
+          if(is_p != 7) {
+            real t1,t2;
+            t1 = tab1[is_p]; t2 = tab2[is_p];
+            for ( ; sb > 0; sb--,idx++)
+            {
+               real v = xr[0][idx];
+               xr[0][idx] = v * t1;
+               xr[1][idx] = v * t2;
+            }
+          }
+          else
+            idx += sb;
+        }
+
+        is_p = scalefac[20]; /* copy l-band 20 to l-band 21 */
+        if(is_p != 7)
+        {
+          int sb;
+          real t1 = tab1[is_p],t2 = tab2[is_p]; 
+
+          for ( sb = bi->longDiff[21]; sb > 0; sb--,idx++ )
+          {
+            real v = xr[0][idx];
+            xr[0][idx] = v * t1;
+            xr[1][idx] = v * t2;
+          }
+        }
+      } /* ... */
+}
+
+static void III_antialias(real xr[SBLIMIT][SSLIMIT],struct gr_info_s *gr_info)
+{
+   int sblim;
+
+   if(gr_info->block_type == 2) {
+      if(!gr_info->mixed_block_flag) return;
+      sblim = 1; 
+   } else {
+     sblim = gr_info->maxb-1;
+   }
+   
+   //printf("sblim=%d\n",sblim);
+   //if(sblim<=0 || sblim>SBLIMIT) return;
+
+   /* 31 alias-reduction operations between each pair of sub-bands */
+   /* with 8 butterflies between each pair                         */
+
+   { int sb;
+     real *xr1=(real *) xr[1];
+
+     for(sb=sblim;sb;sb--,xr1+=10) {
+       int ss;
+       real *cs=aa_cs,*ca=aa_ca;
+       real *xr2 = xr1;
+
+       for(ss=7;ss>=0;ss--) {    /* upper and lower butterfly inputs */
+         register real bu = *--xr2,bd = *xr1;
+         *xr2   = (bu * (*cs)   ) - (bd * (*ca)   );
+         *xr1++ = (bd * (*cs++) ) + (bu * (*ca++) );
+       }
+     }
+     
+  }
+}
+
+#include "dct64.c"
+#include "dct36.c"
+#include "dct12.c"
+
+#include "decod386.c"
+
+/*
+ * III_hybrid
+ */
+static void III_hybrid(real fsIn[SBLIMIT][SSLIMIT],real tsOut[SSLIMIT][SBLIMIT],
+   int ch,struct gr_info_s *gr_info)
+{
+   real *tspnt = (real *) tsOut;
+   static real block[2][2][SBLIMIT*SSLIMIT] = { { { 0, } } };
+   static int blc[2]={0,0};
+   real *rawout1,*rawout2;
+   int bt;
+   int sb = 0;
+
+   {
+     int b = blc[ch];
+     rawout1=block[b][ch];
+     b=-b+1;
+     rawout2=block[b][ch];
+     blc[ch] = b;
+   }
+
+   if(gr_info->mixed_block_flag) {
+     sb = 2;
+     dct36(fsIn[0],rawout1,rawout2,win[0],tspnt);
+     dct36(fsIn[1],rawout1+18,rawout2+18,win1[0],tspnt+1);
+     rawout1 += 36; rawout2 += 36; tspnt += 2;
+   }
+ 
+   bt = gr_info->block_type;
+   if(bt == 2) {
+     for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) {
+       dct12(fsIn[sb],rawout1,rawout2,win[2],tspnt);
+       dct12(fsIn[sb+1],rawout1+18,rawout2+18,win1[2],tspnt+1);
+     }
+   }
+   else {
+     for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) {
+       dct36(fsIn[sb],rawout1,rawout2,win[bt],tspnt);
+       dct36(fsIn[sb+1],rawout1+18,rawout2+18,win1[bt],tspnt+1);
+     }
+   }
+
+   for(;sb<SBLIMIT;sb++,tspnt++) {
+     int i;
+     for(i=0;i<SSLIMIT;i++) {
+       tspnt[i*SBLIMIT] = *rawout1++;
+       *rawout2++ = 0.0;
+     }
+   }
+}
+
+/*
+ * main layer3 handler
+ */
+/* int do_layer3(struct frame *fr,int outmode,struct audio_info_struct *ai) */
+static int do_layer3(struct frame *fr,int single){
+  int gr, ch, ss,clip=0;
+  int scalefacs[2][39]; /* max 39 for short[13][3] mode, mixed: 38, long: 22 */
+  struct III_sideinfo sideinfo;
+  int stereo = fr->stereo;
+  int ms_stereo,i_stereo;
+  int sfreq = fr->sampling_frequency;
+  int stereo1,granules;
+
+//  if (fr->error_protection) getbits(16); /* skip crc */
+
+  if(stereo == 1) { /* stream is mono */
+    stereo1 = 1;
+    single = 0;
+  } else
+  if(single >= 0) /* stream is stereo, but force to mono */
+    stereo1 = 1;
+  else
+    stereo1 = 2;
+
+  if(fr->mode == MPG_MD_JOINT_STEREO) {
+    ms_stereo = fr->mode_ext & 0x2;
+    i_stereo  = fr->mode_ext & 0x1;
+  } else
+    ms_stereo = i_stereo = 0;
+
+  if(fr->lsf) {
+    granules = 1;
+    III_get_side_info_2(&sideinfo,stereo,ms_stereo,sfreq,single);
+  } else {
+    granules = 2;
+    III_get_side_info_1(&sideinfo,stereo,ms_stereo,sfreq,single);
+  }
+
+  set_pointer(sideinfo.main_data_begin);
+
+  for (gr=0;gr<granules;gr++){
+    static real hybridIn[2][SBLIMIT][SSLIMIT];
+    static real hybridOut[2][SSLIMIT][SBLIMIT];
+
+    { struct gr_info_s *gr_info = &(sideinfo.ch[0].gr[gr]);
+      long part2bits;
+      if(fr->lsf)
+        part2bits = III_get_scale_factors_2(scalefacs[0],gr_info,0);
+      else
+        part2bits = III_get_scale_factors_1(scalefacs[0],gr_info);
+      if(III_dequantize_sample(hybridIn[0], scalefacs[0],gr_info,sfreq,part2bits))
+        return clip;
+    }
+
+    if(stereo == 2) {
+      struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]);
+      
+      long part2bits;
+      if(fr->lsf) 
+        part2bits = III_get_scale_factors_2(scalefacs[1],gr_info,i_stereo);
+      else
+        part2bits = III_get_scale_factors_1(scalefacs[1],gr_info);
+
+      if(ms_stereo) {
+        if(III_dequantize_sample_ms(hybridIn,scalefacs[1],gr_info,sfreq,part2bits))
+          return clip;
+      } else {
+        if(III_dequantize_sample(hybridIn[1],scalefacs[1],gr_info,sfreq,part2bits))
+          return clip;
+      }
+
+      if(i_stereo)
+        III_i_stereo(hybridIn,scalefacs[1],gr_info,sfreq,ms_stereo,fr->lsf);
+
+      if(ms_stereo || i_stereo || (single == 3) ) {
+        if(gr_info->maxb > sideinfo.ch[0].gr[gr].maxb) 
+          sideinfo.ch[0].gr[gr].maxb = gr_info->maxb;
+        else
+          gr_info->maxb = sideinfo.ch[0].gr[gr].maxb;
+      }
+
+      switch(single) {
+        case 3: {
+          register int i;
+          register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
+          for(i=0;i<SSLIMIT*gr_info->maxb;i++,in0++)
+            *in0 = (*in0 + *in1++); /* *0.5 done by pow-scale */ 
+          break; }
+        case 1: {
+          register int i;
+          register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
+          for(i=0;i<SSLIMIT*gr_info->maxb;i++)
+            *in0++ = *in1++;
+          break; }
+      }
+
+    }  // if(stereo == 2)
+
+    for(ch=0;ch<stereo1;ch++) {
+      struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]);
+		  III_antialias(hybridIn[ch],gr_info);
+		  III_hybrid(hybridIn[ch], hybridOut[ch], ch,gr_info);
+    }
+
+    for(ss=0;ss<SSLIMIT;ss++) {
+      if(single >= 0) {
+		    clip += (fr->synth_mono)(hybridOut[0][ss],pcm_sample,&pcm_point);
+  		} else {
+	  	  int p1 = pcm_point;
+		    clip += (fr->synth)(hybridOut[0][ss],0,pcm_sample,&p1);
+		    clip += (fr->synth)(hybridOut[1][ss],1,pcm_sample,&pcm_point);
+      }
+    }
+    
+  }
+
+  return clip;
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/mp3.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,31 @@
+/* MP3 Player Library 2.0      (C) 1999 A'rpi/Astral&ESP-team  */
+
+/* decoder level: */
+extern void MP3_Init();
+extern int MP3_Open(char *filename,int buffsize);
+extern void MP3_SeekFrame(int num,int dir);
+extern void MP3_SeekForward(int num);
+extern int MP3_PrintTAG();
+extern int MP3_DecodeFrame(unsigned char *hova,short single);
+extern int MP3_FillBuffers();
+extern void MP3_PrintHeader();
+extern void MP3_Close();
+/* public variables: */
+extern int MP3_eof;        // set if EOF reached
+extern int MP3_pause;      // lock playing
+/* informational: */
+extern int MP3_filesize;   // filesize
+extern int MP3_frames;     // current frame no
+extern int MP3_fpos;       // current file pos
+extern int MP3_framesize;  // current framesize in bytes (including header)
+extern int MP3_bitrate;    // current bitrate (kbits)
+extern int MP3_samplerate; // current sampling freq (Hz)
+extern int MP3_channels;
+extern int MP3_bps;
+
+/* player level: */
+extern int  MP3_OpenDevice(char *devname);  /* devname can be NULL for default) */
+extern void MP3_Play();
+extern void MP3_Stop();
+extern void MP3_CloseDevice();
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/mpg123.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,125 @@
+/*
+ * mpg123 defines
+ * used source: musicout.h from mpegaudio package
+ */
+
+#include "../config.h"
+
+# define M_PI       3.14159265358979323846
+# define M_SQRT2        1.41421356237309504880
+# define REAL_IS_FLOAT
+# define NEW_DCT9
+
+#undef MPG123_REMOTE           /* Get rid of this stuff for Win32 */
+
+/*
+#  define real float
+#  define real long double
+#  define real double
+#include "audio.h"
+
+// #define              AUDIOBUFSIZE            4096
+*/
+
+#define         FALSE                   0
+#define         TRUE                    1
+
+#define         MAX_NAME_SIZE           81
+#define         SBLIMIT                 32
+#define         SCALE_BLOCK             12
+#define         SSLIMIT                 18
+
+#define         MPG_MD_STEREO           0
+#define         MPG_MD_JOINT_STEREO     1
+#define         MPG_MD_DUAL_CHANNEL     2
+#define         MPG_MD_MONO             3
+
+/* #define MAXOUTBURST 32768 */
+
+/* Pre Shift fo 16 to 8 bit converter table */
+#define AUSHIFT (3)
+
+struct al_table
+{
+  short bits;
+  short d;
+};
+
+struct frame {
+         struct al_table *alloc;
+         int (*synth)(real *,int,unsigned char *,int *);
+    int (*synth_mono)(real *,unsigned char *,int *);
+    int stereo;
+    int jsbound;
+    int single;
+    int II_sblimit;
+    int down_sample_sblimit;
+         int lsf;
+         int mpeg25;
+    int down_sample;
+         int header_change;
+    int lay;
+    int error_protection;
+    int bitrate_index;
+    long sampling_frequency;
+    int padding;
+    int extension;
+    int mode;
+         int mode_ext;
+    int copyright;
+         int original;
+         int emphasis;
+         long framesize; /* computed framesize */
+};
+
+
+struct gr_info_s {
+      int scfsi;
+      unsigned part2_3_length;
+      unsigned big_values;
+      unsigned scalefac_compress;
+      unsigned block_type;
+      unsigned mixed_block_flag;
+      unsigned table_select[3];
+      unsigned subblock_gain[3];
+      unsigned maxband[3];
+      unsigned maxbandl;
+      unsigned maxb;
+      unsigned region1start;
+      unsigned region2start;
+      unsigned preflag;
+      unsigned scalefac_scale;
+      unsigned count1table_select;
+      int full_gain[3];
+      int pow2gain;
+};
+
+struct III_sideinfo
+{
+  unsigned main_data_begin;
+  unsigned private_bits;
+  struct {
+         struct gr_info_s gr[2];
+  } ch[2];
+};
+
+static long freqs[9];
+#ifdef HAVE_3DNOW
+        real decwin[2*(512+32)];
+#else
+        real decwin[512+32];
+#endif
+       real *pnts[];
+
+static int do_layer2(struct frame *fr,int single);
+static int do_layer3(struct frame *fr,int single);
+static int synth_1to1(real *bandPtr,int channel,unsigned char *out,int *pnt);
+
+extern int  synth_1to1_pent( real *,int,unsigned char * );
+extern void dct64(real *a,real *b,real *c);
+
+#ifdef HAVE_3DNOW
+ extern void dct64_3dnow( real *,real *, real * );
+ extern void dct36_3dnow(real *,real *,real *,real *,real *);
+ extern int  synth_1to1_3dnow( real *,int,unsigned char * );
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/sr1.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,489 @@
+// #define NEWBUFFERING
+//#define DEBUG_RESYNC
+
+/* 1 frame = 4608 byte PCM */
+
+#ifdef __GNUC__
+#define LOCAL static inline
+#else
+#define LOCAL static _inline
+#endif
+
+//#undef LOCAL
+//#define LOCAL
+
+#include        <stdlib.h>
+#include        <stdio.h>
+#include        <string.h>
+#include        <signal.h>
+#include        <math.h>
+
+#define real float
+// #define int long
+
+#include "mpg123.h"
+#include "huffman.h"
+#include "mp3.h"
+
+#include "d_cpu.h"
+
+//static FILE* mp3_file=NULL;
+
+int MP3_frames=0;
+int MP3_eof=0;
+int MP3_pause=0;
+int MP3_filesize=0;
+int MP3_fpos=0;      // current file position
+int MP3_framesize=0; // current framesize
+int MP3_bitrate=0;   // current bitrate
+int MP3_samplerate=0;  // current samplerate
+int MP3_resync=0;
+int MP3_channels=0;
+int MP3_bps=2;
+
+static long outscale  = 32768;
+#include "tabinit.c"
+
+extern int mplayer_audio_read(char *buf,int size);
+
+#if 1
+LOCAL int mp3_read(char *buf,int size){
+//  int len=fread(buf,1,size,mp3_file);
+  int len=mplayer_audio_read(buf,size);
+  if(len>0) MP3_fpos+=len;
+//  if(len!=size) MP3_eof=1;
+  return len;
+}
+#else
+extern int mp3_read(char *buf,int size);
+#endif
+
+//void mp3_seek(int pos){
+//  fseek(mp3_file,pos,SEEK_SET);
+//  return (MP3_fpos=ftell(mp3_file));
+//}
+
+/*       Frame reader           */
+
+#define MAXFRAMESIZE 1280
+#define MAXFRAMESIZE2 (512+MAXFRAMESIZE)
+
+static int fsizeold=0,ssize=0;
+static unsigned char bsspace[2][MAXFRAMESIZE2]; /* !!!!! */
+static unsigned char *bsbufold=bsspace[0]+512;
+static unsigned char *bsbuf=bsspace[1]+512;
+static int bsnum=0;
+
+static int bitindex;
+static unsigned char *wordpointer;
+static int bitsleft;
+
+unsigned char *pcm_sample;   /* az outbuffer CIME */
+int pcm_point = 0;           /* ez az outbuffer pozicioja */
+
+static struct frame fr;
+
+static int tabsel_123[2][3][16] = {
+   { {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,},
+     {0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,},
+     {0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,} },
+
+   { {0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,},
+     {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,},
+     {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,} }
+};
+
+static long freqs[9] = { 44100, 48000, 32000, 22050, 24000, 16000 , 11025 , 12000 , 8000 };
+
+LOCAL unsigned int getbits(short number_of_bits)
+{
+  unsigned long rval;
+//  if(MP3_frames>=7741) printf("getbits: bits=%d  bitsleft=%d  wordptr=%x\n",number_of_bits,bitsleft,wordpointer);
+  if((bitsleft-=number_of_bits)<0) return 0;
+  if(!number_of_bits) return 0;
+         rval = wordpointer[0];
+         rval <<= 8;
+         rval |= wordpointer[1];
+         rval <<= 8;
+         rval |= wordpointer[2];
+         rval <<= bitindex;
+         rval &= 0xffffff;
+         bitindex += number_of_bits;
+         rval >>= (24-number_of_bits);
+         wordpointer += (bitindex>>3);
+         bitindex &= 7;
+  return rval;
+}
+
+
+LOCAL unsigned int getbits_fast(short number_of_bits)
+{
+  unsigned long rval;
+//  if(MP3_frames>=7741) printf("getbits_fast: bits=%d  bitsleft=%d  wordptr=%x\n",number_of_bits,bitsleft,wordpointer);
+  if((bitsleft-=number_of_bits)<0) return 0;
+  if(!number_of_bits) return 0;
+   rval = wordpointer[0];
+         rval <<= 8;
+         rval |= wordpointer[1];
+         rval <<= bitindex;
+         rval &= 0xffff;
+         bitindex += number_of_bits;
+         rval >>= (16-number_of_bits);
+         wordpointer += (bitindex>>3);
+         bitindex &= 7;
+  return rval;
+}
+
+LOCAL unsigned int get1bit(void)
+{
+  unsigned char rval;
+//  if(MP3_frames>=7741) printf("get1bit: bitsleft=%d  wordptr=%x\n",bitsleft,wordpointer);
+  if((--bitsleft)<0) return 0;
+  rval = *wordpointer << bitindex;
+  bitindex++;
+  wordpointer += (bitindex>>3);
+  bitindex &= 7;
+  return ((rval>>7)&1);
+}
+
+LOCAL void set_pointer(long backstep)
+{
+//  if(backstep!=512 && backstep>fsizeold)
+//    printf("\rWarning! backstep (%d>%d)                                         \n",backstep,fsizeold);
+  wordpointer = bsbuf + ssize - backstep;
+  if (backstep) memcpy(wordpointer,bsbufold+fsizeold-backstep,backstep);
+  bitindex = 0;
+  bitsleft+=8*backstep;
+//  printf("Backstep %d  (bitsleft=%d)\n",backstep,bitsleft);
+}
+
+LOCAL int stream_head_read(unsigned char *hbuf,unsigned long *newhead){
+  if(mp3_read(hbuf,4) != 4) return FALSE;
+  *newhead = ((unsigned long) hbuf[0] << 24) |
+                   ((unsigned long) hbuf[1] << 16) |
+                   ((unsigned long) hbuf[2] << 8)  |
+                    (unsigned long) hbuf[3];
+        return TRUE;
+}
+
+LOCAL int stream_head_shift(unsigned char *hbuf,unsigned long *head){
+  memmove (&hbuf[0], &hbuf[1], 3);
+  if(mp3_read(hbuf+3,1) != 1) return 0;
+  *head <<= 8;
+  *head |= hbuf[3];
+  *head &= 0xffffffff;
+  return 1;
+}
+
+/*
+ * decode a header and write the information
+ * into the frame structure
+ */
+LOCAL int decode_header(struct frame *fr,unsigned long newhead){
+
+    // head_check:
+    if( (newhead & 0xffe00000) != 0xffe00000)   return FALSE;
+    if( ((newhead>>12)&0xf) == 0xf)     return FALSE;
+    if( ((newhead>>10)&0x3) == 0x3 )    return FALSE;
+
+    fr->lay = 4-((newhead>>17)&3);
+//    if(fr->lay!=3) return FALSE;
+
+    if( newhead & ((long)1<<20) ) {
+      fr->lsf = (newhead & ((long)1<<19)) ? 0x0 : 0x1;
+      fr->mpeg25 = 0;
+    } else {
+      fr->lsf = 1;
+      fr->mpeg25 = 1;
+    }
+
+    if(fr->mpeg25)
+      fr->sampling_frequency = 6 + ((newhead>>10)&0x3);
+    else
+      fr->sampling_frequency = ((newhead>>10)&0x3) + (fr->lsf*3);
+
+    fr->error_protection = ((newhead>>16)&0x1)^0x1;
+    fr->bitrate_index = ((newhead>>12)&0xf);
+    fr->padding   = ((newhead>>9)&0x1);
+    fr->extension = ((newhead>>8)&0x1);
+    fr->mode      = ((newhead>>6)&0x3);
+    fr->mode_ext  = ((newhead>>4)&0x3);
+    fr->copyright = ((newhead>>3)&0x1);
+    fr->original  = ((newhead>>2)&0x1);
+    fr->emphasis  = newhead & 0x3;
+
+    MP3_channels = fr->stereo    = (fr->mode == MPG_MD_MONO) ? 1 : 2;
+
+    if(!fr->bitrate_index){
+//      fprintf(stderr,"Free format not supported.\n");
+      return FALSE;
+    }
+
+switch(fr->lay){
+  case 2:
+    MP3_bitrate=tabsel_123[fr->lsf][1][fr->bitrate_index];
+    MP3_samplerate=freqs[fr->sampling_frequency];
+    fr->framesize = (long) MP3_bitrate * 144000;
+    fr->framesize /= MP3_samplerate;
+    MP3_framesize=fr->framesize;
+    fr->framesize += fr->padding - 4;
+    break;
+  case 3:
+    if(fr->lsf)
+      ssize = (fr->stereo == 1) ? 9 : 17;
+    else
+      ssize = (fr->stereo == 1) ? 17 : 32;
+    if(fr->error_protection) ssize += 2;
+
+    MP3_bitrate=tabsel_123[fr->lsf][2][fr->bitrate_index];
+    MP3_samplerate=freqs[fr->sampling_frequency];
+    fr->framesize  = (long) MP3_bitrate * 144000;
+    fr->framesize /= MP3_samplerate<<(fr->lsf);
+    MP3_framesize=fr->framesize;
+    fr->framesize += fr->padding - 4;
+    break;
+  default:
+//    fprintf(stderr,"Sorry, unsupported layer type.\n");
+    return 0;
+}
+    if(fr->framesize<=0 || fr->framesize>MAXFRAMESIZE) return FALSE;
+
+    return 1;
+}
+
+
+LOCAL int stream_read_frame_body(int size){
+
+  /* flip/init buffer for Layer 3 */
+  bsbufold = bsbuf;
+  bsbuf = bsspace[bsnum]+512;
+  bsnum = (bsnum + 1) & 1;
+
+  if( mp3_read(bsbuf,size) != size) return 0; // broken frame
+
+  bitindex = 0;
+  wordpointer = (unsigned char *) bsbuf;
+  bitsleft=8*size;
+
+  return 1;
+}
+
+
+/*****************************************************************
+ * read next frame     return number of frames read.
+ */
+LOCAL int read_frame(struct frame *fr){
+  unsigned long newhead;
+  unsigned char hbuf[8];
+  int skipped,resyncpos;
+  int frames=0;
+
+resync:
+  skipped=MP3_fpos;
+  resyncpos=MP3_fpos;
+
+  set_pointer(512);
+  fsizeold=fr->framesize;       /* for Layer3 */
+  if(!stream_head_read(hbuf,&newhead)) return 0;
+  if(!decode_header(fr,newhead)){
+    // invalid header! try to resync stream!
+#ifdef DEBUG_RESYNC
+    printf("ReSync: searching for a valid header...  (pos=%X)\n",MP3_fpos);
+#endif
+retry1:
+    while(!decode_header(fr,newhead)){
+      if(!stream_head_shift(hbuf,&newhead)) return 0;
+    }
+    resyncpos=MP3_fpos-4;
+    // found valid header
+#ifdef DEBUG_RESYNC
+    printf("ReSync: found valid hdr at %X  fsize=%ld  ",resyncpos,fr->framesize);
+#endif
+    if(!stream_read_frame_body(fr->framesize)) return 0; // read body
+    set_pointer(512);
+    fsizeold=fr->framesize;       /* for Layer3 */
+    if(!stream_head_read(hbuf,&newhead)) return 0;
+    if(!decode_header(fr,newhead)){
+      // invalid hdr! go back...
+#ifdef DEBUG_RESYNC
+      printf("INVALID\n");
+#endif
+//      mp3_seek(resyncpos+1);
+      if(!stream_head_read(hbuf,&newhead)) return 0;
+      goto retry1;
+    }
+#ifdef DEBUG_RESYNC
+    printf("OK!\n");
+    ++frames;
+#endif
+  }
+
+  skipped=resyncpos-skipped;
+//  if(skipped && !MP3_resync) printf("\r%d bad bytes skipped  (resync at 0x%X)                          \n",skipped,resyncpos);
+
+//  printf("%8X [%08X] %d %d (%d)%s%s\n",MP3_fpos-4,newhead,fr->framesize,fr->mode,fr->mode_ext,fr->error_protection?" CRC":"",fr->padding?" PAD":"");
+
+  /* read main data into memory */
+  if(!stream_read_frame_body(fr->framesize)){
+    printf("\nBroken frame at 0x%X                                                  \n",resyncpos);
+    return 0;
+  }
+  ++frames;
+
+  if(MP3_resync){
+    MP3_resync=0;
+    if(frames==1) goto resync;
+  }
+
+  return frames;
+}
+
+#include "layer2.c"
+#include "layer3.c"
+
+/******************************************************************************/
+/*           PUBLIC FUNCTIONS                  */
+/******************************************************************************/
+
+static int tables_done_flag=0;
+
+// Init decoder tables.  Call first, once!
+void MP3_Init(){
+    _CpuID=CpuDetect();
+    _i586=ipentium();
+#ifdef HAVE_3DNOW
+    _3dnow=a3dnow();
+#endif
+
+    printf( "mp3lib: Processor ID: %x\n",_CpuID );
+    printf( "mp3lib: i586 processor %sdetected.\n",(_i586?"":"not ") );
+#ifdef HAVE_3DNOW
+    printf( "mp3lib: AMD 3dnow! extension %sdetected.\n",(a3dnow()?"":"not ") );
+#endif
+
+    make_decode_tables(outscale);
+    fr.synth=synth_1to1;
+    fr.synth_mono=synth_1to1_mono2stereo;
+    fr.down_sample=0;
+    fr.down_sample_sblimit = SBLIMIT>>(fr.down_sample);
+    init_layer2();
+    init_layer3(fr.down_sample_sblimit);
+    tables_done_flag=1;
+}
+
+#if 0
+
+void MP3_Close(){
+  MP3_eof=1;
+  if(mp3_file) fclose(mp3_file);
+  mp3_file=NULL;
+}
+
+// Open a file, init buffers. Call once per file!
+int MP3_Open(char *filename,int buffsize){
+  MP3_eof=1;   // lock decoding
+  MP3_pause=1; // lock playing
+  if(mp3_file) MP3_Close(); // close prev. file
+  MP3_frames=0;
+
+  mp3_file=fopen(filename,"rb");
+//  printf("MP3_Open: file='%s'",filename);
+//  if(!mp3_file){ printf(" not found!\n"); return 0;} else printf("Ok!\n");
+  if(!mp3_file) return 0;
+
+  MP3_filesize=MP3_PrintTAG();
+  fseek(mp3_file,0,SEEK_SET);
+
+  MP3_InitBuffers(buffsize);
+  if(!tables_done_flag) MP3_Init();
+  MP3_eof=0;  // allow decoding
+  MP3_pause=0; // allow playing
+  return MP3_filesize;
+}
+
+#endif
+
+// Read & decode a single frame. Called by sound driver.
+int MP3_DecodeFrame(unsigned char *hova,short single){
+   pcm_sample = hova;
+   pcm_point = 0;
+   if(!read_frame(&fr))return(0);
+   if(single==-2){ set_pointer(512); return(1); }
+   if(fr.error_protection) getbits(16); /* skip crc */
+   fr.single=single;
+   switch(fr.lay){
+     case 2: do_layer2(&fr,single);break;
+     case 3: do_layer3(&fr,single);break;
+   }
+//   ++MP3_frames;
+   return(pcm_point?pcm_point:2);
+}
+
+#if 0
+
+// Prints last frame header in ascii.
+void MP3_PrintHeader(){
+        static char *modes[4] = { "Stereo", "Joint-Stereo", "Dual-Channel", "Single-Channel" };
+        static char *layers[4] = { "???" , "I", "II", "III" };
+
+        printf("\rMPEG %s, Layer %s, %ld Hz %d kbit %s, BPF : %ld\n",
+                fr.mpeg25 ? "2.5" : (fr.lsf ? "2.0" : "1.0"),
+                layers[fr.lay],freqs[fr.sampling_frequency],
+    tabsel_123[fr.lsf][fr.lay-1][fr.bitrate_index],
+                modes[fr.mode],fr.framesize+4);
+        printf("Channels: %d, copyright: %s, original: %s, CRC: %s, emphasis: %d.\n\n",
+                fr.stereo,fr.copyright?"Yes":"No",
+                fr.original?"Yes":"No",fr.error_protection?"Yes":"No",
+                fr.emphasis);
+}
+
+#include "genre.h"
+
+// Read & print ID3 TAG. Do not call when playing!!!  returns filesize.
+int MP3_PrintTAG(){
+        struct id3tag {
+                char tag[3];
+                char title[30];
+                char artist[30];
+                char album[30];
+                char year[4];
+                char comment[30];
+                unsigned char genre;
+        };
+        struct id3tag tag;
+        char title[31]={0,};
+        char artist[31]={0,};
+        char album[31]={0,};
+        char year[5]={0,};
+        char comment[31]={0,};
+        char genre[31]={0,};
+  int fsize;
+  int ret;
+
+  fseek(mp3_file,0,SEEK_END);
+  fsize=ftell(mp3_file);
+  if(fseek(mp3_file,-128,SEEK_END)) return fsize;
+  ret=fread(&tag,128,1,mp3_file);
+  if(ret!=1 || tag.tag[0]!='T' || tag.tag[1]!='A' || tag.tag[2]!='G') return fsize;
+
+        strncpy(title,tag.title,30);
+        strncpy(artist,tag.artist,30);
+        strncpy(album,tag.album,30);
+        strncpy(year,tag.year,4);
+        strncpy(comment,tag.comment,30);
+
+        if ( tag.genre <= sizeof(genre_table)/sizeof(*genre_table) ) {
+                strncpy(genre, genre_table[tag.genre], 30);
+        } else {
+                strncpy(genre,"Unknown",30);
+        }
+
+//      printf("\n");
+        printf("Title  : %30s  Artist: %s\n",title,artist);
+        printf("Album  : %30s  Year  : %4s\n",album,year);
+        printf("Comment: %30s  Genre : %s\n",comment,genre);
+        printf("\n");
+  return fsize-128;
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mp3lib/tabinit.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,89 @@
+
+
+#ifdef HAVE_3DNOW
+        real decwin[2*(512+32)];
+        real cos64[32],cos32[16],cos16[8],cos8[4],cos4[2];
+        real *pnts[]={ cos64,cos32,cos16,cos8,cos4 };
+#else
+        real decwin[512+32];
+        real cos64[16],cos32[8],cos16[4],cos8[2],cos4[1];
+        real *pnts[] = { cos64,cos32,cos16,cos8,cos4 };
+#endif
+
+       long intwinbase[] = {
+     0,    -1,    -1,    -1,    -1,    -1,    -1,    -2,    -2,    -2,
+    -2,    -3,    -3,    -4,    -4,    -5,    -5,    -6,    -7,    -7,
+    -8,    -9,   -10,   -11,   -13,   -14,   -16,   -17,   -19,   -21,
+   -24,   -26,   -29,   -31,   -35,   -38,   -41,   -45,   -49,   -53,
+   -58,   -63,   -68,   -73,   -79,   -85,   -91,   -97,  -104,  -111,
+  -117,  -125,  -132,  -139,  -147,  -154,  -161,  -169,  -176,  -183,
+  -190,  -196,  -202,  -208,  -213,  -218,  -222,  -225,  -227,  -228,
+  -228,  -227,  -224,  -221,  -215,  -208,  -200,  -189,  -177,  -163,
+  -146,  -127,  -106,   -83,   -57,   -29,     2,    36,    72,   111,
+   153,   197,   244,   294,   347,   401,   459,   519,   581,   645,
+   711,   779,   848,   919,   991,  1064,  1137,  1210,  1283,  1356,
+  1428,  1498,  1567,  1634,  1698,  1759,  1817,  1870,  1919,  1962,
+  2001,  2032,  2057,  2075,  2085,  2087,  2080,  2063,  2037,  2000,
+  1952,  1893,  1822,  1739,  1644,  1535,  1414,  1280,  1131,   970,
+   794,   605,   402,   185,   -45,  -288,  -545,  -814, -1095, -1388,
+ -1692, -2006, -2330, -2663, -3004, -3351, -3705, -4063, -4425, -4788,
+ -5153, -5517, -5879, -6237, -6589, -6935, -7271, -7597, -7910, -8209,
+ -8491, -8755, -8998, -9219, -9416, -9585, -9727, -9838, -9916, -9959,
+ -9966, -9935, -9863, -9750, -9592, -9389, -9139, -8840, -8492, -8092,
+ -7640, -7134, -6574, -5959, -5288, -4561, -3776, -2935, -2037, -1082,
+   -70,   998,  2122,  3300,  4533,  5818,  7154,  8540,  9975, 11455,
+ 12980, 14548, 16155, 17799, 19478, 21189, 22929, 24694, 26482, 28289,
+ 30112, 31947, 33791, 35640, 37489, 39336, 41176, 43006, 44821, 46617,
+ 48390, 50137, 51853, 53534, 55178, 56778, 58333, 59838, 61289, 62684,
+ 64019, 65290, 66494, 67629, 68692, 69679, 70590, 71420, 72169, 72835,
+ 73415, 73908, 74313, 74630, 74856, 74992, 75038 };
+
+       void make_decode_tables(long scaleval)
+{
+  int i,j,k,kr,divv;
+  real *table,*costab;
+
+
+  for(i=0;i<5;i++)
+  {
+    kr=0x10>>i; divv=0x40>>i;
+    costab = pnts[i];
+    for(k=0;k<kr;k++) costab[k] = 1.0 / (2.0 * cos(M_PI * ((double) k * 2.0 + 1.0) / (double) divv));
+    #ifdef HAVE_3DNOW
+     if ( _3dnow ) for(k=0;k<kr;k++) costab[k+kr]=-costab[k];
+    #endif
+
+  }
+
+  table = decwin;
+  scaleval = -scaleval;
+  for(i=0,j=0;i<256;i++,j++,table+=32)
+  {
+         if(table < decwin+512+16)
+      table[16] = table[0] = (double) intwinbase[j] / 65536.0 * (double) scaleval;
+    if(i % 32 == 31)
+      table -= 1023;
+    if(i % 64 == 63)
+      scaleval = - scaleval;
+  }
+
+  for( /* i=256 */ ;i<512;i++,j--,table+=32)
+  {
+    if(table < decwin+512+16)
+      table[16] = table[0] = (double) intwinbase[j] / 65536.0 * (double) scaleval;
+    if(i % 32 == 31)
+      table -= 1023;
+    if(i % 64 == 63)
+      scaleval = - scaleval;
+  }
+  #ifdef HAVE_3DNOW
+   if ( _3dnow )
+    for(i=0;i<512+32;i++)
+     {
+      decwin[512+31-i]*=65536.0; // allows faster clipping in 3dnow code
+      decwin[512+32+i]=decwin[512+31-i];
+     }
+  #endif
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mplayer.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,1957 @@
+// AVI & MPEG Player    v0.11   (C) 2000-2001. by A'rpi/ESP-team
+
+//#define SIMULATE_ALSA
+
+#ifdef USE_XMMP_AUDIO
+#define OUTBURST 4096
+#else
+//#define OUTBURST 1024
+#define OUTBURST 512
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <signal.h>
+
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/soundcard.h>
+#include <linux/cdrom.h>
+
+#include "version.h"
+#include "config.h"
+
+// CODECS:
+#include "mp3lib/mp3.h"
+#include "libac3/ac3.h"
+#include "libmpeg2/mpeg2.h"
+#include "libmpeg2/mpeg2_internal.h"
+
+#include "loader.h"
+#include "wine/avifmt.h"
+//#include "libvo/video_out.h"      // included from mpeg2.h
+
+#include "opendivx/decore.h"
+
+
+#ifdef USE_XMMP_AUDIO
+#include "libxmm/xmmp.h"
+#include "libxmm/libxmm.h"
+XMM xmm;
+XMM_PluginSound *pSound=NULL;
+#endif
+
+
+extern char* win32_codec_name;  // must be set before calling DrvOpen() !!!
+
+extern int errno;
+
+#include "linux/getch2.h"
+#include "linux/keycodes.h"
+#include "linux/timer.h"
+#include "linux/shmem.h"
+
+#ifdef HAVE_LIRC
+#include "lirc_mp.h"
+#endif
+
+#include "help_mp.h"
+
+#define DEBUG if(0)
+static int verbose=0;
+
+static int max_framesize=0;
+
+static int dbg_es_sent=0;
+static int dbg_es_rcvd=0;
+
+//static int show_packets=0;
+
+//**************************************************************************//
+
+typedef struct {
+  // file:
+  MainAVIHeader avih;
+  unsigned int movi_start;
+  unsigned int movi_end;
+  // index:
+  AVIINDEXENTRY* idx;
+  int idx_size;
+  int idx_pos;
+  int idx_pos_a;
+  int idx_pos_v;
+  int idx_offset;  // ennyit kell hozzaadni az index offset ertekekhez
+//  int a_idx;
+//  int v_idx;
+  // video:
+  AVIStreamHeader video;
+  char *video_codec;
+  BITMAPINFOHEADER bih;   // in format
+  BITMAPINFOHEADER o_bih; // out format
+  HIC hic;
+  void *our_out_buffer;
+  unsigned int bitrate;
+  // video format flags:  (filled by codecs.c)
+  char yuv_supported;   // 1 if codec support YUY2 output format
+  char yuv_hack_needed; // requires for divx & mpeg4
+  char no_32bpp_support; // requires for INDEO 3.x, 4.x
+  char flipped;         // image is upside-down
+  // audio:
+  AVIStreamHeader audio;
+  char *audio_codec;
+  int audio_seekable;
+  char wf_ext[64];     // in format
+  WAVEFORMATEX wf;     // out format
+  HACMSTREAM srcstream;
+  int audio_in_minsize;
+  int audio_out_minsize;
+} avi_header_t;
+
+avi_header_t avi_header;
+
+#include "aviprint.c"
+#include "codecs.c"
+
+extern picture_t *picture;
+
+char* encode_name=NULL;
+char* encode_index_name=NULL;
+int encode_bitrate=0;
+
+//**************************************************************************//
+
+#include "stream.c"
+#include "demuxer.c"
+#include "demux_avi.c"
+#include "demux_mpg.c"
+
+demuxer_t *demuxer=NULL;
+demux_stream_t *d_audio=NULL;
+demux_stream_t *d_video=NULL;
+
+// MPEG video stream parser:
+#include "parse_es.c"
+
+//int mp3_read(char *buf,int size){
+int mplayer_audio_read(char *buf,int size){
+  int len;
+  len=demux_read_data(d_audio,buf,size);
+  return len;
+}
+
+static void ac3_fill_buffer(uint8_t **start,uint8_t **end){
+    int len=ds_get_packet(d_audio,(char**)start);
+    //printf("<ac3:%d>\n",len);
+    if(len<0)
+          *start = *end = NULL;
+    else
+          *end = *start + len;
+}
+
+#include "alaw.c"
+
+#include "xa/xa_gsm.h"
+
+unsigned char *opendivx_src[3];
+int opendivx_stride[3];
+
+void my_convert_yuv(unsigned char *puc_y, int stride_y,
+	unsigned char *puc_u, unsigned char *puc_v, int stride_uv,
+	unsigned char *bmp, int width_y, int height_y){
+
+//    vo_functions_t *video_out=(vo_functions_t *) bmp;
+
+//    printf("convert_yuv called  %dx%d  stride: %d,%d\n",width_y,height_y,stride_y,stride_uv);
+
+    opendivx_src[0]=puc_y;
+    opendivx_src[1]=puc_u;
+    opendivx_src[2]=puc_v;
+    
+    opendivx_stride[0]=stride_y;
+    opendivx_stride[1]=stride_uv;
+    opendivx_stride[2]=stride_uv;
+}
+
+//**************************************************************************//
+
+#ifdef SIMULATE_ALSA
+// Simulate ALSA buffering on OSS device :)  (for testing...)
+
+#define fake_ALSA_size 32768
+char fake_ALSA_buffer[fake_ALSA_size];
+int fake_ALSA_len=0;
+
+void fake_ALSA_write(int audio_fd,char* a_buffer,int len){
+while(len>0){
+  int x=fake_ALSA_size-fake_ALSA_len;
+  if(x>0){
+    if(x>len) x=len;
+    memcpy(&fake_ALSA_buffer[fake_ALSA_len],a_buffer,x);
+    fake_ALSA_len+=x;len-=x;
+  }
+  if(fake_ALSA_len>=fake_ALSA_size){
+    write(audio_fd,fake_ALSA_buffer,fake_ALSA_len);
+    fake_ALSA_len=0;
+  }
+}
+}
+#endif
+//**************************************************************************//
+
+// AVI file header reader/parser/writer:
+#include "aviheader.c"
+#include "aviwrite.c"
+
+// ASF headers:
+#include "asfheader.c"
+#include "demux_asf.c"
+
+// DLL codecs init routines
+#include "dll_init.c"
+
+// MPEG video codec process controller:
+#include "codecctrl.c"
+
+//**************************************************************************//
+
+static vo_functions_t *video_out=NULL;
+
+static int play_in_bg=0;
+
+void exit_player(char* how){
+  if(how) printf("\nExiting... (%s)\n",how);
+  printf("max framesize was %d bytes\n",max_framesize);
+  // restore terminal:
+  getch2_disable();
+  if(child_pid){
+    // MPEG
+      // printf("\n\n");
+      //send_cmd(data_fifo,0);usleep(50000); // EOF request
+    DEBUG_SIG { printf("Sending TERM signal to CTRL...\n");DEBUG_SIGNALS_SLEEP}
+      kill(child_pid,SIGTERM);
+      usleep(10000);  // kill & wait 10ms
+    DEBUG_SIG { printf("Closing PIPEs...\n");DEBUG_SIGNALS_SLEEP}
+      close(control_fifo);
+      close(data_fifo);
+    DEBUG_SIG { printf("Freeing shmem...\n");DEBUG_SIGNALS_SLEEP}
+      if(videobuffer) shmem_free(videobuffer);
+    DEBUG_SIG { printf("Exiting...\n");DEBUG_SIGNALS_SLEEP}
+  } else {
+  	// AVI
+	video_out->uninit();
+  }
+#ifdef USE_XMMP_AUDIO
+  if(verbose) printf("XMM: closing audio driver...\n");
+  if(pSound){
+    pSound->Exit( pSound );
+    xmm_Exit( &xmm );
+  }
+#endif
+  if(encode_name) avi_fixate();
+#ifdef HAVE_LIRC
+  lirc_mp_cleanup();
+#endif
+  //if(play_in_bg) system("xsetroot -solid \\#000000");
+  exit(1);
+}
+
+static char* current_module=NULL; // for debugging
+
+void exit_sighandler(int x){
+  static int sig_count=0;
+  ++sig_count;
+  if(sig_count==2) exit(1);
+  if(sig_count>2){
+    // can't stop :(
+    kill(getpid(),SIGKILL);
+  }
+  printf("\nMPlayer interrupted by signal %d in module: %s \n",x,
+      current_module?current_module:"unknown"
+  );
+  exit_player(NULL);
+}
+
+int divx_quality=0;
+
+int main(int argc,char* argv[]){
+char* filename=NULL; //"MI2-Trailer.avi";
+int i;
+int seek_to_sec=0;
+int seek_to_byte=0;
+int f; // filedes
+int stream_type;
+stream_t* stream=NULL;
+int file_format=DEMUXER_TYPE_UNKNOWN;
+int has_audio=1; // audio format  0=none  1=mpeg 2=pcm 3=ac3 4=win32 5=alaw 6=msgsm
+int has_video=0; // video format  0=none  1=mpeg 2=win32 3=OpenDivX
+//
+int audio_format=0; // override
+#ifdef ALSA_TIMER
+int alsa=1;
+#else
+int alsa=0;
+#endif
+int audio_buffer_size=-1;
+int audio_id=-1;
+int video_id=-1;
+float default_max_pts_correction=0.01f;
+int delay_corrected=1;
+float force_fps=0;
+float default_fps=25;
+float audio_delay=0;
+int vcd_track=0;
+#ifdef VCD_CACHE
+int vcd_cache_size=128;
+#endif
+int no_index=0;
+#ifdef AVI_SYNC_BPS
+int pts_from_bps=1;
+#else
+int pts_from_bps=0;
+#endif
+char* title="MPlayer";
+// screen info:
+char* video_driver=NULL; //"mga"; // default
+int fullscreen=0;
+int screen_size_x=SCREEN_SIZE_X;
+int screen_size_y=SCREEN_SIZE_Y;
+int screen_size_xy=0;
+// movie info:
+int movie_size_x=0;
+int movie_size_y=0;
+int out_fmt=0;
+char *dsp="/dev/dsp";
+int force_ni=0;
+
+  printf("%s",banner_text);
+
+for(i=1;i<argc;i++){
+  if(strcmp(argv[i],"-o")==0){
+    printf("Option -o has been changed to -vo (video-out), use -vo !\n");
+    exit(1);
+  } else
+  if(strcmp(argv[i],"-vo")==0)  video_driver=argv[++i]; else
+  if(strcmp(argv[i],"-dsp")==0) dsp=argv[++i]; else
+  if(strcmp(argv[i],"-encode")==0)  encode_name=argv[++i]; else
+  if(strcmp(argv[i],"-bg")==0) play_in_bg=1; else
+  if(strcmp(argv[i],"-sb")==0) seek_to_byte=strtol(argv[++i],NULL,0); else
+  if(strcmp(argv[i],"-ss")==0) seek_to_sec=strtol(argv[++i],NULL,0); else
+  if(strcmp(argv[i],"-nosound")==0) has_audio=0; else
+  if(strcmp(argv[i],"-abs")==0) audio_buffer_size=strtol(argv[++i],NULL,0); else
+  if(strcmp(argv[i],"-delay")==0) audio_delay=strtod(argv[++i],NULL); else
+#ifdef AVI_SYNC_BPS
+  if(strcmp(argv[i],"-nobps")==0) pts_from_bps=0; else
+#else
+  if(strcmp(argv[i],"-bps")==0) pts_from_bps=1; else
+#endif
+#ifdef ALSA_TIMER
+  if(strcmp(argv[i],"-noalsa")==0) alsa=0; else
+#else
+  if(strcmp(argv[i],"-alsa")==0) alsa=1; else
+#endif
+  if(strcmp(argv[i],"-ni")==0) force_ni=1; else
+  if(strcmp(argv[i],"-aid")==0) audio_id=strtol(argv[++i],NULL,0); else
+  if(strcmp(argv[i],"-vid")==0) video_id=strtol(argv[++i],NULL,0); else
+  if(strcmp(argv[i],"-auds")==0) avi_header.audio_codec=argv[++i]; else
+  if(strcmp(argv[i],"-vids")==0) avi_header.video_codec=argv[++i]; else
+  if(strcmp(argv[i],"-mc")==0) default_max_pts_correction=strtod(argv[++i],NULL); else
+  if(strcmp(argv[i],"-fps")==0) force_fps=strtod(argv[++i],NULL); else
+  if(strcmp(argv[i],"-afm")==0) audio_format=strtol(argv[++i],NULL,0); else
+  if(strcmp(argv[i],"-vcd")==0) vcd_track=strtol(argv[++i],NULL,0); else
+  if(strcmp(argv[i],"-divxq")==0) divx_quality=strtol(argv[++i],NULL,0); else
+  if(strcmp(argv[i],"-br")==0) encode_bitrate=strtol(argv[++i],NULL,0); else
+  if(strcmp(argv[i],"-x")==0) screen_size_x=strtol(argv[++i],NULL,0); else
+  if(strcmp(argv[i],"-y")==0) screen_size_y=strtol(argv[++i],NULL,0); else
+  if(strcmp(argv[i],"-xy")==0) screen_size_xy=strtol(argv[++i],NULL,0); else
+  if(strcmp(argv[i],"-fs")==0) fullscreen=1; else
+  if(strcmp(argv[i],"-noidx")==0) no_index=1; else
+  if(strcmp(argv[i],"-v")==0) ++verbose; else
+  if(strcmp(argv[i],"-h")==0) break; else
+  if(strcmp(argv[i],"--help")==0) break; else
+  { if(filename){ printf("invalid option: %s\n",filename);exit(1);}
+    filename=argv[i];
+  }
+}
+
+// Many users forget to include command line in bugreports...
+if(verbose){
+  printf("CommandLine:");
+  for(i=1;i<argc;i++)printf(" '%s'",argv[i]);
+  printf("\n");
+}
+
+if(video_driver && strcmp(video_driver,"help")==0){
+  printf("Available video output drivers:\n");
+  i=0;
+  while (video_out_drivers[i]) {
+    const vo_info_t *info = video_out_drivers[i++]->get_info ();
+  	printf("\t%s\t%s\n", info->short_name, info->name);
+  }
+  printf("\n");
+  exit(0);
+}
+
+// check video_out driver name:
+  if(!video_driver)
+    video_out=video_out_drivers[0];
+  else
+  for (i=0; video_out_drivers[i] != NULL; i++){
+    const vo_info_t *info = video_out_drivers[i]->get_info ();
+    if(strcmp(info->short_name,video_driver) == 0){
+      video_out = video_out_drivers[i];break;
+    }
+  }
+  if(!video_out){
+    printf("Invalid video output driver name: %s\n",video_driver);
+    return 0;
+  }
+
+
+if(!filename){
+  if(vcd_track) filename="/dev/cdrom"; 
+  else
+  //filename="MI2-Trailer.avi";
+  { printf("%s",help_text); exit(0);}
+}
+
+
+if(vcd_track){
+//============ Open VideoCD track ==============
+  f=open(filename,O_RDONLY);
+  if(f<0){ printf("CD-ROM Device '%s' not found!\n",filename);return 1; }
+  vcd_read_toc(f);
+  if(!vcd_seek_to_track(f,vcd_track)){ printf("Error selecting VCD track!\n");return 1;}
+  seek_to_byte+=VCD_SECTOR_DATA*vcd_get_msf();
+  if(verbose) printf("VCD start byte position: 0x%X\n",seek_to_byte);
+  stream_type=STREAMTYPE_VCD;
+#ifdef VCD_CACHE
+  vcd_cache_init(vcd_cache_size);
+#endif
+} else {
+//============ Open plain FILE ============
+  f=open(filename,O_RDONLY);
+  if(f<0){ printf("File not found: '%s'\n",filename);return 1; }
+  stream_type=STREAMTYPE_FILE;
+}
+
+stream=new_stream(f,stream_type);
+
+//============ Open & Sync stream and detect file format ===============
+
+if(has_audio==0) audio_id=-2; // do NOT read audio packets...
+
+//=============== Try to open as AVI file: =================
+stream_reset(stream);
+demuxer=new_demuxer(stream,DEMUXER_TYPE_AVI,audio_id,video_id);
+stream_seek(demuxer->stream,seek_to_byte);
+{ //---- RIFF header:
+  int id=stream_read_dword_le(demuxer->stream); // "RIFF"
+  if(id==mmioFOURCC('R','I','F','F')){
+    stream_read_dword_le(demuxer->stream); //filesize
+    id=stream_read_dword_le(demuxer->stream); // "AVI "
+    if(id==formtypeAVI){ 
+      printf("Detected AVI file format!\n");
+      file_format=DEMUXER_TYPE_AVI;
+    }
+  }
+}
+//=============== Try to open as ASF file: =================
+if(file_format==DEMUXER_TYPE_UNKNOWN){
+  stream_reset(stream);
+  demuxer=new_demuxer(stream,DEMUXER_TYPE_ASF,audio_id,video_id);
+  stream_seek(demuxer->stream,seek_to_byte);
+  if(asf_check_header()){
+      printf("Detected ASF file format!\n");
+      file_format=DEMUXER_TYPE_ASF;
+//      printf("!!! ASF files not (yet) supported !!!\n");exit(1);
+  }
+}
+//=============== Try to open as MPEG-PS file: =================
+if(file_format==DEMUXER_TYPE_UNKNOWN){
+  stream_reset(stream);
+  demuxer=new_demuxer(stream,DEMUXER_TYPE_MPEG_PS,audio_id,video_id);
+  stream_seek(demuxer->stream,seek_to_byte);
+  if(audio_format) demuxer->audio->type=audio_format; // override audio format
+  if(ds_fill_buffer(demuxer->video)){
+    printf("Detected MPEG-PS file format!\n");
+    file_format=DEMUXER_TYPE_MPEG_PS;
+  } else {
+    // some hack to get meaningfull error messages to our unhappy users:
+//    if(num_elementary_packets100>16 &&
+//       abs(num_elementary_packets101-num_elementary_packets100)<8){
+    if(num_elementary_packets100>=2 && num_elementary_packets101>=2 &&
+       abs(num_elementary_packets101-num_elementary_packets100)<8){
+      file_format=DEMUXER_TYPE_MPEG_ES; //  <-- hack is here :)
+    } else {
+      if(demuxer->synced==2)
+        printf("Missing MPEG video stream!? contact the author, it may be a bug :(\n");
+      else
+        printf("Not MPEG System Stream format... (maybe Transport Stream?)\n");
+    }
+  }
+}
+//=============== Try to open as MPEG-ES file: =================
+if(file_format==DEMUXER_TYPE_MPEG_ES){ // little hack, see above!
+  stream_reset(stream);
+  demuxer=new_demuxer(stream,DEMUXER_TYPE_MPEG_ES,audio_id,video_id);
+  stream_seek(demuxer->stream,seek_to_byte);
+  if(!ds_fill_buffer(demuxer->video)){
+    printf("Invalid MPEG-ES stream??? contact the author, it may be a bug :(\n");
+    file_format=DEMUXER_TYPE_UNKNOWN;
+  } else {
+    printf("Detected MPEG-ES file format!\n");
+  }
+}
+//=============== Unknown, exiting... ===========================
+if(file_format==DEMUXER_TYPE_UNKNOWN){
+  printf("============= Sorry, this file format not recognized/supported ===============\n");
+  printf("=== If this file is an AVI, ASF or MPEG stream, please contact the author! ===\n");
+  exit(1);
+}
+//====== File format recognized, set up these for compatibility: =========
+d_audio=demuxer->audio;
+d_video=demuxer->video;
+
+switch(file_format){
+ case DEMUXER_TYPE_AVI: {
+  //---- AVI header:
+  read_avi_header(no_index);
+  stream_reset(demuxer->stream);
+  stream_seek(demuxer->stream,avi_header.movi_start);
+  avi_header.idx_pos=0;
+  avi_header.idx_pos_a=0;
+  avi_header.idx_pos_v=0;
+  if(avi_header.idx_size>0){
+    // decide index format:
+    if(avi_header.idx[0].dwChunkOffset<avi_header.movi_start)
+      avi_header.idx_offset=avi_header.movi_start-4;
+    else
+      avi_header.idx_offset=0;
+    if(verbose) printf("AVI index offset: %d\n",avi_header.idx_offset);
+  }
+  demuxer->endpos=avi_header.movi_end;
+  
+  if(avi_header.idx_size>0){
+      // check that file is non-interleaved:
+      int i;
+      int a_pos=-1;
+      int v_pos=-1;
+      for(i=0;i<avi_header.idx_size;i++){
+        AVIINDEXENTRY* idx=&avi_header.idx[i];
+        demux_stream_t* ds=demux_avi_select_stream(demuxer,idx->ckid);
+        int pos=idx->dwChunkOffset+avi_header.idx_offset;
+        if(a_pos==-1 && ds==demuxer->audio){
+          a_pos=pos;
+          if(v_pos!=-1) break;
+        }
+        if(v_pos==-1 && ds==demuxer->video){
+          v_pos=pos;
+          if(a_pos!=-1) break;
+        }
+      }
+      if(v_pos==-1){
+        printf("AVI_NI: missing video stream!? contact the author, it may be a bug :(\n");
+        exit(1);
+      }
+      if(a_pos==-1){
+        printf("AVI_NI: No audio stream found -> nosound\n");
+        has_audio=0;
+      } else {
+        if(force_ni || abs(a_pos-v_pos)>0x100000){  // distance > 1MB
+          printf("Detected NON-INTERLEAVED AVI file-format!\n");
+          file_format=DEMUXER_TYPE_AVI_NI; // HACK!!!!
+          demuxer->type=DEMUXER_TYPE_AVI_NI; // HACK!!!!
+	  pts_from_bps=1; // force BPS sync!
+        }
+      }
+  } else {
+      // no index
+      if(force_ni){
+          printf("Using NON-INTERLEAVED Broken AVI file-format!\n");
+//          file_format=DEMUXER_TYPE_AVI_NI; // HACK!!!!
+          demuxer->type=DEMUXER_TYPE_AVI_NINI; // HACK!!!!
+	  avi_header.idx_pos_a=
+	  avi_header.idx_pos_v=avi_header.movi_start;
+	  pts_from_bps=1; // force BPS sync!
+      }
+  }
+  
+  if(!ds_fill_buffer(d_video)){
+    printf("AVI: missing video stream!? contact the author, it may be a bug :(\n");
+    exit(1);
+  }
+  has_video=2;
+  // Decide audio format:
+  if(audio_format)
+    has_audio=audio_format; // override type
+  else if(has_audio)
+    switch(((WAVEFORMATEX *)&avi_header.wf_ext)->wFormatTag){
+      case 0:
+        has_audio=0;break; // disable/no audio
+      case 6:
+        avi_header.audio_seekable=1;
+        has_audio=5;break; // aLaw
+      case 0x31:
+      case 0x32:
+        has_audio=6;break; // MS-GSM
+      case 0x50:
+#ifdef DEFAULT_MPG123
+      case 0x55:
+#endif
+        avi_header.audio_seekable=1;
+        has_audio=1;break; // MPEG
+      case 0x01:
+        avi_header.audio_seekable=1;
+        has_audio=2;break; // PCM
+      case 0x2000:
+        avi_header.audio_seekable=1;
+        has_audio=3;break; // AC3
+      default:
+        avi_header.audio_seekable=0;
+        has_audio=4;       // Win32/ACM
+    }
+  if(verbose) printf("detected AVI audio format: %d\n",has_audio);
+  if(has_audio==4){
+    if(!avi_header.audio_codec) avi_header.audio_codec=get_auds_codec_name();
+    if(!avi_header.audio_codec) has_audio=0; // unknown win32 codec
+    if(verbose) printf("win32 audio codec: '%s'\n",avi_header.audio_codec);
+  }
+  if(has_audio){
+    if(verbose) printf("AVI: Searching for audio stream (id:%d)\n",d_audio->id);
+    if(!ds_fill_buffer(d_audio)){
+      printf("AVI: No Audio stream found...  ->nosound\n");
+      has_audio=0;
+    }
+  }
+  default_fps=(float)avi_header.video.dwRate/(float)avi_header.video.dwScale;
+  break;
+ }
+ case DEMUXER_TYPE_ASF: {
+  //---- ASF header:
+  read_asf_header();
+  stream_reset(demuxer->stream);
+  stream_seek(demuxer->stream,avi_header.movi_start);
+  avi_header.idx_pos=0;
+#if 0
+  if(avi_header.idx_size>0){
+    // decide index format:
+    if(avi_header.idx[0].dwChunkOffset<avi_header.movi_start)
+      avi_header.idx_offset=avi_header.movi_start-4;
+    else
+      avi_header.idx_offset=0;
+    if(verbose) printf("ASF index offset: %d\n",avi_header.idx_offset);
+  }
+#endif
+  demuxer->endpos=avi_header.movi_end;
+  if(!ds_fill_buffer(d_video)){
+    printf("ASF: missing video stream!? contact the author, it may be a bug :(\n");
+    exit(1);
+  }
+  has_video=2;
+  // Decide audio format:
+  if(audio_format)
+    has_audio=audio_format; // override type
+  else if(has_audio)
+    switch(((WAVEFORMATEX *)&avi_header.wf_ext)->wFormatTag){
+      case 0:
+        has_audio=0;break; // disable/no audio
+      case 6:
+        avi_header.audio_seekable=1;
+        has_audio=5;break; // aLaw
+      case 0x31:
+      case 0x32:
+        has_audio=6;break; // MS-GSM
+      case 0x50:
+#ifdef DEFAULT_MPG123
+      case 0x55:
+#endif
+        avi_header.audio_seekable=1;
+        has_audio=1;break; // MPEG
+      case 0x01:
+        avi_header.audio_seekable=1;
+        has_audio=2;break; // PCM
+      case 0x2000:
+        avi_header.audio_seekable=1;
+        has_audio=3;break; // AC3
+      default:
+        avi_header.audio_seekable=0;
+        has_audio=4;       // Win32/ACM
+    }
+  if(verbose) printf("detected ASF audio format: %d\n",has_audio);
+  if(has_audio==4){
+    if(!avi_header.audio_codec) avi_header.audio_codec=get_auds_codec_name();
+    if(!avi_header.audio_codec) has_audio=0; // unknown win32 codec
+    if(verbose) printf("win32 audio codec: '%s'\n",avi_header.audio_codec);
+  }
+  if(has_audio){
+    if(verbose) printf("ASF: Searching for audio stream (id:%d)\n",d_audio->id);
+    if(!ds_fill_buffer(d_audio)){
+      printf("ASF: No Audio stream found...  ->nosound\n");
+      has_audio=0;
+    }
+  }
+  break;
+ }
+ case DEMUXER_TYPE_MPEG_ES: {
+  demuxer->audio->type=0;
+  has_audio=0; // ES streams has no audio channel
+  has_video=1; // mpeg video
+  break;
+ }
+ case DEMUXER_TYPE_MPEG_PS: {
+  if(has_audio)
+  if(!ds_fill_buffer(d_audio)){
+    printf("MPEG: No Audio stream found...  ->nosound\n");
+    has_audio=0;
+  } else {
+    has_audio=d_audio->type;
+  }
+  if(verbose) printf("detected MPG-PS audio format: %d\n",has_audio);
+  has_video=1; // mpeg video
+  break;
+ }
+} // switch(file_format)
+
+if(verbose) printf("file successfully opened  (has_audio=%d)\n",has_audio);
+
+fflush(stdout);
+
+//================== Init VIDEO (codec & libvo) ==========================
+
+if(has_video==2){
+  if(avi_header.video.fccHandler==mmioFOURCC('d', 'v', 'x', '1')) has_video=3;
+  if(avi_header.video.fccHandler==mmioFOURCC('d', 'i', 'v', 'x')) has_video=3;
+  if(avi_header.bih.biCompression==mmioFOURCC('d', 'v', 'x', '1')) has_video=3;
+  if(avi_header.bih.biCompression==mmioFOURCC('d', 'i', 'v', 'x')) has_video=3;
+}
+
+switch(has_video){
+ case 2: {
+   if(!avi_header.video_codec) avi_header.video_codec=get_vids_codec_name();
+   if(verbose)
+     printf("win32 video codec: '%s' %s%s%s\n",avi_header.video_codec,
+       avi_header.yuv_supported?"[YUV]":"",
+       avi_header.yuv_hack_needed?"[hack]":"",
+       avi_header.flipped?"[FLIP]":""
+     );
+   if(!avi_header.video_codec) exit(1); // unknown video codec
+   if(avi_header.yuv_supported && video_out->query_format(IMGFMT_YUY2)) out_fmt=IMGFMT_YUY2; else
+   if(avi_header.no_32bpp_support && video_out->query_format(IMGFMT_BGR|32)) out_fmt=IMGFMT_BGR|24; else
+   if(video_out->query_format(IMGFMT_BGR|15)) out_fmt=IMGFMT_BGR|16; else
+   if(video_out->query_format(IMGFMT_BGR|16)) out_fmt=IMGFMT_BGR|16; else
+   if(video_out->query_format(IMGFMT_BGR|24)) out_fmt=IMGFMT_BGR|24; else
+   if(video_out->query_format(IMGFMT_BGR|32)) out_fmt=IMGFMT_BGR|32; else {
+     printf("Sorry, selected video_out device is incompatible with this codec.\n");
+     printf("(It can't show 24bpp or 32bpp RGB images. Try to run X at 24/32bpp!)\n");
+//     printf("(cannot convert between YUY2, YV12 and RGB colorspace formats)\n");
+     exit(1);
+   }
+   //if(verbose) printf("AVI out_fmt=%X\n",out_fmt);
+   if(verbose) if(out_fmt==IMGFMT_YUY2) printf("Using YUV/YUY2 video output format!\n");
+   if(!init_video_codec(out_fmt)) exit(1);
+   if(verbose) printf("INFO: Win32 video codec init OK!\n");
+   if(out_fmt==(IMGFMT_BGR|16)) out_fmt=IMGFMT_BGR|15; // fix bpp
+   
+   // calculating video bitrate:
+   avi_header.bitrate=avi_header.movi_end-avi_header.movi_start-avi_header.idx_size*8;
+   if(avi_header.audio.fccType) avi_header.bitrate-=avi_header.audio.dwLength;
+   if(verbose) printf("AVI video length=%d\n",avi_header.bitrate);
+   avi_header.bitrate=((float)avi_header.bitrate/(float)avi_header.video.dwLength)
+                     *((float)avi_header.video.dwRate/(float)avi_header.video.dwScale);
+//   default_fps=(float)avi_header.video.dwRate/(float)avi_header.video.dwScale;
+   printf("VIDEO:  [%.4s]  %dx%d  %dbpp  %4.2f fps  %5.1f kbps (%4.1f kbyte/s)\n",
+    &avi_header.bih.biCompression,
+    avi_header.bih.biWidth,
+    avi_header.bih.biHeight,
+    avi_header.bih.biBitCount,
+    default_fps,
+    avi_header.bitrate*0.008f,
+    avi_header.bitrate/1024.0f );
+
+   // display info:
+   movie_size_x=avi_header.o_bih.biWidth;
+   movie_size_y=abs(avi_header.o_bih.biHeight);
+   break;
+ }
+ case 3: {  // OpenDivX
+   if(verbose) printf("OpenDivX video codec\n");
+   out_fmt=IMGFMT_YV12;
+   { DEC_PARAM dec_param;
+     DEC_SET dec_set;
+	dec_param.x_dim = avi_header.bih.biWidth;
+	dec_param.y_dim = avi_header.bih.biHeight;
+	dec_param.color_depth = 32;
+	decore(0x123, DEC_OPT_INIT, &dec_param, NULL);
+	dec_set.postproc_level = divx_quality;
+	decore(0x123, DEC_OPT_SETPP, &dec_set, NULL);
+   }
+   if(verbose) printf("INFO: OpenDivX video codec init OK!\n");
+   
+   // calculating video bitrate:
+   avi_header.bitrate=avi_header.movi_end-avi_header.movi_start-avi_header.idx_size*8;
+   if(avi_header.audio.fccType) avi_header.bitrate-=avi_header.audio.dwLength;
+   if(verbose) printf("AVI video length=%d\n",avi_header.bitrate);
+   avi_header.bitrate=((float)avi_header.bitrate/(float)avi_header.video.dwLength)
+                     *((float)avi_header.video.dwRate/(float)avi_header.video.dwScale);
+//   default_fps=(float)avi_header.video.dwRate/(float)avi_header.video.dwScale;
+   printf("VIDEO:  [%.4s]  %dx%d  %dbpp  %4.2f fps  %5.1f kbps (%4.1f kbyte/s)\n",
+    &avi_header.bih.biCompression,
+    avi_header.bih.biWidth,
+    avi_header.bih.biHeight,
+    avi_header.bih.biBitCount,
+    default_fps,
+    avi_header.bitrate*0.008f,
+    avi_header.bitrate/1024.0f );
+
+   // display info:
+//   movie_size_x=avi_header.bih.biWidth+(divx_quality?0:64);
+   movie_size_x=avi_header.bih.biWidth;
+   movie_size_y=abs(avi_header.bih.biHeight);
+   break;
+ }
+ case 1: {
+   // Find sequence_header first:
+   if(verbose) printf("Searching for sequence header... ");fflush(stdout);
+   while(1){
+      int i=sync_video_packet(d_video);
+      if(i==0x1B3) break; // found it!
+      if(!i || !skip_video_packet(d_video)){
+        if(verbose)  printf("NONE :(\n");
+        printf("MPEG: FATAL: EOF while searching for sequence header\n");
+        exit(1);
+      }
+   }
+   if(verbose) printf("FOUND!\n");
+   // allocate some shared memory for the video packet buffer:
+   videobuffer=shmem_alloc(VIDEOBUFFER_SIZE);
+   if(!videobuffer){ printf("Cannot allocate shared memory\n");exit(0);}
+   // init libmpeg2:
+   mpeg2_init();
+   picture->pp_options=divx_quality;
+   if(verbose)  printf("mpeg2_init() ok\n");
+   // ========= Read & process sequence header & extension ============
+   videobuf_len=0;
+   if(!read_video_packet(d_video)){ printf("FATAL: Cannot read sequence header!\n");return 1;}
+   if(header_process_sequence_header (picture, &videobuffer[4])) {
+     printf ("bad sequence header!\n"); return 1;
+   }
+   if(sync_video_packet(d_video)==0x1B5){ // next packet is seq. ext.
+    videobuf_len=0;
+    if(!read_video_packet(d_video)){ printf("FATAL: Cannot read sequence header extension!\n");return 1;}
+    if(header_process_extension (picture, &videobuffer[4])) {
+      printf ("bad sequence header extension!\n"); return 1;
+    }
+   }
+   default_fps=picture->frame_rate*0.0001f;
+   if(verbose) printf("mpeg bitrate: %d (%X)\n",picture->bitrate,picture->bitrate);
+   printf("VIDEO:  %s  %dx%d  (aspect %d)  %4.2f fps  %5.1f kbps (%4.1f kbyte/s)\n",
+    picture->mpeg1?"MPEG1":"MPEG2",
+    picture->display_picture_width,picture->display_picture_height,
+    picture->aspect_ratio_information,
+    default_fps,
+    picture->bitrate*0.5f,
+    picture->bitrate/16.0f );
+   // display info:
+   out_fmt=IMGFMT_YV12;
+//   movie_size_x=picture->coded_picture_width;
+   movie_size_x=picture->display_picture_width;
+   movie_size_y=picture->display_picture_height;
+   break;
+ }
+}
+
+// ================== Init output files for encoding ===============
+   if(encode_name){
+     // encode file!!!
+     FILE *encode_file=fopen(encode_name,"rb");
+     if(encode_file){
+       fclose(encode_file);
+       printf("File already exists: %s (don't overwrite your favourite AVI!)\n",encode_name);
+       return 0;
+     }
+     encode_file=fopen(encode_name,"wb");
+     if(!encode_file){
+       printf("Cannot create file for encoding\n");
+       return 0;
+     }
+     write_avi_header_1(encode_file,mmioFOURCC('d', 'i', 'v', 'x'),default_fps,movie_size_x,movie_size_y);
+     fclose(encode_file);
+     encode_index_name=malloc(strlen(encode_name)+8);
+     strcpy(encode_index_name,encode_name);
+     strcat(encode_index_name,".index");
+     if((encode_file=fopen(encode_index_name,"wb")))
+       fclose(encode_file);
+     else encode_index_name=NULL;
+     has_audio=0; // disable audio !!!!!
+   }
+
+// ========== Init keyboard FIFO (connection to libvo) ============
+
+make_pipe(&keyb_fifo_get,&keyb_fifo_put);
+
+// ========== Init display (movie_size_x*movie_size_y/out_fmt) ============
+
+#ifdef X11_FULLSCREEN
+   if(fullscreen){
+     if(vo_init()){
+       //if(verbose) printf("X11 running at %dx%d depth: %d\n",vo_screenwidth,vo_screenheight,vo_depthonscreen);
+     }
+     if(!screen_size_xy) screen_size_xy=vo_screenwidth; // scale with asp.ratio
+   }
+#endif
+
+   if(screen_size_xy>0){
+     if(screen_size_xy<=8){
+       screen_size_x=screen_size_xy*movie_size_x;
+       screen_size_y=screen_size_xy*movie_size_y;
+     } else {
+       screen_size_x=screen_size_xy;
+       screen_size_y=screen_size_xy*movie_size_y/movie_size_x;
+     }
+   } else {
+     if(screen_size_x<=8) screen_size_x*=movie_size_x;
+     if(screen_size_y<=8) screen_size_y*=movie_size_y;
+   }
+   if(verbose) printf("Destination size: %d x %d  out_fmt=%0X\n",
+                      screen_size_x,screen_size_y,out_fmt);
+
+   if(verbose) printf("video_out->init(%dx%d->%dx%d,fs=%d,'%s',0x%X)\n",
+                      movie_size_x,movie_size_y,
+                      screen_size_x,screen_size_y,
+                      fullscreen,title,out_fmt);
+
+   if(video_out->init(movie_size_x,movie_size_y,
+                      screen_size_x,screen_size_y,
+                      fullscreen,title,out_fmt)){
+     printf("FATAL: Cannot initialize video driver!\n");exit(1);
+   }
+   if(verbose) printf("INFO: Video OUT driver init OK!\n");
+
+   fflush(stdout);
+   
+  
+if(has_video==1){
+   //================== init mpeg codec ===================
+   mpeg2_allocate_image_buffers (picture);
+   if(verbose) printf("INFO: mpeg2_init_video() OK!\n");
+   // ====== Init MPEG codec process ============
+   make_pipe(&control_fifo,&control_fifo2);
+   make_pipe(&data_fifo2,&data_fifo);
+   // ====== Let's FORK() !!! ===================
+   if((child_pid=fork())==0)
+     mpeg_codec_controller(video_out); // this one is running in a new process!!!!
+   signal(SIGPIPE,SIG_IGN);  // Ignore "Broken pipe" signal (codec restarts)
+}
+
+//================== MAIN: ==========================
+{
+char* a_buffer=NULL;
+int a_buffer_len=0;
+int a_buffer_size=0;
+char* a_in_buffer=NULL;
+int a_in_buffer_len=0;
+int a_in_buffer_size=0;
+int audio_fd=-1;
+int pcm_bswap=0;
+float buffer_delay=0;
+float frame_correction=0; // A-V timestamp kulonbseg atlagolas
+int frame_corr_num=0;   //
+float a_frame=0;    // Audio
+float v_frame=0;    // Video
+float time_frame=0; // Timer
+float a_pts=0;
+float v_pts=0;
+float c_total=0;
+float max_pts_correction=default_max_pts_correction;
+int eof=0;
+int force_redraw=0;
+ac3_frame_t *ac3_frame=NULL;
+float num_frames=0;      // number of frames played
+//int real_num_frames=0;   // number of frames readed
+double video_time_usage=0;
+double vout_time_usage=0;
+double audio_time_usage=0;
+
+#ifdef HAVE_LIRC
+  lirc_mp_setup();
+#endif
+
+#ifdef USE_TERMCAP
+  load_termcap(NULL); // load key-codes
+#endif
+  getch2_enable();
+
+  //========= Catch terminate signals: ================
+  // terminate requests:
+  signal(SIGTERM,exit_sighandler); // kill
+  signal(SIGHUP,exit_sighandler);  // kill -HUP  /  xterm closed
+  signal(SIGINT,exit_sighandler);  // Interrupt from keyboard
+  signal(SIGQUIT,exit_sighandler); // Quit from keyboard
+  // fatal errors:
+  signal(SIGBUS,exit_sighandler);  // bus error
+  signal(SIGSEGV,exit_sighandler); // segfault
+  signal(SIGILL,exit_sighandler);  // illegal instruction
+  signal(SIGFPE,exit_sighandler);  // floating point exc.
+  signal(SIGABRT,exit_sighandler); // abort()
+
+//================ SETUP AUDIO ==========================
+  current_module="setup_audio";
+
+if(has_audio){
+
+  if(verbose) printf("Initializing audio codec...\n");
+
+MP3_bps=2;
+pcm_bswap=0;
+a_buffer_size=16384;        // default size, maybe not enough for Win32/ACM
+
+if(has_audio==4){
+  // Win32 ACM audio codec:
+  if(init_audio_codec()){
+    MP3_channels=avi_header.wf.nChannels;
+    MP3_samplerate=avi_header.wf.nSamplesPerSec;
+    a_in_buffer_size=avi_header.audio_in_minsize;
+    a_in_buffer=malloc(a_in_buffer_size);
+    a_in_buffer_len=0;
+    if(a_buffer_size<avi_header.audio_out_minsize+OUTBURST)
+        a_buffer_size=avi_header.audio_out_minsize+OUTBURST;
+  } else {
+    printf("Could not load/initialize Win32/ACM AUDIO codec (missing DLL file?)\n");
+    if((((WAVEFORMATEX *)&avi_header.wf_ext)->wFormatTag)==0x55){
+      printf("Audio format is MP3 -> fallback to internal mp3lib/mpg123\n");
+      has_audio=1;  // fallback to mp3lib
+    } else
+      has_audio=0;  // nosound
+  }
+}
+
+// allocate audio out buffer:
+a_buffer=malloc(a_buffer_size);
+memset(a_buffer,0,a_buffer_size);
+a_buffer_len=0;
+
+if(has_audio==2){
+  if(file_format==DEMUXER_TYPE_AVI || file_format==DEMUXER_TYPE_AVI_NI){
+    // AVI PCM Audio:
+    WAVEFORMATEX *h=(WAVEFORMATEX*)&avi_header.wf_ext;
+    MP3_channels=h->nChannels;
+    MP3_samplerate=h->nSamplesPerSec;
+    MP3_bps=(h->wBitsPerSample+7)/8;
+  } else {
+    // DVD PCM audio:
+    MP3_channels=2;
+    MP3_samplerate=48000;
+    pcm_bswap=1;
+  }
+} else
+if(has_audio==3){
+  // Dolby AC3 audio:
+  ac3_config.fill_buffer_callback = ac3_fill_buffer;
+  ac3_config.num_output_ch = 2;
+  ac3_config.flags = 0;
+#ifdef HAVE_MMX
+  ac3_config.flags |= AC3_MMX_ENABLE;
+#endif
+#ifdef HAVE_3DNOW
+  ac3_config.flags |= AC3_3DNOW_ENABLE;
+#endif
+  ac3_init();
+  ac3_frame = ac3_decode_frame();
+  if(ac3_frame){
+    MP3_samplerate=ac3_frame->sampling_rate;
+    MP3_channels=2;
+  } else has_audio=0; // bad frame -> disable audio
+} else
+if(has_audio==5){
+  // aLaw audio codec:
+  Gen_aLaw_2_Signed(); // init table
+  MP3_channels=((WAVEFORMATEX*)&avi_header.wf_ext)->nChannels;
+  MP3_samplerate=((WAVEFORMATEX*)&avi_header.wf_ext)->nSamplesPerSec;
+} else
+if(has_audio==6){
+  // MS-GSM audio codec:
+  GSM_Init();
+  MP3_channels=((WAVEFORMATEX*)&avi_header.wf_ext)->nChannels;
+  MP3_samplerate=((WAVEFORMATEX*)&avi_header.wf_ext)->nSamplesPerSec;
+}
+// must be here for Win32->mp3lib fallbacks
+if(has_audio==1){
+  // MPEG Audio:
+  MP3_Init();
+  MP3_samplerate=MP3_channels=0;
+//  printf("[\n");
+  a_buffer_len=MP3_DecodeFrame(a_buffer,-1);
+//  printf("]\n");
+  MP3_channels=2; // hack
+}
+
+if(verbose) printf("Audio: type: %d  samplerate=%d  channels=%d  bps=%d\n",has_audio,MP3_samplerate,MP3_channels,MP3_bps);
+
+if(!MP3_channels || !MP3_samplerate){
+  printf("Unknown/missing audio format, using nosound\n");
+  has_audio=0;
+}
+
+if(has_audio){
+#ifdef USE_XMMP_AUDIO
+  xmm_Init( &xmm );
+  xmm.cSound = (XMM_PluginSound *)xmm_PluginRegister( XMMP_AUDIO_DRIVER );
+  if( xmm.cSound ){
+    pSound = xmm.cSound->Init( &xmm );
+    if( pSound && pSound->Start( pSound, MP3_samplerate, MP3_channels,
+                ( MP3_bps == 2 ) ?  XMM_SOUND_FMT_S16LE : XMM_SOUND_FMT_U8 )){
+        printf("XMM: audio setup ok\n");
+    } else {
+      has_audio=0;
+    }
+  } else has_audio=0;
+#else
+  audio_fd=open(dsp, O_WRONLY);
+  if(audio_fd<0){
+    printf("Can't open audio device %s  -> nosound\n",dsp);
+    has_audio=0;
+  }
+#endif
+}
+
+if(has_audio){
+#ifdef USE_XMMP_AUDIO
+  if(audio_buffer_size==-1){
+    // Measuring buffer size:
+    buffer_delay=pSound->QueryDelay(pSound, 0);
+  } else {
+    // -abs commandline option
+    buffer_delay=audio_buffer_size/(float)(MP3_samplerate*MP3_channels*MP3_bps);
+  }
+#else
+  int r;
+  r=(MP3_bps==2)?AFMT_S16_LE:AFMT_U8;ioctl (audio_fd, SNDCTL_DSP_SETFMT, &r);
+  r=MP3_channels-1; ioctl (audio_fd, SNDCTL_DSP_STEREO, &r);
+  r=MP3_samplerate; if(ioctl (audio_fd, SNDCTL_DSP_SPEED, &r)==-1)
+      printf("audio_setup: your card doesn't support %d Hz samplerate\n",r);
+
+  if(audio_buffer_size==-1){
+    // Measuring buffer size:
+    audio_buffer_size=0;
+#ifdef HAVE_AUDIO_SELECT
+    while(audio_buffer_size<0x40000){
+      fd_set rfds;
+      struct timeval tv;
+      FD_ZERO(&rfds); FD_SET(audio_fd,&rfds);
+      tv.tv_sec=0; tv.tv_usec = 0;
+      if(!select(audio_fd+1, NULL, &rfds, NULL, &tv)) break;
+      write(audio_fd,&a_buffer[a_buffer_len],OUTBURST);
+      audio_buffer_size+=OUTBURST;
+    }
+    if(audio_buffer_size==0){
+        printf("\n   ***  Your audio driver DOES NOT support select()  ***\n");
+          printf("Recompile mplayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n");
+        exit_player("audio_init");
+    }
+#endif
+  }
+  buffer_delay=audio_buffer_size/(float)(MP3_samplerate*MP3_channels*MP3_bps);
+#endif
+  a_frame=-(buffer_delay);
+  printf("Audio buffer size: %d bytes, delay: %5.3fs\n",audio_buffer_size,buffer_delay);
+}
+
+} // has_audio
+
+if(has_audio){
+  printf("Audio: type: %d  samplerate: %d  channels: %d  bps: %d\n",has_audio,MP3_samplerate,MP3_channels,MP3_bps);
+} else {
+  printf("Audio: no sound\n");
+  if(verbose) printf("Freeing %d unused audio chunks\n",d_audio->packs);
+  ds_free_packs(d_audio); // free buffered chunks
+  d_audio->id=-2;         // do not read audio chunks
+  if(a_buffer) free(a_buffer);
+  alsa=1; MP3_samplerate=44100;MP3_bps=MP3_channels=2; // fake, required for timer
+}
+
+  current_module=NULL;
+
+//==================== START PLAYING =======================
+
+if(file_format==DEMUXER_TYPE_AVI || file_format==DEMUXER_TYPE_AVI_NI){
+  a_pts=d_audio->pts-(buffer_delay+audio_delay);
+  audio_delay-=(float)(avi_header.audio.dwInitialFrames-avi_header.video.dwInitialFrames)/default_fps;
+//  audio_delay-=(float)(avi_header.audio.dwInitialFrames-avi_header.video.dwInitialFrames)/default_fps;
+  printf("AVI Initial frame delay: %5.3f\n",(float)(avi_header.audio.dwInitialFrames-avi_header.video.dwInitialFrames)/default_fps);
+  printf("v: audio_delay=%5.3f  buffer_delay=%5.3f  a_pts=%5.3f  a_frame=%5.3f\n",
+           audio_delay,buffer_delay,a_pts,a_frame);
+  printf("START:  a_pts=%5.3f  v_pts=%5.3f  \n",d_audio->pts,d_video->pts);
+  delay_corrected=0; // has to correct PTS diffs
+  d_video->pts=0;d_audio->pts=0; // PTS is outdated now!
+}
+if(force_fps) default_fps=force_fps;
+
+printf("Start playing...\n");fflush(stdout);
+
+if(0)        // ACM debug code
+{   DWORD srcsize=0;
+    DWORD dstsize=16384*8;
+    int ret=acmStreamSize(avi_header.srcstream,dstsize, &srcsize, ACM_STREAMSIZEF_DESTINATION);
+    printf("acmStreamSize %d -> %d (err=%d)\n",dstsize,srcsize,ret);
+}
+
+InitTimer();
+
+while(!eof){
+
+/*========================== PLAY AUDIO ============================*/
+
+while(has_audio){
+  unsigned int t=GetTimer();
+  current_module="decode_audio";   // Enter AUDIO decoder module
+  // Update buffer if needed
+  while(a_buffer_len<OUTBURST && !d_audio->eof){
+    switch(has_audio){
+      case 1: // MPEG layer 2 or 3
+        a_buffer_len+=MP3_DecodeFrame(&a_buffer[a_buffer_len],-1);
+        MP3_channels=2; // hack
+        break;
+      case 2: // PCM
+      { int i=demux_read_data(d_audio,&a_buffer[a_buffer_len],OUTBURST);
+        if(pcm_bswap){
+          int j;
+          if(i&3){ printf("Warning! pcm_audio_size&3 !=0  (%d)\n",i);i&=~3; }
+          for(j=0;j<i;j+=2){
+            char x=a_buffer[a_buffer_len+j];
+            a_buffer[a_buffer_len+j]=a_buffer[a_buffer_len+j+1];
+            a_buffer[a_buffer_len+j+1]=x;
+          }
+        }
+        a_buffer_len+=i;
+        break;
+      }
+      case 5:  // aLaw decoder
+      { int l=demux_read_data(d_audio,&a_buffer[a_buffer_len],OUTBURST/2);
+        unsigned short *d=(unsigned short *) &a_buffer[a_buffer_len];
+        unsigned char *s=&a_buffer[a_buffer_len];
+        a_buffer_len+=2*l;
+        while(l>0){
+          --l;
+          d[l]=xa_alaw_2_sign[s[l]];
+        }
+        break;
+      }
+      case 6:  // MS-GSM decoder
+      { unsigned char buf[65]; // 65 bytes / frame
+	    while(a_buffer_len<OUTBURST){
+		  if(demux_read_data(d_audio,buf,65)!=65) break; // EOF
+		  XA_MSGSM_Decoder(buf,(unsigned short *) &a_buffer[a_buffer_len]); // decodes 65 byte -> 320 short
+//  		XA_GSM_Decoder(buf,(unsigned short *) &a_buffer[a_buffer_len]); // decodes 33 byte -> 160 short
+          a_buffer_len+=2*320;
+		}
+        break;
+      }
+      case 3: // AC3 decoder
+        //printf("{1:%d}",avi_header.idx_pos);fflush(stdout);
+        if(!ac3_frame) ac3_frame=ac3_decode_frame();
+        //printf("{2:%d}",avi_header.idx_pos);fflush(stdout);
+        if(ac3_frame){
+          memcpy(&a_buffer[a_buffer_len],ac3_frame->audio_data,256 * 6 *MP3_channels*MP3_bps);
+          a_buffer_len+=256 * 6 *MP3_channels*MP3_bps;
+          ac3_frame=NULL;
+        }
+        //printf("{3:%d}",avi_header.idx_pos);fflush(stdout);
+        break;
+      case 4:
+      { ACMSTREAMHEADER ash;
+        HRESULT hr;
+        DWORD srcsize=0;
+        acmStreamSize(avi_header.srcstream,a_buffer_size-a_buffer_len , &srcsize, ACM_STREAMSIZEF_DESTINATION);
+        if(verbose>=3)printf("acm says: srcsize=%d  (buffsize=%d)  out_size=%d\n",srcsize,a_in_buffer_size,a_buffer_size-a_buffer_len);
+//        if(srcsize==0) srcsize=((WAVEFORMATEX *)&avi_header.wf_ext)->nBlockAlign;
+        if(srcsize>a_in_buffer_size) srcsize=a_in_buffer_size; // !!!!!!
+        if(a_in_buffer_len<srcsize){
+          a_in_buffer_len+=
+            demux_read_data(d_audio,&a_in_buffer[a_in_buffer_len],
+            srcsize-a_in_buffer_len);
+        }
+        memset(&ash, 0, sizeof(ash));
+        ash.cbStruct=sizeof(ash);
+        ash.fdwStatus=0;
+        ash.dwUser=0; 
+        ash.pbSrc=a_in_buffer;
+        ash.cbSrcLength=a_in_buffer_len;
+        ash.pbDst=&a_buffer[a_buffer_len];
+        ash.cbDstLength=a_buffer_size-a_buffer_len;
+        hr=acmStreamPrepareHeader(avi_header.srcstream,&ash,0);
+        if(hr){
+          printf("ACM_Decoder: acmStreamPrepareHeader error %d\n",hr);break;
+        }
+        hr=acmStreamConvert(avi_header.srcstream,&ash,0);
+        if(hr){
+          printf("ACM_Decoder: acmStreamConvert error %d\n",hr);break;
+        }
+        //printf("ACM convert %d -> %d  (buf=%d)\n",ash.cbSrcLengthUsed,ash.cbDstLengthUsed,a_in_buffer_len);
+        if(ash.cbSrcLengthUsed>=a_in_buffer_len){
+          a_in_buffer_len=0;
+        } else {
+          a_in_buffer_len-=ash.cbSrcLengthUsed;
+          memcpy(a_in_buffer,&a_in_buffer[ash.cbSrcLengthUsed],a_in_buffer_len);
+        }
+        a_buffer_len+=ash.cbDstLengthUsed;
+        hr=acmStreamUnprepareHeader(avi_header.srcstream,&ash,0);
+        if(hr){
+          printf("ACM_Decoder: acmStreamUnprepareHeader error %d\n",hr);
+        }
+        break;
+      }
+    }
+  }
+  current_module=NULL;   // Leave AUDIO decoder module
+  t=GetTimer()-t;
+  audio_time_usage+=t*0.000001;
+
+  // Play sound from the buffer:
+
+  if(a_buffer_len>=OUTBURST){ // if not EOF
+#ifdef USE_XMMP_AUDIO
+    pSound->Write( pSound, a_buffer, OUTBURST );
+#else
+#ifdef SIMULATE_ALSA
+    fake_ALSA_write(audio_fd,a_buffer,OUTBURST); // for testing purposes
+#else
+    write(audio_fd,a_buffer,OUTBURST);
+#endif
+#endif
+    a_buffer_len-=OUTBURST;
+    memcpy(a_buffer,&a_buffer[OUTBURST],a_buffer_len);
+#ifndef USE_XMMP_AUDIO
+#ifndef SIMULATE_ALSA
+    // check buffer
+#ifdef HAVE_AUDIO_SELECT
+    {  fd_set rfds;
+       struct timeval tv;
+       FD_ZERO(&rfds);
+       FD_SET(audio_fd, &rfds);
+       tv.tv_sec = 0;
+       tv.tv_usec = 0;
+       if(select(audio_fd+1, NULL, &rfds, NULL, &tv)){
+         a_frame+=OUTBURST/(float)(MP3_samplerate*MP3_channels*MP3_bps);
+         a_pts+=OUTBURST/(float)(MP3_samplerate*MP3_channels*MP3_bps);
+//         printf("Filling audio buffer...\n");
+         continue;
+//       } else {
+//         printf("audio buffer full...\n");
+       }
+    }
+#endif
+#endif
+#endif
+  }
+
+  break;
+} // if(has_audio)
+
+/*========================== UPDATE TIMERS ============================*/
+
+  a_frame+=OUTBURST/(float)(MP3_samplerate*MP3_channels*MP3_bps);
+  a_pts+=OUTBURST/(float)(MP3_samplerate*MP3_channels*MP3_bps);
+
+  if(alsa){
+    // Use system timer for sync, not audio card/driver
+    time_frame+=OUTBURST/(float)(MP3_samplerate*MP3_channels*MP3_bps);
+    time_frame-=GetRelativeTime();
+//    printf("time_frame=%5.3f\n",time_frame);
+    if(time_frame<-0.1 || time_frame>0.1){
+      time_frame=0;
+    } else {
+//      if(time_frame>0.01) usleep(1000000*(time_frame-0.01)); // sleeping
+      if(time_frame>0.001) usleep(1000000*(time_frame)); // sleeping
+    }
+  }
+
+
+/*========================== PLAY VIDEO ============================*/
+
+if(1)
+  while(v_frame<a_frame || force_redraw){
+
+    current_module="decode_video";
+
+  //--------------------  Decode a frame: -----------------------
+switch(has_video){
+  case 3: {
+    // OpenDivX
+    unsigned int t=GetTimer();
+    unsigned int t2;
+    DEC_FRAME dec_frame;
+    char* start=NULL;
+    int in_size=ds_get_packet(d_video,&start);
+    if(in_size<0){ eof=1;break;}
+    if(in_size>max_framesize) max_framesize=in_size;
+    // let's decode
+        dec_frame.length = in_size;
+	dec_frame.bitstream = start;
+	//dec_frame.bmp = video_out;
+	dec_frame.render_flag = 1;
+	decore(0x123, 0, &dec_frame, NULL);
+      t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f;
+
+      if(opendivx_src[0]){
+        video_out->draw_slice(opendivx_src,opendivx_stride,
+                            movie_size_x,movie_size_y,0,0);
+        video_out->flip_page();
+        opendivx_src[0]=NULL;
+      }
+
+      t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f;
+
+      ++num_frames;
+      v_frame+=1.0f/default_fps; //(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
+    
+    break;
+  }
+  case 2: {
+    HRESULT ret;
+    char* start=NULL;
+    unsigned int t=GetTimer();
+    unsigned int t2;
+    float pts1=d_video->pts;
+    int in_size=ds_get_packet(d_video,&start);
+    float pts2=d_video->pts;
+    if(in_size<0){ eof=1;break;}
+    if(in_size>max_framesize) max_framesize=in_size;
+    
+//    printf("frame len = %5.4f\n",pts2-pts1);
+
+//if(in_size>0){
+      avi_header.bih.biSizeImage = in_size;
+      ret = ICDecompress(avi_header.hic, ICDECOMPRESS_NOTKEYFRAME, 
+//      ret = ICDecompress(avi_header.hic, ICDECOMPRESS_NOTKEYFRAME|(ICDECOMPRESS_HURRYUP|ICDECOMPRESS_PREROL), 
+                        &avi_header.bih,   start,
+                        &avi_header.o_bih, avi_header.our_out_buffer);
+      if(ret){ printf("Error decompressing frame, err=%d\n",ret);break; }
+//}
+
+      t2=GetTimer();t=t2-t;video_time_usage+=t*0.000001f;
+        video_out->draw_frame((uint8_t **)&avi_header.our_out_buffer);
+        video_out->flip_page();
+      t2=GetTimer()-t2;vout_time_usage+=t2*0.000001f;
+
+      ++num_frames;
+      
+      if(file_format==DEMUXER_TYPE_ASF){
+        float d=pts2-pts1;
+        if(d>0 && d<0.2) v_frame+=d;
+      } else
+        v_frame+=1.0f/default_fps; //(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
+      //v_pts+=1.0f/default_fps;   //(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
+
+    break;
+  }
+  case 1: {
+    while(1){
+      int x;
+      while(1){
+        x=-1; // paranoia
+        if(4==read(control_fifo,&x,4)) break;  // status/command
+        usleep(5000); // do not eat 100% CPU (waiting for codec restart)
+      }
+      if(x==0x3030303){
+        //*** CMD=3030303 : Video packet requested ***
+        // read a single compressed frame:
+        int in_frame=0;
+        videobuf_len=0;
+        while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE){
+          int i=sync_video_packet(d_video);
+          if(in_frame){
+            if(i<0x101 || i>=0x1B0){  // not slice code -> end of frame
+              // send END OF FRAME code:
+#if 1
+              videobuffer[videobuf_len+0]=0;
+              videobuffer[videobuf_len+1]=0;
+              videobuffer[videobuf_len+2]=1;
+              videobuffer[videobuf_len+3]=0xFF;
+              videobuf_len+=4;
+#endif
+              if(!i) eof=1; // EOF
+              break;
+            }
+          } else {
+            //if(i==0x100) in_frame=1; // picture startcode
+            if(i>=0x101 && i<0x1B0) in_frame=1; // picture startcode
+            else if(!i){ eof=1; break;} // EOF
+          }
+          if(!read_video_packet(d_video)){ eof=1; break;} // EOF
+          //printf("read packet 0x%X, len=%d\n",i,videobuf_len);
+        }
+        if(videobuf_len>max_framesize) max_framesize=videobuf_len; // debug
+        //printf("--- SEND %d bytes\n",videobuf_len);
+        ++dbg_es_sent;
+        //if(videobuf_len>4) 
+        my_write(data_fifo,(char*) &videobuf_len,4);
+        if(eof) break;
+      } else
+      if(x==0){
+        //*** CMD=0 : Frame completed ***
+        int l=100;
+        int t=0;
+        read(control_fifo,&x,4); // FPS
+        read(control_fifo,&l,4); // Length*100
+        read(control_fifo,&t,4); // Time*1000000
+        //printf("+++ FRAME COMPLETED fps=%d  len=%d  time=%d\n",x,l,t);
+        ++dbg_es_rcvd;
+        num_frames+=l/100.0f;
+        video_time_usage+=t*0.000001;
+        if(x && !force_fps) default_fps=x*0.0001f;
+        if(!force_redraw){
+          // increase video timers:
+          v_frame+=l*0.01f/default_fps;
+          v_pts+=l*0.01f/default_fps;
+        }
+        break; // frame OK.
+      } else
+      if(x==0x22222222){
+        //*** CMD=22222222 : codec reset/restart ***
+        read(control_fifo,&codec_pid,4); // PID
+        printf("\nVideo codec started... (pid %d)\n",codec_pid);
+        send_cmd(data_fifo,0x22222222);  // send response (syncword)
+        dbg_es_sent=dbg_es_rcvd=0;
+        //printf("  [ReSync-VIDEO]       \n");
+        while(1){
+          int id=sync_video_packet(d_video);
+          if(id==0x100 || id>=0x1B0) break; // header chunk
+          if(!id || !skip_video_packet(d_video)){ eof=1; break;} // EOF
+        }
+        if(eof) break;
+        max_pts_correction=0.2;
+      } else
+        printf("invalid cmd: 0x%X\n",x);
+    }
+    break;
+  }
+} // switch
+//------------------------ frame decoded. --------------------
+
+    current_module=NULL;
+
+    if(eof) break;
+    if(force_redraw) --force_redraw;
+
+//    printf("A:%6.1f  V:%6.1f  A-V:%7.3f  frame=%5.2f   \r",d_audio->pts,d_video->pts,d_audio->pts-d_video->pts,a_frame);
+//    fflush(stdout);
+
+#if 1
+/*================ A-V TIMESTAMP CORRECTION: =========================*/
+  if(has_audio){
+    if(pts_from_bps && (file_format==DEMUXER_TYPE_AVI || file_format==DEMUXER_TYPE_AVI_NI)){
+//      a_pts=(float)ds_tell(d_audio)/((WAVEFORMATEX*)avi_header.wf_ext)->nAvgBytesPerSec-(buffer_delay+audio_delay);
+      a_pts=(float)ds_tell(d_audio)/((WAVEFORMATEX*)avi_header.wf_ext)->nAvgBytesPerSec-(buffer_delay);
+      delay_corrected=1; // hack
+    } else
+    if(d_audio->pts){
+//      printf("\n=== APTS  a_pts=%5.3f  v_pts=%5.3f ===  \n",d_audio->pts,d_video->pts);
+#if 1
+      if(!delay_corrected){
+        float x=d_audio->pts-d_video->pts-(buffer_delay+audio_delay);
+        float y=-(buffer_delay+audio_delay);
+        printf("Initial PTS delay: %5.3f sec  (calculated: %5.3f)\n",x,y);
+        audio_delay+=x;
+        //a_pts-=x;
+        delay_corrected=1;
+        printf("v: audio_delay=%5.3f  buffer_delay=%5.3f  a.pts=%5.3f  v.pts=%5.3f\n",
+               audio_delay,buffer_delay,d_audio->pts,d_video->pts);
+      }
+#endif
+      a_pts=d_audio->pts-(buffer_delay+audio_delay);
+      d_audio->pts=0;
+    }
+    if(d_video->pts) v_pts=d_video->pts;
+    if(frame_corr_num==5){
+      float x=(frame_correction/5.0f);
+      if(!delay_corrected){
+#if 0
+        printf("Initial PTS delay: %5.3f sec\n",x);
+        delay_corrected=1;
+        audio_delay+=x;
+        a_pts-=x;
+#endif
+      } else
+      {
+        printf("A:%6.1f  V:%6.1f  A-V:%7.3f",a_pts,v_pts,x);
+        x*=0.5f;
+        if(x<-max_pts_correction) x=-max_pts_correction; else
+        if(x> max_pts_correction) x= max_pts_correction;
+        max_pts_correction=default_max_pts_correction;
+        a_frame+=x; c_total+=x;
+#if 0
+        printf("  ct:%7.3f  a=%d v=%d  \r",c_total,
+        d_audio->pos,d_video->pos);
+#else
+        printf("  ct:%7.3f  %3d  %2d%%  %2d%%  %3.1f%% %d \r",c_total,
+        (int)num_frames,
+        (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0,
+        (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0,
+        (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0,
+        dbg_es_sent-dbg_es_rcvd 
+        );
+#endif
+        fflush(stdout);
+//        printf("\n");
+      }
+      //force_fps+=1*force_fps*x;
+//      printf("  ct:%7.3f  fps:%5.2f nf:%2.1f/%d  t:%d.%03d\r",c_total,default_fps,num_frames,real_num_frames,codec_time_usage_sec,codec_time_usage/1000);fflush(stdout);
+      frame_corr_num=0; frame_correction=0;
+    }
+    if(frame_corr_num>=0) frame_correction+=a_pts-v_pts;
+  } else {
+    // No audio:
+    if(d_video->pts) v_pts=d_video->pts;
+    if(frame_corr_num==5){
+//      printf("A: ---   V:%6.1f   \r",v_pts);
+      printf("V:%6.1f  %3d  %2d%%  %2d%%  %3.1f%% %d \r",v_pts,
+        (int)num_frames,
+        (v_frame>0.5)?(int)(100.0*video_time_usage/(double)v_frame):0,
+        (v_frame>0.5)?(int)(100.0*vout_time_usage/(double)v_frame):0,
+        (v_frame>0.5)?(100.0*audio_time_usage/(double)v_frame):0,
+        dbg_es_sent-dbg_es_rcvd);
+
+      fflush(stdout);
+      frame_corr_num=0;
+    }
+  }
+  ++frame_corr_num;
+#endif
+
+  } //  while(v_frame<a_frame || force_redraw)
+
+
+//================= Keyboard events, SEEKing ====================
+
+{ int rel_seek_secs=0;
+  int c;
+  while(
+#ifdef HAVE_LIRC
+      (c=lirc_mp_getinput())>0 ||
+#endif
+      (c=getch2(0))>0 || (c=mplayer_get_key())>0) switch(c){
+    // seek 10 sec
+    case KEY_RIGHT:
+      rel_seek_secs+=10;break;
+    case KEY_LEFT:
+      rel_seek_secs-=10;break;
+    // seek 1 min
+    case KEY_UP:
+      rel_seek_secs+=60;break;
+    case KEY_DOWN:
+      rel_seek_secs-=60;break;
+    // delay correction:
+    case '+':
+      buffer_delay+=0.1;  // increase audio buffer size
+      a_frame-=0.1;
+      break;
+    case '-':
+      buffer_delay-=0.1;  // decrease audio buffer size
+      a_frame+=0.1;
+      break;
+    // quit
+    case KEY_ESC: // ESC
+    case KEY_ENTER: // ESC
+    case 'q': exit_player("Quit");
+    // restart codec
+    case 'k': kill(codec_pid,SIGKILL);break;
+//    case 'k': kill(child_pid,SIGKILL);break;
+    // pause
+    case 'p':
+    case ' ':
+      printf("\n------ PAUSED -------\r");fflush(stdout);
+      while(
+#ifdef HAVE_LIRC
+          lirc_mp_getinput()<=0 &&
+#endif
+          getch2(20)<=0 && mplayer_get_key()<=0){}
+      break;
+  }
+  if(rel_seek_secs)
+  if(file_format==DEMUXER_TYPE_AVI && avi_header.idx_size<=0){
+    printf("Can't seek in raw .AVI streams! (index required)  \n");
+  } else {
+    int skip_audio_bytes=0;
+    float skip_audio_secs=0;
+
+    // clear demux buffers:
+    if(has_audio) ds_free_packs(d_audio);
+    ds_free_packs(d_video);
+    
+//    printf("a_buffer_len=%d  \n",a_buffer_len);
+    a_buffer_len=0;
+
+switch(file_format){
+
+  case DEMUXER_TYPE_AVI_NI:
+  case DEMUXER_TYPE_AVI: {
+  //================= seek in AVI ==========================
+    int rel_seek_frames=rel_seek_secs*default_fps;
+    int curr_audio_pos=0;
+    int audio_chunk_pos=-1;
+    int video_chunk_pos=d_video->pos;
+    
+    skip_video_frames=0;
+
+      // SEEK streams
+//      if(d_video->pts) avi_video_pts=d_video->pts;
+      avi_audio_pts=0;
+      d_video->pts=0;
+      d_audio->pts=0;
+
+      // find video chunk pos:
+      if(rel_seek_frames>0){
+        // seek forward
+        while(video_chunk_pos<avi_header.idx_size){
+          int id=avi_header.idx[video_chunk_pos].ckid;
+//          if(LOWORD(id)==aviTWOCC('0','0')){ // video frame
+          if(avi_stream_id(id)==d_video->id){  // video frame
+            if((--rel_seek_frames)<0 && avi_header.idx[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
+            v_pts+=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
+            ++skip_audio_bytes;
+          }
+          ++video_chunk_pos;
+        }
+      } else {
+        // seek backward
+        while(video_chunk_pos>=0){
+          int id=avi_header.idx[video_chunk_pos].ckid;
+//          if(LOWORD(id)==aviTWOCC('0','0')){ // video frame
+          if(avi_stream_id(id)==d_video->id){  // video frame
+            if((++rel_seek_frames)>0 && avi_header.idx[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
+            v_pts-=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
+            --skip_audio_bytes;
+          }
+          --video_chunk_pos;
+        }
+      }
+      avi_header.idx_pos_a=avi_header.idx_pos_v=
+      avi_header.idx_pos=video_chunk_pos;
+//      printf("%d frames skipped\n",skip_audio_bytes);
+
+#if 1
+      // re-calc video pts:
+      avi_video_pts=0;
+      for(i=0;i<video_chunk_pos;i++){
+          int id=avi_header.idx[i].ckid;
+//          if(LOWORD(id)==aviTWOCC('0','0')){ // video frame
+          if(avi_stream_id(id)==d_video->id){  // video frame
+            avi_video_pts+=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
+          }
+      }
+      //printf("v-pts recalc! %5.3f -> %5.3f  \n",v_pts,avi_video_pts);
+      v_pts=avi_video_pts;
+#else
+      avi_video_pts=v_pts;
+#endif
+      a_pts=avi_video_pts-(buffer_delay);
+      //a_pts=v_pts; //-(buffer_delay+audio_delay);
+
+      if(has_audio){
+        int i;
+        int apos=0;
+        int last=0;
+        int temp;
+        int len=0;
+
+        // calc new audio position in audio stream: (using avg.bps value)
+        curr_audio_pos=(avi_video_pts) * ((WAVEFORMATEX*)avi_header.wf_ext)->nAvgBytesPerSec;
+        if(curr_audio_pos<0)curr_audio_pos=0;
+#if 1
+        curr_audio_pos&=~15; // requires for PCM formats!!!
+#else
+        curr_audio_pos/=((WAVEFORMATEX*)avi_header.wf_ext)->nBlockAlign;
+        curr_audio_pos*=((WAVEFORMATEX*)avi_header.wf_ext)->nBlockAlign;
+        avi_header.audio_seekable=1;
+#endif
+
+        // find audio chunk pos:
+          for(i=0;i<video_chunk_pos;i++){
+            int id=avi_header.idx[i].ckid;
+            //if(TWOCCFromFOURCC(id)==cktypeWAVEbytes){
+            if(avi_stream_id(id)==d_audio->id){
+              int aid=StreamFromFOURCC(id);
+              if(d_audio->id==aid || d_audio->id==-1){
+                len=avi_header.idx[i].dwChunkLength;
+                last=i;
+                if(apos<=curr_audio_pos && curr_audio_pos<(apos+len)){
+                  if(verbose)printf("break;\n");
+                  break;
+                }
+                apos+=len;
+              }
+            }
+          }
+          if(verbose)printf("XXX i=%d  last=%d  apos=%d  curr_audio_pos=%d  \n",
+           i,last,apos,curr_audio_pos);
+//          audio_chunk_pos=last; // maybe wrong (if not break; )
+          audio_chunk_pos=i; // maybe wrong (if not break; )
+          skip_audio_bytes=curr_audio_pos-apos;
+
+          // update stream position:
+          d_audio->pos=audio_chunk_pos;
+          d_audio->dpos=apos;
+          avi_header.idx_pos_a=avi_header.idx_pos_v=
+          avi_header.idx_pos=audio_chunk_pos;
+
+          if(!avi_header.audio_seekable){
+#if 0
+//             curr_audio_pos=apos; // selected audio codec can't seek in chunk
+             skip_audio_secs=(float)skip_audio_bytes/(float)((WAVEFORMATEX*)avi_header.wf_ext)->nAvgBytesPerSec;
+             //printf("Seek_AUDIO: %d bytes --> %5.3f secs\n",skip_audio_bytes,skip_audio_secs);
+             skip_audio_bytes=0;
+#else
+             int d=skip_audio_bytes % ((WAVEFORMATEX*)avi_header.wf_ext)->nBlockAlign;
+             skip_audio_bytes-=d;
+//             curr_audio_pos-=d;
+             skip_audio_secs=(float)d/(float)((WAVEFORMATEX*)avi_header.wf_ext)->nAvgBytesPerSec;
+             //printf("Seek_AUDIO: %d bytes --> %5.3f secs\n",d,skip_audio_secs);
+#endif
+          }
+          // now: audio_chunk_pos=pos in index
+          //      skip_audio_bytes=bytes to skip from that chunk
+          //      skip_audio_secs=time to play audio before video (if can't skip)
+          
+          // calc skip_video_frames & adjust video pts counter:
+//          i=last;
+          i=avi_header.idx_pos;
+          while(i<video_chunk_pos){
+            int id=avi_header.idx[i].ckid;
+//            if(LOWORD(id)==aviTWOCC('0','0')){ // video frame
+            if(avi_stream_id(id)==d_video->id){  // video frame
+              ++skip_video_frames;
+              // requires for correct audio pts calculation (demuxer):
+              avi_video_pts-=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
+            }
+            ++i;
+          }
+          
+      }
+
+      if(verbose) printf("SEEK: idx=%d  (a:%d v:%d)  v.skip=%d  a.skip=%d/%4.3f  \n",
+        avi_header.idx_pos,audio_chunk_pos,video_chunk_pos,
+        skip_video_frames,skip_audio_bytes,skip_audio_secs);
+
+  }
+  break;
+
+  case DEMUXER_TYPE_ASF: {
+  //================= seek in ASF ==========================
+    float p_rate=10; // packets / sec
+    int rel_seek_packs=rel_seek_secs*p_rate;
+    int rel_seek_bytes=rel_seek_packs*fileh.packetsize;
+    int newpos;
+    //printf("ASF: packs: %d  duration: %d  \n",(int)fileh.packets,*((int*)&fileh.duration));
+//    printf("ASF_seek: %d secs -> %d packs -> %d bytes  \n",
+//       rel_seek_secs,rel_seek_packs,rel_seek_bytes);
+    newpos=demuxer->filepos+rel_seek_bytes;
+    if(newpos<0) newpos=0;
+    stream_seek(demuxer->stream,newpos);
+  }
+  break;
+  
+  case DEMUXER_TYPE_MPEG_ES:
+  case DEMUXER_TYPE_MPEG_PS: {
+  //================= seek in MPEG ==========================
+        int newpos;
+        if(picture->bitrate==0x3FFFF) // unspecified?
+          newpos=demuxer->filepos+2324*75*rel_seek_secs; // 174.3 kbyte/sec
+        else
+          newpos=demuxer->filepos+(picture->bitrate*1000/16)*rel_seek_secs;
+//       picture->bitrate=2324*75*8; // standard VCD bitrate (75 sectors / sec)
+
+        if(newpos<seek_to_byte) newpos=seek_to_byte;
+        stream_seek(demuxer->stream,newpos);
+        // re-sync video:
+        videobuf_code_len=0; // reset ES stream buffer
+        while(1){
+          int i=sync_video_packet(d_video);
+          if(i==0x1B3 || i==0x1B8) break; // found it!
+          if(!i || !skip_video_packet(d_video)){ eof=1; break;} // EOF
+        }
+        // re-sync audio:  (must read to get actual audio PTS)
+        // if(has_audio) ds_fill_buffer(d_audio);
+  }
+  break;
+
+} // switch(file_format)
+
+      //====================== re-sync audio: =====================
+      if(has_audio){
+
+        if(skip_audio_bytes){
+          demux_read_data(d_audio,NULL,skip_audio_bytes);
+          d_audio->pts=0; // PTS is outdated because of the raw data skipping
+        }
+        
+        current_module="resync_audio";
+
+        switch(has_audio){
+        case 1:
+          MP3_DecodeFrame(NULL,-2); // resync
+          MP3_DecodeFrame(NULL,-2); // resync
+          MP3_DecodeFrame(NULL,-2); // resync
+          break;
+        case 3:
+          ac3_bitstream_reset();    // reset AC3 bitstream buffer
+    //      if(verbose){ printf("Resyncing AC3 audio...");fflush(stdout);}
+          ac3_frame=ac3_decode_frame(); // resync
+    //      if(verbose) printf(" OK!\n");
+          break;
+        case 4:
+          a_in_buffer_len=0;        // reset ACM audio buffer
+          break;
+        }
+
+        // re-sync PTS (MPEG-PS only!!!)
+        if(file_format==DEMUXER_TYPE_MPEG_PS)
+        if(d_video->pts && d_audio->pts){
+          if (d_video->pts < d_audio->pts){
+          
+          } else {
+            while(d_video->pts > d_audio->pts){
+              switch(has_audio){
+                case 1: MP3_DecodeFrame(NULL,-2);break; // skip MPEG frame
+                case 3: ac3_frame=ac3_decode_frame();break; // skip AC3 frame
+                default: ds_fill_buffer(d_audio);  // skip PCM frame
+              }
+            }
+          }
+        }
+
+        current_module=NULL;
+
+        c_total=0; // kell ez?
+        printf("A:%6.1f  V:%6.1f  A-V:%7.3f",d_audio->pts,d_video->pts,0.0f);
+        printf("  ct:%7.3f   \r",c_total);fflush(stdout);
+      } else {
+        printf("A: ---   V:%6.1f   \r",d_video->pts);fflush(stdout);
+      }
+
+      max_pts_correction=0.1;
+      frame_corr_num=-5; frame_correction=0;
+      force_redraw=5;
+      a_frame=-buffer_delay-skip_audio_secs;
+//      a_frame=-audio_delay-buffer_delay-skip_audio_secs;
+      v_frame=0; // !!!!!!
+      audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
+//      num_frames=real_num_frames=0;
+  }
+} // keyboard event handler
+
+
+
+} // while(!eof)
+
+//printf("\nEnd of file.\n");
+exit_player("End of file");
+}}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/parse_es.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,106 @@
+//=================== VIDEO PARSER =========================
+
+#define MAX_VIDEO_PACKET_SIZE (224*1024+4)
+#define VIDEOBUFFER_SIZE 0x100000
+
+//static unsigned char videobuffer[MAX_VIDEO_PACKET_SIZE];
+static unsigned char* videobuffer=NULL;
+static int videobuf_len=0;
+
+static unsigned char videobuf_code[4];
+static int videobuf_code_len=0;
+
+// sync video stream, and returns next packet code
+int sync_video_packet(demux_stream_t *ds){
+  int skipped=0;
+  // we need enough bytes in the buffer:
+  while(videobuf_code_len<4){
+#if 0
+    int c;
+    c=demux_getc(ds);if(c<0){ return 0;} // EOF
+    videobuf_code[videobuf_code_len++]=c;
+#else
+    videobuf_code[videobuf_code_len++]=demux_getc(ds);
+#endif
+  }
+  // sync packet:
+  while(1){
+    int c;
+    if(videobuf_code[0]==0 &&
+       videobuf_code[1]==0 &&
+       videobuf_code[2]==1) break; // synced
+    // shift buffer, drop first byte
+    ++skipped;
+    videobuf_code[0]=videobuf_code[1];
+    videobuf_code[1]=videobuf_code[2];
+    videobuf_code[2]=videobuf_code[3];
+    c=demux_getc(ds);if(c<0){ return 0;} // EOF
+    videobuf_code[3]=c;
+  }
+  if(verbose>=2) if(skipped) printf("videobuf: %d bytes skipped\n",skipped);
+  return 0x100|videobuf_code[3];
+}
+
+// return: packet length
+int read_video_packet(demux_stream_t *ds){
+int packet_start;
+  
+  // SYNC STREAM
+//  if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
+
+  // COPY STARTCODE:
+  packet_start=videobuf_len;
+  videobuffer[videobuf_len+0]=videobuf_code[0];
+  videobuffer[videobuf_len+1]=videobuf_code[1];
+  videobuffer[videobuf_len+2]=videobuf_code[2];
+  videobuffer[videobuf_len+3]=videobuf_code[3];
+  videobuf_len+=4;
+  
+  // READ PACKET:
+  { unsigned int head=-1;
+    while(videobuf_len<VIDEOBUFFER_SIZE){
+      int c=demux_getc(ds);
+      if(c<0) break; // EOF
+      videobuffer[videobuf_len++]=c;
+#if 1
+      head<<=8;
+      if(head==0x100) break; // synced
+      head|=c;
+#else
+      if(videobuffer[videobuf_len-4]==0 &&
+         videobuffer[videobuf_len-3]==0 &&
+         videobuffer[videobuf_len-2]==1) break; // synced
+#endif
+    }
+  }
+  
+  if(ds->eof){
+    videobuf_code_len=0; // EOF, no next code
+    return videobuf_len-packet_start;
+  }
+  
+  videobuf_len-=4;
+
+  if(verbose>=2) printf("videobuf: packet 0x1%02X  len=%d\n",videobuffer[3],videobuf_len);
+
+  // Save next packet code:
+  videobuf_code[0]=videobuffer[videobuf_len];
+  videobuf_code[1]=videobuffer[videobuf_len+1];
+  videobuf_code[2]=videobuffer[videobuf_len+2];
+  videobuf_code[3]=videobuffer[videobuf_len+3];
+  videobuf_code_len=4;
+
+  return videobuf_len-packet_start;
+}
+
+// return: next packet code
+int skip_video_packet(demux_stream_t *ds){
+
+  // SYNC STREAM
+//  if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
+  
+  videobuf_code_len=0; // force resync
+  
+  // SYNC AGAIN:
+  return sync_video_packet(ds);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stream.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,203 @@
+
+#include "vcd_read.c"
+
+//=================== STREAMER =========================
+
+#define STREAM_BUFFER_SIZE 4096
+
+#define STREAMTYPE_FILE 0
+#define STREAMTYPE_VCD  1
+
+typedef struct {
+  int fd;
+  long pos;
+  int eof;
+  int type; // 0=file 1=VCD
+  unsigned int buf_pos,buf_len;
+  unsigned char buffer[STREAM_BUFFER_SIZE];
+} stream_t;
+
+int stream_fill_buffer(stream_t *s){
+  int len;
+  if(s->eof){ s->buf_pos=s->buf_len=0; return 0; }
+  switch(s->type){
+  case STREAMTYPE_FILE:
+    len=read(s->fd,s->buffer,STREAM_BUFFER_SIZE);break;
+  case STREAMTYPE_VCD:
+#ifdef VCD_CACHE
+    len=vcd_cache_read(s->fd,s->buffer);break;
+#else
+    len=vcd_read(s->fd,s->buffer);break;
+#endif
+  default: len=0;
+  }
+  if(len<=0){ s->eof=1; s->buf_pos=s->buf_len=0; return 0; }
+  s->buf_pos=0;
+  s->buf_len=len;
+  s->pos+=len;
+//  printf("[%d]",len);fflush(stdout);
+  return len;
+}
+
+inline unsigned int stream_read_char(stream_t *s){
+  return (s->buf_pos<s->buf_len)?s->buffer[s->buf_pos++]:
+    (stream_fill_buffer(s)?s->buffer[s->buf_pos++]:0);
+//  if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++];
+//  stream_fill_buffer(s);
+//  if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++];
+//  return 0; // EOF
+}
+
+inline unsigned int stream_read_word(stream_t *s){
+  int x,y;
+  x=stream_read_char(s);
+  y=stream_read_char(s);
+  return (x<<8)|y;
+}
+
+inline unsigned int stream_read_dword(stream_t *s){
+  unsigned int y;
+  y=stream_read_char(s);
+  y=(y<<8)|stream_read_char(s);
+  y=(y<<8)|stream_read_char(s);
+  y=(y<<8)|stream_read_char(s);
+  return y;
+}
+
+inline unsigned int stream_read_word_le(stream_t *s){
+  int x,y;
+  x=stream_read_char(s);
+  y=stream_read_char(s);
+  return (y<<8)|x;
+}
+
+inline unsigned int stream_read_dword_le(stream_t *s){
+  unsigned int y;
+  y=stream_read_char(s);
+  y|=stream_read_char(s)<<8;
+  y|=stream_read_char(s)<<16;
+  y|=stream_read_char(s)<<24;
+  return y;
+}
+
+inline void stream_read(stream_t *s,char* mem,int len){
+  while(len>0){
+    int x;
+    x=s->buf_len-s->buf_pos;
+    if(x==0){
+      if(!stream_fill_buffer(s)) return; // EOF
+      x=s->buf_len-s->buf_pos;
+    }
+    if(s->buf_pos>s->buf_len) printf("stream_read: WARNING! s->buf_pos>s->buf_len\n");
+    if(x>len) x=len;
+    memcpy(mem,&s->buffer[s->buf_pos],x);
+    s->buf_pos+=x; mem+=x; len-=x;
+  }
+}
+
+inline int stream_eof(stream_t *s){
+  return s->eof;
+}
+
+inline int stream_tell(stream_t *s){
+  return s->pos+s->buf_pos-s->buf_len;
+}
+
+inline int stream_seek(stream_t *s,unsigned int pos){
+unsigned int newpos;
+
+  if(verbose>=3) printf("seek to 0x%X\n",pos);
+
+  if(pos<s->pos){
+    int x=pos-(s->pos-s->buf_len);
+    if(x>=0){
+      s->buf_pos=x;
+//      putchar('*');fflush(stdout);
+      return 1;
+    }
+  }
+
+if(verbose>=3){
+  printf("s->pos=%X  newpos=%X  new_bufpos=%X  buflen=%X  \n",
+    s->pos,newpos,pos,s->buf_len);
+}
+
+  s->buf_pos=s->buf_len=0;
+
+  switch(s->type){
+  case STREAMTYPE_FILE:
+    newpos=pos&(~4095);break;
+  case STREAMTYPE_VCD:
+    newpos=(pos/VCD_SECTOR_DATA)*VCD_SECTOR_DATA;break;
+  }
+
+  pos-=newpos;
+
+if(newpos==0 || newpos!=s->pos){
+  s->pos=newpos; // real seek
+  switch(s->type){
+  case STREAMTYPE_FILE:
+    if(lseek(s->fd,s->pos,SEEK_SET)<0) s->eof=1;
+    break;
+  case STREAMTYPE_VCD:
+#ifdef VCD_CACHE
+    vcd_cache_seek(s->pos/VCD_SECTOR_DATA);
+#else
+    vcd_set_msf(s->pos/VCD_SECTOR_DATA);
+#endif
+    break;
+  }
+//   putchar('.');fflush(stdout);
+//} else {
+//   putchar('%');fflush(stdout);
+}
+
+  stream_fill_buffer(s);
+  if(pos>=0 && pos<s->buf_len){
+    s->buf_pos=pos; // byte position in sector
+    return 1;
+  }
+  printf("stream_seek: WARNING! Can't seek to 0x%X !\n",pos+newpos);
+  return 0;
+}
+
+inline void stream_skip(stream_t *s,int len){
+  if(len<0 || len>2*STREAM_BUFFER_SIZE){
+    // negative or big skip!
+    stream_seek(s,stream_tell(s)+len);
+    return;
+  }
+  while(len>0){
+    int x=s->buf_len-s->buf_pos;
+    if(x==0){
+      if(!stream_fill_buffer(s)) return; // EOF
+      x=s->buf_len-s->buf_pos;
+    }
+    if(x>len) x=len;
+    //memcpy(mem,&s->buf[s->buf_pos],x);
+    s->buf_pos+=x; len-=x;
+  }
+}
+
+void stream_reset(stream_t *s){
+  if(s->eof){
+    s->pos=0; //ftell(f);
+//    s->buf_pos=s->buf_len=0;
+    s->eof=0;
+  }
+  //stream_seek(s,0);
+}
+
+stream_t* new_stream(int fd,int type){
+  stream_t *s=malloc(sizeof(stream_t));
+  s->fd=fd;
+  s->type=type;
+  stream_reset(s);
+  return s;
+}
+
+void free_stream(stream_t *s){
+  free(s);
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tvision.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,152 @@
+// testing only, not finished!!!!!!!
+
+// little TeleVision program by A'rpi/ESP-team
+// based on streamer-old.c video capture util (part of xawtv) by
+//     (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <math.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <ctype.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/shm.h>
+#include <sys/ipc.h>
+#include <sys/wait.h>
+
+
+#include <asm/types.h>		/* XXX glibc */
+#include "videodev.h"
+
+#include "libvo/video_out.h"
+
+#define DEVNAME "/dev/video"
+
+static struct video_mmap        gb1,gb2;
+static struct video_capability  capability;
+static struct video_channel     channel;
+static struct video_mbuf        gb_buffers = { 2*0x151000, 0, {0,0x151000 }};
+static unsigned char            *map = NULL;
+
+
+int main(int argc,char* argv[]){
+vo_functions_t *video_out=NULL;
+char* video_driver=NULL; //"mga"; // default
+int i;
+int fd=-1;
+char* frame=NULL;
+int count=0;
+
+  if(argc>1) video_driver=argv[1];
+
+// check video_out driver name:
+  if(!video_driver)
+    video_out=video_out_drivers[0];
+  else
+  for (i=0; video_out_drivers[i] != NULL; i++){
+    const vo_info_t *info = video_out_drivers[i]->get_info ();
+    if(strcmp(info->short_name,video_driver) == 0){
+      video_out = video_out_drivers[i];break;
+    }
+  }
+  if(!video_out){
+    printf("Invalid video output driver name: %s\n",video_driver);
+    return 0;
+  }
+
+
+    /* open */
+    if (-1 == fd && -1 == (fd = open(DEVNAME,O_RDWR))) {
+	fprintf(stderr,"open %s: %s\n",DEVNAME,strerror(errno));
+	exit(1);
+    }
+
+    /* get settings */
+    if (-1 == ioctl(fd,VIDIOCGCAP,&capability)) {
+	perror("ioctl VIDIOCGCAP");
+	exit(1);
+    }
+    if (-1 == ioctl(fd,VIDIOCGCHAN,&channel))
+	perror("ioctl VIDIOCGCHAN");
+
+    /* mmap() buffer */
+    if (-1 == ioctl(fd,VIDIOCGMBUF,&gb_buffers)) {
+	perror("ioctl VIDIOCGMBUF");
+    }
+    map = mmap(0,gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
+    if ((unsigned char*)-1 == map) {
+	perror("mmap");
+    } else {
+	    fprintf(stderr,"v4l: mmap()'ed buffer size = 0x%x\n",
+		    gb_buffers.size);
+    }
+
+    /* prepare for grabbing */
+    gb1.format = VIDEO_PALETTE_YUV422;
+//    gb1.format = VIDEO_PALETTE_RGB24;
+    gb1.frame  = 0;
+    gb1.width  = 352;//720;//640;//320;
+    gb1.height = 288;//576;//480;//240;
+
+    gb2.format = gb1.format;
+    gb2.frame  = 1;
+    gb2.width  = gb1.width;
+    gb2.height = gb1.height;
+
+    video_out->init(gb1.width,gb1.height,1024,768,0,0,IMGFMT_YUY2);
+//    video_out->init(gb1.width,gb1.height,1024,768,0,0,IMGFMT_RGB|24);
+
+    if (-1 == ioctl(fd,VIDIOCMCAPTURE,&gb1)) {
+	if (errno == EAGAIN)
+	    fprintf(stderr,"grabber chip can't sync (no station tuned in?)\n");
+	else
+	    perror("ioctl VIDIOCMCAPTURE");
+	exit(1);
+    }
+    count++;
+    while(1){
+    // MAIN LOOP
+	if (-1 == ioctl(fd,VIDIOCMCAPTURE,(count%2) ? &gb2 : &gb1)) {
+	    if (errno == EAGAIN)
+		fprintf(stderr,"grabber chip can't sync (no station tuned in?)\n");
+	    else
+		perror("ioctl VIDIOCMCAPTURE");
+	    exit(1);
+	}
+
+	if (-1 == ioctl(fd,VIDIOCSYNC,(count%2) ? &gb1.frame : &gb2.frame)) {
+	    perror("ioctl VIDIOCSYNC");
+	    exit(1);
+	}
+        frame=map + gb_buffers.offsets[(count%2) ? 0 : 1];
+        video_out->draw_frame((unsigned char**)&frame);
+        video_out->flip_page();
+        
+        count++;
+    }
+    
+#if 0
+    { FILE *f=fopen("frame.yuv","wb");
+      fwrite(map,320*240*2,1,f);
+      fclose(f);
+    }
+    video_out->init(320,240,800,600,0,0,IMGFMT_YUY2);
+    video_out->draw_frame(count?map1:map2);
+    video_out->flip_page();
+    
+    getchar();
+#endif
+
+
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vcd_read.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,122 @@
+//=================== VideoCD ==========================
+static struct cdrom_tocentry vcd_entry;
+
+void vcd_set_msf(unsigned int sect){
+  vcd_entry.cdte_addr.msf.frame=sect%75;
+  sect=sect/75;
+  vcd_entry.cdte_addr.msf.second=sect%60;
+  sect=sect/60;
+  vcd_entry.cdte_addr.msf.minute=sect;
+}
+
+unsigned int vcd_get_msf(){
+  return vcd_entry.cdte_addr.msf.frame +
+        (vcd_entry.cdte_addr.msf.second+
+         vcd_entry.cdte_addr.msf.minute*60)*75;
+}
+
+int vcd_seek_to_track(int fd,int track){
+  vcd_entry.cdte_format = CDROM_MSF;
+  vcd_entry.cdte_track  = track;
+  if (ioctl(fd, CDROMREADTOCENTRY, &vcd_entry)) {
+    perror("ioctl dif1");
+    return 0;
+  }
+  return 1;
+}
+
+void vcd_read_toc(int fd){
+  struct cdrom_tochdr tochdr;
+  int i;
+  if (ioctl(fd,CDROMREADTOCHDR,&tochdr)==-1)
+    { perror("read CDROM toc header: "); return; }
+  for (i=tochdr.cdth_trk0 ; i<=tochdr.cdth_trk1 ; i++){
+      struct cdrom_tocentry tocentry;
+
+      tocentry.cdte_track  = i;
+      tocentry.cdte_format = CDROM_MSF;
+
+      if (ioctl(fd,CDROMREADTOCENTRY,&tocentry)==-1)
+	{ perror("read CDROM toc entry: "); return; }
+        
+      printf("track %02d:  adr=%d  ctrl=%d  format=%d  %02d:%02d:%02d  mode: %d\n",
+          (int)tocentry.cdte_track,
+          (int)tocentry.cdte_adr,
+          (int)tocentry.cdte_ctrl,
+          (int)tocentry.cdte_format,
+          (int)tocentry.cdte_addr.msf.minute,
+          (int)tocentry.cdte_addr.msf.second,
+          (int)tocentry.cdte_addr.msf.frame,
+          (int)tocentry.cdte_datamode
+      );
+    }
+}
+
+#define VCD_SECTOR_SIZE 2352
+#define VCD_SECTOR_OFFS 24
+#define VCD_SECTOR_DATA 2324
+static char vcd_buf[VCD_SECTOR_SIZE];
+
+int vcd_read(int fd,char *mem){
+      memcpy(vcd_buf,&vcd_entry.cdte_addr.msf,sizeof(struct cdrom_msf));
+      if(ioctl(fd,CDROMREADRAW,vcd_buf)==-1) return 0; // EOF?
+
+      vcd_entry.cdte_addr.msf.frame++;
+      if (vcd_entry.cdte_addr.msf.frame==75){
+        vcd_entry.cdte_addr.msf.frame=0;
+        vcd_entry.cdte_addr.msf.second++;
+        if (vcd_entry.cdte_addr.msf.second==60){
+          vcd_entry.cdte_addr.msf.second=0;
+          vcd_entry.cdte_addr.msf.minute++;
+        }
+      }
+
+      memcpy(mem,&vcd_buf[VCD_SECTOR_OFFS],VCD_SECTOR_DATA);
+      return VCD_SECTOR_DATA;
+}
+
+//================== VCD CACHE =======================
+#ifdef VCD_CACHE
+
+static int vcd_cache_size=0;
+static char *vcd_cache_data=NULL;
+static int *vcd_cache_sectors=NULL;
+static int vcd_cache_index=0; // index to first free (or oldest) cache sector
+static int vcd_cache_current=-1;
+
+void vcd_cache_init(int s){
+  vcd_cache_size=s;
+  vcd_cache_sectors=malloc(s*sizeof(int));
+  vcd_cache_data=malloc(s*VCD_SECTOR_SIZE);
+  memset(vcd_cache_sectors,255,s*sizeof(int));
+}
+
+void vcd_cache_seek(int sect){
+  vcd_cache_current=sect;
+}
+
+int vcd_cache_read(int fd,char* mem){
+int i;
+char* vcd_buf;
+  for(i=0;i<vcd_cache_size;i++)
+    if(vcd_cache_sectors[i]==vcd_cache_current){
+      // found in the cache! :)
+      vcd_buf=&vcd_cache_data[i*VCD_SECTOR_SIZE];
+      ++vcd_cache_current;
+      memcpy(mem,&vcd_buf[VCD_SECTOR_OFFS],VCD_SECTOR_DATA);
+      return VCD_SECTOR_DATA;
+    }
+  // NEW cache entry:
+  vcd_buf=&vcd_cache_data[vcd_cache_index*VCD_SECTOR_SIZE];
+  vcd_cache_sectors[vcd_cache_index]=vcd_cache_current;
+  ++vcd_cache_index;if(vcd_cache_index>=vcd_cache_size)vcd_cache_index=0;
+  // read data!
+  vcd_set_msf(vcd_cache_current);
+  memcpy(vcd_buf,&vcd_entry.cdte_addr.msf,sizeof(struct cdrom_msf));
+  if(ioctl(fd,CDROMREADRAW,vcd_buf)==-1) return 0; // EOF?
+  ++vcd_cache_current;
+  memcpy(mem,&vcd_buf[VCD_SECTOR_OFFS],VCD_SECTOR_DATA);
+  return VCD_SECTOR_DATA;
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/version.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,1 @@
+#define VERSION "0.11pre24"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/videodev.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,283 @@
+#ifndef __LINUX_VIDEODEV_H
+#define __LINUX_VIDEODEV_H
+
+#include <linux/types.h>
+
+#ifdef __KERNEL__
+
+#if LINUX_VERSION_CODE >= 0x020100
+#include <linux/poll.h>
+#endif
+
+struct video_device
+{
+	char name[32];
+	int type;
+	int hardware;
+
+	int (*open)(struct video_device *, int mode);
+	void (*close)(struct video_device *);
+	long (*read)(struct video_device *, char *, unsigned long, int noblock);
+	/* Do we need a write method ? */
+	long (*write)(struct video_device *, const char *, unsigned long, int noblock);
+#if LINUX_VERSION_CODE >= 0x020100
+	unsigned int (*poll)(struct video_device *, struct file *, poll_table *);
+#endif
+	int (*ioctl)(struct video_device *, unsigned int , void *);
+	int (*mmap)(struct video_device *, const char *, unsigned long);
+	int (*initialize)(struct video_device *);	
+	void *priv;		/* Used to be 'private' but that upsets C++ */
+	int busy;
+	int minor;
+};
+
+extern int videodev_init(void);
+#define VIDEO_MAJOR	81
+extern int video_register_device(struct video_device *, int type);
+
+#define VFL_TYPE_GRABBER	0
+#define VFL_TYPE_VBI		1
+#define VFL_TYPE_RADIO		2
+#define VFL_TYPE_VTX		3
+
+extern void video_unregister_device(struct video_device *);
+#endif
+
+
+#define VID_TYPE_CAPTURE	1	/* Can capture */
+#define VID_TYPE_TUNER		2	/* Can tune */
+#define VID_TYPE_TELETEXT	4	/* Does teletext */
+#define VID_TYPE_OVERLAY	8	/* Overlay onto frame buffer */
+#define VID_TYPE_CHROMAKEY	16	/* Overlay by chromakey */
+#define VID_TYPE_CLIPPING	32	/* Can clip */
+#define VID_TYPE_FRAMERAM	64	/* Uses the frame buffer memory */
+#define VID_TYPE_SCALES		128	/* Scalable */
+#define VID_TYPE_MONOCHROME	256	/* Monochrome only */
+#define VID_TYPE_SUBCAPTURE	512	/* Can capture subareas of the image */
+
+struct video_capability
+{
+	char name[32];
+	int type;
+	int channels;	/* Num channels */
+	int audios;	/* Num audio devices */
+	int maxwidth;	/* Supported width */
+	int maxheight;	/* And height */
+	int minwidth;	/* Supported width */
+	int minheight;	/* And height */
+};
+
+
+struct video_channel
+{
+	int channel;
+	char name[32];
+	int tuners;
+	__u32  flags;
+#define VIDEO_VC_TUNER		1	/* Channel has a tuner */
+#define VIDEO_VC_AUDIO		2	/* Channel has audio */
+	__u16  type;
+#define VIDEO_TYPE_TV		1
+#define VIDEO_TYPE_CAMERA	2	
+	__u16 norm;			/* Norm set by channel */
+};
+
+struct video_tuner
+{
+	int tuner;
+	char name[32];
+	ulong rangelow, rangehigh;	/* Tuner range */
+	__u32 flags;
+#define VIDEO_TUNER_PAL		1
+#define VIDEO_TUNER_NTSC	2
+#define VIDEO_TUNER_SECAM	4
+#define VIDEO_TUNER_LOW		8	/* Uses KHz not MHz */
+#define VIDEO_TUNER_NORM	16	/* Tuner can set norm */
+#define VIDEO_TUNER_STEREO_ON	128	/* Tuner is seeing stereo */
+	__u16 mode;			/* PAL/NTSC/SECAM/OTHER */
+#define VIDEO_MODE_PAL		0
+#define VIDEO_MODE_NTSC		1
+#define VIDEO_MODE_SECAM	2
+#define VIDEO_MODE_AUTO		3
+	__u16 signal;			/* Signal strength 16bit scale */
+};
+
+struct video_picture
+{
+	__u16	brightness;
+	__u16	hue;
+	__u16	colour;
+	__u16	contrast;
+	__u16	whiteness;	/* Black and white only */
+	__u16	depth;		/* Capture depth */
+	__u16   palette;	/* Palette in use */
+#define VIDEO_PALETTE_GREY	1	/* Linear greyscale */
+#define VIDEO_PALETTE_HI240	2	/* High 240 cube (BT848) */
+#define VIDEO_PALETTE_RGB565	3	/* 565 16 bit RGB */
+#define VIDEO_PALETTE_RGB24	4	/* 24bit RGB */
+#define VIDEO_PALETTE_RGB32	5	/* 32bit RGB */	
+#define VIDEO_PALETTE_RGB555	6	/* 555 15bit RGB */
+#define VIDEO_PALETTE_YUV422	7	/* YUV422 capture */
+#define VIDEO_PALETTE_YUYV	8
+#define VIDEO_PALETTE_UYVY	9	/* The great thing about standards is ... */
+#define VIDEO_PALETTE_YUV420	10
+#define VIDEO_PALETTE_YUV411	11	/* YUV411 capture */
+#define VIDEO_PALETTE_RAW	12	/* RAW capture (BT848) */
+#define VIDEO_PALETTE_YUV422P	13	/* YUV 4:2:2 Planar */
+#define VIDEO_PALETTE_YUV411P	14	/* YUV 4:1:1 Planar */
+#define VIDEO_PALETTE_YUV420P	15	/* YUV 4:2:0 Planar */
+#define VIDEO_PALETTE_YUV410P	16	/* YUV 4:1:0 Planar */
+#define VIDEO_PALETTE_PLANAR	13	/* start of planar entries */
+#define VIDEO_PALETTE_COMPONENT 7	/* start of component entries */
+};
+
+struct video_audio
+{
+	int	audio;		/* Audio channel */
+	__u16	volume;		/* If settable */
+	__u16	bass, treble;
+	__u32	flags;
+#define VIDEO_AUDIO_MUTE	1
+#define VIDEO_AUDIO_MUTABLE	2
+#define VIDEO_AUDIO_VOLUME	4
+#define VIDEO_AUDIO_BASS	8
+#define VIDEO_AUDIO_TREBLE	16	
+	char    name[16];
+#define VIDEO_SOUND_MONO	1
+#define VIDEO_SOUND_STEREO	2
+#define VIDEO_SOUND_LANG1	4
+#define VIDEO_SOUND_LANG2	8
+        __u16   mode;		/* detected audio carriers or one to set */
+        __u16	balance;	/* Stereo balance */
+        __u16	step;		/* Step actual volume uses */
+};
+
+struct video_clip
+{
+	__s32	x,y;
+	__s32	width, height;
+	struct	video_clip *next;	/* For user use/driver use only */
+};
+
+struct video_window
+{
+	__u32	x,y;			/* Position of window */
+	__u32	width,height;		/* Its size */
+	__u32	chromakey;
+	__u32	flags;
+	struct	video_clip *clips;	/* Set only */
+	int	clipcount;
+#define VIDEO_WINDOW_INTERLACE	1
+#define VIDEO_CLIP_BITMAP	-1
+/* bitmap is 1024x625, a '1' bit represents a clipped pixel */
+#define VIDEO_CLIPMAP_SIZE	(128 * 625)
+};
+
+struct video_capture
+{
+	__u32 	x,y;			/* Offsets into image */
+	__u32	width, height;		/* Area to capture */
+	__u16	decimation;		/* Decimation divder */
+	__u16	flags;			/* Flags for capture */
+#define VIDEO_CAPTURE_ODD		0	/* Temporal */
+#define VIDEO_CAPTURE_EVEN		1
+};
+
+struct video_buffer
+{
+	void	*base;
+	int	height,width;
+	int	depth;
+	int	bytesperline;
+};
+
+struct video_mmap
+{
+	unsigned	int frame;		/* Frame (0 - n) for double buffer */
+	int		height,width;
+	unsigned	int format;		/* should be VIDEO_PALETTE_* */
+};
+
+struct video_key
+{
+	__u8	key[8];
+	__u32	flags;
+};
+
+
+#define VIDEO_MAX_FRAME		32
+
+struct video_mbuf
+{
+	int	size;		/* Total memory to map */
+	int	frames;		/* Frames */
+	int	offsets[VIDEO_MAX_FRAME];
+};
+	
+
+#define 	VIDEO_NO_UNIT	(-1)
+
+	
+struct video_unit
+{
+	int 	video;		/* Video minor */
+	int	vbi;		/* VBI minor */
+	int	radio;		/* Radio minor */
+	int	audio;		/* Audio minor */
+	int	teletext;	/* Teletext minor */
+};
+
+#define VIDIOCGCAP		_IOR('v',1,struct video_capability)	/* Get capabilities */
+#define VIDIOCGCHAN		_IOWR('v',2,struct video_channel)	/* Get channel info (sources) */
+#define VIDIOCSCHAN		_IOW('v',3,struct video_channel)	/* Set channel 	*/
+#define VIDIOCGTUNER		_IOWR('v',4,struct video_tuner)		/* Get tuner abilities */
+#define VIDIOCSTUNER		_IOW('v',5,struct video_tuner)		/* Tune the tuner for the current channel */
+#define VIDIOCGPICT		_IOR('v',6,struct video_picture)	/* Get picture properties */
+#define VIDIOCSPICT		_IOW('v',7,struct video_picture)	/* Set picture properties */
+#define VIDIOCCAPTURE		_IOW('v',8,int)				/* Start, end capture */
+#define VIDIOCGWIN		_IOR('v',9, struct video_window)	/* Set the video overlay window */
+#define VIDIOCSWIN		_IOW('v',10, struct video_window)	/* Set the video overlay window - passes clip list for hardware smarts , chromakey etc */
+#define VIDIOCGFBUF		_IOR('v',11, struct video_buffer)	/* Get frame buffer */
+#define VIDIOCSFBUF		_IOW('v',12, struct video_buffer)	/* Set frame buffer - root only */
+#define VIDIOCKEY		_IOR('v',13, struct video_key)		/* Video key event - to dev 255 is to all - cuts capture on all DMA windows with this key (0xFFFFFFFF == all) */
+#define VIDIOCGFREQ		_IOR('v',14, unsigned long)		/* Set tuner */
+#define VIDIOCSFREQ		_IOW('v',15, unsigned long)		/* Set tuner */
+#define VIDIOCGAUDIO		_IOR('v',16, struct video_audio)	/* Get audio info */
+#define VIDIOCSAUDIO		_IOW('v',17, struct video_audio)	/* Audio source, mute etc */
+#define VIDIOCSYNC		_IOW('v',18, int)			/* Sync with mmap grabbing */
+#define VIDIOCMCAPTURE		_IOW('v',19, struct video_mmap)		/* Grab frames */
+#define VIDIOCGMBUF		_IOR('v', 20, struct video_mbuf)	/* Memory map buffer info */
+#define VIDIOCGUNIT		_IOR('v', 21, struct video_unit)	/* Get attached units */
+#define VIDIOCGCAPTURE		_IOR('v',22, struct video_capture)	/* Get frame buffer */
+#define VIDIOCSCAPTURE		_IOW('v',23, struct video_capture)	/* Set frame buffer - root only */
+
+#define BASE_VIDIOCPRIVATE	192		/* 192-255 are private */
+
+
+#define VID_HARDWARE_BT848	1
+#define VID_HARDWARE_QCAM_BW	2
+#define VID_HARDWARE_PMS	3
+#define VID_HARDWARE_QCAM_C	4
+#define VID_HARDWARE_PSEUDO	5
+#define VID_HARDWARE_SAA5249	6
+#define VID_HARDWARE_AZTECH	7
+#define VID_HARDWARE_SF16MI	8
+#define VID_HARDWARE_RTRACK	9
+#define VID_HARDWARE_ZOLTRIX	10
+#define VID_HARDWARE_SAA7146    11
+#define VID_HARDWARE_VIDEUM	12	/* Reserved for Winnov videum */
+#define VID_HARDWARE_RTRACK2	13
+#define VID_HARDWARE_PERMEDIA2	14	/* Reserved for Permedia2 */
+#define VID_HARDWARE_RIVA128	15	/* Reserved for RIVA 128 */
+
+/*
+ *	Initialiser list
+ */
+ 
+struct video_init
+{
+	char *name;
+	int (*init)(struct video_init *);
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xa/xa_gsm.c	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,988 @@
+
+/********************************************************************
+    Copyright 1992 by Jutta Degener and Carsten Bormann,
+    Technische Universitaet Berlin
+
+Any use of this software is permitted provided that this notice is not
+removed and that neither the authors nor the Technische Universitaet Berlin
+are deemed to have made any representations as to the suitability of this
+software for any purpose nor are held responsible for any defects of
+this software.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
+
+As a matter of courtesy, the authors request to be informed about uses
+this software has found, about bugs in this software, and about any
+improvements that may be of general interest.
+
+    Berlin, 15.09.1992
+    Jutta Degener
+    Carsten Bormann
+********************************************************************/
+
+
+#include <stdio.h>
+#include <assert.h>  /* POD optional */
+#include "xa_gsm_int.h"
+
+//void XA_MSGSM_Decoder();
+static void GSM_Decode();
+static void Gsm_RPE_Decoding();
+
+//static short gsm_buf[320];
+static XA_GSM_STATE gsm_state;
+
+unsigned char xa_sign_2_ulaw[256];
+
+unsigned char XA_Signed_To_uLaw(long ch)
+{
+  long mask;
+  if (ch < 0) { ch = -ch; mask = 0x7f; }
+  else { mask = 0xff; }
+  if (ch < 32)		{ ch = 0xF0 | (15 - (ch / 2)); }
+  else if (ch < 96)	{ ch = 0xE0 | (15 - (ch - 32) / 4); }
+  else if (ch < 224)	{ ch = 0xD0 | (15 - (ch - 96) / 8); }
+  else if (ch < 480)	{ ch = 0xC0 | (15 - (ch - 224) / 16); }
+  else if (ch < 992)	{ ch = 0xB0 | (15 - (ch - 480) / 32); }
+  else if (ch < 2016)	{ ch = 0xA0 | (15 - (ch - 992) / 64); }
+  else if (ch < 4064)	{ ch = 0x90 | (15 - (ch - 2016) / 128); }
+  else if (ch < 8160)	{ ch = 0x80 | (15 - (ch - 4064) /  256); }
+  else			{ ch = 0x80; }
+  return (mask & ch);
+}
+
+void Gen_Signed_2_uLaw()
+{
+  unsigned long i;
+  for(i=0;i<256;i++)
+  { unsigned char d;
+    char ch = i;
+    long chr = ch;
+    d = XA_Signed_To_uLaw(chr * 16);
+    xa_sign_2_ulaw[i] = d;
+  }
+}
+
+
+void GSM_Init()
+{
+  memset((char *)(&gsm_state), 0, sizeof(XA_GSM_STATE));
+  gsm_state.nrp = 40;
+  Gen_Signed_2_uLaw();
+}
+
+
+/*   Table 4.3b   Quantization levels of the LTP gain quantizer
+ */
+/* bc                 0          1        2          3                  */
+static word gsm_QLB[4] = {  3277,    11469,    21299,     32767        };
+
+/*   Table 4.6   Normalized direct mantissa used to compute xM/xmax
+ */
+/* i                  0      1       2      3      4      5      6      7   */
+static word gsm_FAC[8] = { 18431, 20479, 22527, 24575, 26623, 28671, 30719, 32767 };
+
+
+
+/****************/
+#define saturate(x)     \
+        ((x) < MIN_WORD ? MIN_WORD : (x) > MAX_WORD ? MAX_WORD: (x))
+
+/****************/
+static word gsm_sub (a,b)
+word a;
+word b;
+{
+        longword diff = (longword)a - (longword)b;
+        return saturate(diff);
+}
+
+/****************/
+static word gsm_asr (a,n)
+word a; 
+int n;
+{
+        if (n >= 16) return -(a < 0);
+        if (n <= -16) return 0;
+        if (n < 0) return a << -n;
+
+#       ifdef   SASR
+                return a >> n;
+#       else
+                if (a >= 0) return a >> n;
+                else return -(word)( -(uword)a >> n );
+#       endif
+}
+
+/****************/
+static word gsm_asl (a,n)
+word a; 
+int n;
+{
+        if (n >= 16) return 0;
+        if (n <= -16) return -(a < 0);
+        if (n < 0) return gsm_asr(a, -n);
+        return a << n;
+}
+
+
+/*
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
+ */
+
+/**** 4.2.17 */
+static void RPE_grid_positioning(Mc,xMp,ep)
+word            Mc;             /* grid position        IN      */
+register word   * xMp;          /* [0..12]              IN      */
+register word   * ep;           /* [0..39]              OUT     */
+/*
+ *  This procedure computes the reconstructed long term residual signal
+ *  ep[0..39] for the LTP analysis filter.  The inputs are the Mc
+ *  which is the grid position selection and the xMp[0..12] decoded
+ *  RPE samples which are upsampled by a factor of 3 by inserting zero
+ *  values.
+ */
+{
+        int     i = 13;
+
+        assert(0 <= Mc && Mc <= 3);
+
+        switch (Mc) {
+                case 3: *ep++ = 0;
+                case 2:  do {
+                                *ep++ = 0;
+                case 1:         *ep++ = 0;
+                case 0:         *ep++ = *xMp++;
+                         } while (--i);
+        }
+        while (++Mc < 4) *ep++ = 0;
+
+        /*
+
+        int i, k;
+        for (k = 0; k <= 39; k++) ep[k] = 0;
+        for (i = 0; i <= 12; i++) {
+                ep[ Mc + (3*i) ] = xMp[i];
+        }
+        */
+}
+
+
+/**** 4.2.16 */
+static void APCM_inverse_quantization (xMc,mant,exp,xMp)
+register word   * xMc;  /* [0..12]                      IN      */
+word            mant;
+word            exp;
+register word   * xMp;  /* [0..12]                      OUT     */
+/* 
+ *  This part is for decoding the RPE sequence of coded xMc[0..12]
+ *  samples to obtain the xMp[0..12] array.  Table 4.6 is used to get
+ *  the mantissa of xmaxc (FAC[0..7]).
+ */
+{
+        int     i;
+        word    temp, temp1, temp2, temp3;
+        longword        ltmp;
+
+        assert( mant >= 0 && mant <= 7 ); 
+
+        temp1 = gsm_FAC[ mant ];        /* see 4.2-15 for mant */
+        temp2 = gsm_sub( 6, exp );      /* see 4.2-15 for exp  */
+        temp3 = gsm_asl( 1, gsm_sub( temp2, 1 ));
+
+        for (i = 13; i--;) {
+
+                assert( *xMc <= 7 && *xMc >= 0 );       /* 3 bit unsigned */
+
+                /* temp = gsm_sub( *xMc++ << 1, 7 ); */
+                temp = (*xMc++ << 1) - 7;               /* restore sign   */
+                assert( temp <= 7 && temp >= -7 );      /* 4 bit signed   */
+
+                temp <<= 12;                            /* 16 bit signed  */
+                temp = GSM_MULT_R( temp1, temp );
+                temp = GSM_ADD( temp, temp3 );
+                *xMp++ = gsm_asr( temp, temp2 );
+        }
+}
+
+
+/**** 4.12.15 */
+static void APCM_quantization_xmaxc_to_exp_mant (xmaxc,exp_out,mant_out)
+word            xmaxc;          /* IN   */
+word            * exp_out;      /* OUT  */
+word            * mant_out;    /* OUT  */
+{
+  word    exp, mant;
+
+  /* Compute exponent and mantissa of the decoded version of xmaxc
+   */
+
+        exp = 0;
+        if (xmaxc > 15) exp = SASR(xmaxc, 3) - 1;
+        mant = xmaxc - (exp << 3);
+
+        if (mant == 0) {
+                exp  = -4;
+                mant = 7;
+        }
+        else {
+                while (mant <= 7) {
+                        mant = mant << 1 | 1;
+                        exp--;
+                }
+                mant -= 8;
+        }
+
+        assert( exp  >= -4 && exp <= 6 );
+        assert( mant >= 0 && mant <= 7 );
+
+        *exp_out  = exp;
+        *mant_out = mant;
+}
+
+static void Gsm_RPE_Decoding (S, xmaxcr, Mcr, xMcr, erp)
+XA_GSM_STATE        * S;
+word            xmaxcr;
+word            Mcr;
+word            * xMcr;  /* [0..12], 3 bits             IN      */
+word            * erp;   /* [0..39]                     OUT     */
+
+{
+        word    exp, mant;
+        word    xMp[ 13 ];
+
+        APCM_quantization_xmaxc_to_exp_mant( xmaxcr, &exp, &mant );
+        APCM_inverse_quantization( xMcr, mant, exp, xMp );
+        RPE_grid_positioning( Mcr, xMp, erp );
+
+}
+
+
+/*
+ *  4.3 FIXED POINT IMPLEMENTATION OF THE RPE-LTP DECODER
+ */
+
+static void Postprocessing(S,s)
+XA_GSM_STATE	* S;
+register word 	* s;
+{
+  register int		k;
+  register word		msr = S->msr;
+  register longword	ltmp;	/* for GSM_ADD */
+  register word		tmp;
+
+  for (k = 160; k--; s++) 
+  {
+    tmp = GSM_MULT_R( msr, 28180 );
+    msr = GSM_ADD(*s, tmp);  	   /* Deemphasis 	     */
+    *s  = GSM_ADD(msr, msr) & 0xFFF8;  /* Truncation & Upscaling */
+  }
+  S->msr = msr;
+}
+
+/**** 4.3.2 */
+void Gsm_Long_Term_Synthesis_Filtering (S,Ncr,bcr,erp,drp)
+XA_GSM_STATE        * S;
+word                    Ncr;
+word                    bcr;
+register word           * erp;     /* [0..39]                    IN */
+register word           * drp;     /* [-120..-1] IN, [-120..40] OUT */
+
+/*
+ *  This procedure uses the bcr and Ncr parameter to realize the
+ *  long term synthesis filtering.  The decoding of bcr needs
+ *  table 4.3b.
+ */
+{
+        register longword       ltmp;   /* for ADD */
+        register int            k;
+        word                    brp, drpp, Nr;
+
+        /*  Check the limits of Nr.
+         */
+        Nr = Ncr < 40 || Ncr > 120 ? S->nrp : Ncr;
+        S->nrp = Nr;
+        assert(Nr >= 40 && Nr <= 120);
+
+        /*  Decoding of the LTP gain bcr
+         */
+        brp = gsm_QLB[ bcr ];
+
+        /*  Computation of the reconstructed short term residual 
+         *  signal drp[0..39]
+         */
+        assert(brp != MIN_WORD);
+
+        for (k = 0; k <= 39; k++) {
+                drpp   = GSM_MULT_R( brp, drp[ k - Nr ] );
+                drp[k] = GSM_ADD( erp[k], drpp );
+        }
+
+        /*
+         *  Update of the reconstructed short term residual signal
+         *  drp[ -1..-120 ]
+         */
+
+        for (k = 0; k <= 119; k++) drp[ -120 + k ] = drp[ -80 + k ];
+}
+
+static void Short_term_synthesis_filtering (S,rrp,k,wt,sr)
+XA_GSM_STATE *S;
+register word   *rrp;  /* [0..7]       IN      */
+register int    k;      /* k_end - k_start      */
+register word   *wt;   /* [0..k-1]     IN      */
+register word   *sr;   /* [0..k-1]     OUT     */
+{
+        register word           * v = S->v;
+        register int            i;
+        register word           sri, tmp1, tmp2;
+        register longword       ltmp;   /* for GSM_ADD  & GSM_SUB */
+
+        while (k--) {
+                sri = *wt++;
+                for (i = 8; i--;) {
+
+                        /* sri = GSM_SUB( sri, gsm_mult_r( rrp[i], v[i] ) );
+                         */
+                        tmp1 = rrp[i];
+                        tmp2 = v[i];
+                        tmp2 =  ( tmp1 == MIN_WORD && tmp2 == MIN_WORD
+                                ? MAX_WORD
+                                : 0x0FFFF & (( (longword)tmp1 * (longword)tmp2
+                                             + 16384) >> 15)) ;
+
+                        sri  = GSM_SUB( sri, tmp2 );
+
+                        /* v[i+1] = GSM_ADD( v[i], gsm_mult_r( rrp[i], sri ) );
+                         */
+                        tmp1  = ( tmp1 == MIN_WORD && sri == MIN_WORD
+                                ? MAX_WORD
+                                : 0x0FFFF & (( (longword)tmp1 * (longword)sri
+                                             + 16384) >> 15)) ;
+
+                        v[i+1] = GSM_ADD( v[i], tmp1);
+                }
+                *sr++ = v[0] = sri;
+        }
+}
+
+/* 4.2.8 */
+
+static void Decoding_of_the_coded_Log_Area_Ratios (LARc,LARpp)
+word    * LARc;         /* coded log area ratio [0..7]  IN      */
+word    * LARpp;        /* out: decoded ..                      */
+{
+        register word   temp1 /* , temp2 */;
+        register long   ltmp;   /* for GSM_ADD */
+
+        /*  This procedure requires for efficient implementation
+         *  two tables.
+         *
+         *  INVA[1..8] = integer( (32768 * 8) / real_A[1..8])
+         *  MIC[1..8]  = minimum value of the LARc[1..8]
+         */
+
+        /*  Compute the LARpp[1..8]
+         */
+
+        /*      for (i = 1; i <= 8; i++, B++, MIC++, INVA++, LARc++, LARpp++) {
+         *
+         *              temp1  = GSM_ADD( *LARc, *MIC ) << 10;
+         *              temp2  = *B << 1;
+         *              temp1  = GSM_SUB( temp1, temp2 );
+         *
+         *              assert(*INVA != MIN_WORD);
+         *
+         *              temp1  = GSM_MULT_R( *INVA, temp1 );
+         *              *LARpp = GSM_ADD( temp1, temp1 );
+         *      }
+         */
+
+#undef  STEP
+#define STEP( B, MIC, INVA )    \
+                temp1    = GSM_ADD( *LARc++, MIC ) << 10;       \
+                temp1    = GSM_SUB( temp1, B << 1 );            \
+                temp1    = GSM_MULT_R( INVA, temp1 );           \
+                *LARpp++ = GSM_ADD( temp1, temp1 );
+
+        STEP(      0,  -32,  13107 );
+        STEP(      0,  -32,  13107 );
+        STEP(   2048,  -16,  13107 );
+        STEP(  -2560,  -16,  13107 );
+
+        STEP(     94,   -8,  19223 );
+        STEP(  -1792,   -8,  17476 );
+        STEP(   -341,   -4,  31454 );
+        STEP(  -1144,   -4,  29708 );
+
+        /* NOTE: the addition of *MIC is used to restore
+         *       the sign of *LARc.
+         */
+}
+
+/* 4.2.9 */
+/* Computation of the quantized reflection coefficients 
+ */
+
+/* 4.2.9.1  Interpolation of the LARpp[1..8] to get the LARp[1..8]
+ */
+
+/*
+ *  Within each frame of 160 analyzed speech samples the short term
+ *  analysis and synthesis filters operate with four different sets of
+ *  coefficients, derived from the previous set of decoded LARs(LARpp(j-1))
+ *  and the actual set of decoded LARs (LARpp(j))
+ *
+ * (Initial value: LARpp(j-1)[1..8] = 0.)
+ */
+
+static void Coefficients_0_12 (LARpp_j_1, LARpp_j, LARp)
+register word * LARpp_j_1;
+register word * LARpp_j;
+register word * LARp;
+{
+        register int    i;
+        register longword ltmp;
+
+        for (i = 1; i <= 8; i++, LARp++, LARpp_j_1++, LARpp_j++) {
+                *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 ));
+                *LARp = GSM_ADD( *LARp,  SASR( *LARpp_j_1, 1));
+        }
+}
+
+static void Coefficients_13_26 (LARpp_j_1, LARpp_j, LARp)
+register word * LARpp_j_1;
+register word * LARpp_j;
+register word * LARp;
+{
+        register int i;
+        register longword ltmp;
+        for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) {
+                *LARp = GSM_ADD( SASR( *LARpp_j_1, 1), SASR( *LARpp_j, 1 ));
+        }
+}
+
+static void Coefficients_27_39 (LARpp_j_1, LARpp_j, LARp)
+register word * LARpp_j_1;
+register word * LARpp_j;
+register word * LARp;
+{
+        register int i;
+        register longword ltmp;
+
+        for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) {
+                *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 ));
+                *LARp = GSM_ADD( *LARp, SASR( *LARpp_j, 1 ));
+        }
+}
+
+
+static void Coefficients_40_159 (LARpp_j, LARp)
+register word * LARpp_j;
+register word * LARp;
+{
+        register int i;
+
+        for (i = 1; i <= 8; i++, LARp++, LARpp_j++)
+                *LARp = *LARpp_j;
+}
+/* 4.2.9.2 */
+
+static void LARp_to_rp (LARp)
+register word * LARp;   /* [0..7] IN/OUT  */
+/*
+ *  The input of this procedure is the interpolated LARp[0..7] array.
+ *  The reflection coefficients, rp[i], are used in the analysis
+ *  filter and in the synthesis filter.
+ */
+{
+        register int            i;
+        register word           temp;
+        register longword       ltmp;
+
+        for (i = 1; i <= 8; i++, LARp++) {
+
+                /* temp = GSM_ABS( *LARp );
+                 *
+                 * if (temp < 11059) temp <<= 1;
+                 * else if (temp < 20070) temp += 11059;
+                 * else temp = GSM_ADD( temp >> 2, 26112 );
+                 *
+                 * *LARp = *LARp < 0 ? -temp : temp;
+                 */
+
+                if (*LARp < 0) {
+                        temp = *LARp == MIN_WORD ? MAX_WORD : -(*LARp);
+                        *LARp = - ((temp < 11059) ? temp << 1
+                                : ((temp < 20070) ? temp + 11059
+                                :  GSM_ADD( temp >> 2, 26112 )));
+                } else {
+                        temp  = *LARp;
+                        *LARp =    (temp < 11059) ? temp << 1
+                                : ((temp < 20070) ? temp + 11059
+                                :  GSM_ADD( temp >> 2, 26112 ));
+                }
+        }
+}
+
+
+
+
+
+/**** */
+static void Gsm_Short_Term_Synthesis_Filter (S, LARcr, wt, s)
+XA_GSM_STATE * S;
+word    * LARcr;        /* received log area ratios [0..7] IN  */
+word    * wt;           /* received d [0..159]             IN  */
+word    * s;            /* signal   s [0..159]            OUT  */
+{
+        word            * LARpp_j       = S->LARpp[ S->j     ];
+        word            * LARpp_j_1     = S->LARpp[ S->j ^=1 ];
+
+        word            LARp[8];
+
+#undef  FILTER
+#if     defined(FAST) && defined(USE_FLOAT_MUL)
+
+#       define  FILTER  (* (S->fast                     \
+                           ? Fast_Short_term_synthesis_filtering        \
+                           : Short_term_synthesis_filtering     ))
+#else
+#       define  FILTER  Short_term_synthesis_filtering
+#endif
+
+        Decoding_of_the_coded_Log_Area_Ratios( LARcr, LARpp_j );
+
+        Coefficients_0_12( LARpp_j_1, LARpp_j, LARp );
+        LARp_to_rp( LARp );
+        FILTER( S, LARp, 13, wt, s );
+
+        Coefficients_13_26( LARpp_j_1, LARpp_j, LARp);
+        LARp_to_rp( LARp );
+        FILTER( S, LARp, 14, wt + 13, s + 13 );
+
+        Coefficients_27_39( LARpp_j_1, LARpp_j, LARp);
+        LARp_to_rp( LARp );
+        FILTER( S, LARp, 13, wt + 27, s + 27 );
+
+        Coefficients_40_159( LARpp_j, LARp );
+        LARp_to_rp( LARp );
+        FILTER(S, LARp, 120, wt + 40, s + 40);
+}
+
+
+
+
+static void GSM_Decode(S,LARcr, Ncr,bcr,Mcr,xmaxcr,xMcr,s)
+XA_GSM_STATE	*S;
+word		*LARcr;		/* [0..7]		IN	*/
+word		*Ncr;		/* [0..3] 		IN 	*/
+word		*bcr;		/* [0..3]		IN	*/
+word		*Mcr;		/* [0..3] 		IN 	*/
+word		*xmaxcr;	/* [0..3]		IN 	*/
+word		*xMcr;		/* [0..13*4]		IN	*/
+word		*s;		/* [0..159]		OUT 	*/
+{
+  int		j, k;
+  word		erp[40], wt[160];
+  word		*drp = S->dp0 + 120;
+
+  for (j=0; j <= 3; j++, xmaxcr++, bcr++, Ncr++, Mcr++, xMcr += 13) 
+  {
+    Gsm_RPE_Decoding( S, *xmaxcr, *Mcr, xMcr, erp );
+    Gsm_Long_Term_Synthesis_Filtering( S, *Ncr, *bcr, erp, drp );
+    for (k = 0; k <= 39; k++) wt[ j * 40 + k ] =  drp[ k ];
+  }
+
+  Gsm_Short_Term_Synthesis_Filter( S, LARcr, wt, s );
+  Postprocessing(S, s);
+}
+
+
+
+/****-------------------------------------------------------------------****
+ **** Podlipec:  For AVI/WAV files GSM 6.10 combines two 33 bytes frames
+ **** into one 65 byte frame.
+ ****-------------------------------------------------------------------****/
+void XA_MSGSM_Decoder(unsigned char *ibuf,unsigned short *obuf)
+{ word sr;
+  word  LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];	
+
+  sr = *ibuf++;
+
+  LARc[0] = sr & 0x3f;  sr >>= 6;
+  sr |= (word)*ibuf++ << 2;
+  LARc[1] = sr & 0x3f;  sr >>= 6;
+  sr |= (word)*ibuf++ << 4;
+  LARc[2] = sr & 0x1f;  sr >>= 5;
+  LARc[3] = sr & 0x1f;  sr >>= 5;
+  sr |= (word)*ibuf++ << 2;
+  LARc[4] = sr & 0xf;  sr >>= 4;
+  LARc[5] = sr & 0xf;  sr >>= 4;
+  sr |= (word)*ibuf++ << 2;			/* 5 */
+  LARc[6] = sr & 0x7;  sr >>= 3;
+  LARc[7] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 4;
+  Nc[0] = sr & 0x7f;  sr >>= 7;
+  bc[0] = sr & 0x3;  sr >>= 2;
+  Mc[0] = sr & 0x3;  sr >>= 2;
+  sr |= (word)*ibuf++ << 1;
+  xmaxc[0] = sr & 0x3f;  sr >>= 6;
+  xmc[0] = sr & 0x7;  sr >>= 3;
+  sr = *ibuf++;
+  xmc[1] = sr & 0x7;  sr >>= 3;
+  xmc[2] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 2;
+  xmc[3] = sr & 0x7;  sr >>= 3;
+  xmc[4] = sr & 0x7;  sr >>= 3;
+  xmc[5] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 1;			/* 10 */
+  xmc[6] = sr & 0x7;  sr >>= 3;
+  xmc[7] = sr & 0x7;  sr >>= 3;
+  xmc[8] = sr & 0x7;  sr >>= 3;
+  sr = *ibuf++;
+  xmc[9] = sr & 0x7;  sr >>= 3;
+  xmc[10] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 2;
+  xmc[11] = sr & 0x7;  sr >>= 3;
+  xmc[12] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 4;
+  Nc[1] = sr & 0x7f;  sr >>= 7;
+  bc[1] = sr & 0x3;  sr >>= 2;
+  Mc[1] = sr & 0x3;  sr >>= 2;
+  sr |= (word)*ibuf++ << 1;
+  xmaxc[1] = sr & 0x3f;  sr >>= 6;
+  xmc[13] = sr & 0x7;  sr >>= 3;
+  sr = *ibuf++;				/* 15 */
+  xmc[14] = sr & 0x7;  sr >>= 3;
+  xmc[15] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 2;
+  xmc[16] = sr & 0x7;  sr >>= 3;
+  xmc[17] = sr & 0x7;  sr >>= 3;
+  xmc[18] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 1;
+  xmc[19] = sr & 0x7;  sr >>= 3;
+  xmc[20] = sr & 0x7;  sr >>= 3;
+  xmc[21] = sr & 0x7;  sr >>= 3;
+  sr = *ibuf++;
+  xmc[22] = sr & 0x7;  sr >>= 3;
+  xmc[23] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 2;
+  xmc[24] = sr & 0x7;  sr >>= 3;
+  xmc[25] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 4;			/* 20 */
+  Nc[2] = sr & 0x7f;  sr >>= 7;
+  bc[2] = sr & 0x3;  sr >>= 2;
+  Mc[2] = sr & 0x3;  sr >>= 2;
+  sr |= (word)*ibuf++ << 1;
+  xmaxc[2] = sr & 0x3f;  sr >>= 6;
+  xmc[26] = sr & 0x7;  sr >>= 3;
+  sr = *ibuf++;
+  xmc[27] = sr & 0x7;  sr >>= 3;
+  xmc[28] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 2;
+  xmc[29] = sr & 0x7;  sr >>= 3;
+  xmc[30] = sr & 0x7;  sr >>= 3;
+  xmc[31] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 1;
+  xmc[32] = sr & 0x7;  sr >>= 3;
+  xmc[33] = sr & 0x7;  sr >>= 3;
+  xmc[34] = sr & 0x7;  sr >>= 3;
+  sr = *ibuf++;				/* 25 */
+  xmc[35] = sr & 0x7;  sr >>= 3;
+  xmc[36] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 2;
+  xmc[37] = sr & 0x7;  sr >>= 3;
+  xmc[38] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 4;
+  Nc[3] = sr & 0x7f;  sr >>= 7;
+  bc[3] = sr & 0x3;  sr >>= 2;
+  Mc[3] = sr & 0x3;  sr >>= 2;
+  sr |= (word)*ibuf++ << 1;
+  xmaxc[3] = sr & 0x3f;  sr >>= 6;
+  xmc[39] = sr & 0x7;  sr >>= 3;
+  sr = *ibuf++;
+  xmc[40] = sr & 0x7;  sr >>= 3;
+  xmc[41] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 2;			/* 30 */
+  xmc[42] = sr & 0x7;  sr >>= 3;
+  xmc[43] = sr & 0x7;  sr >>= 3;
+  xmc[44] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 1;
+  xmc[45] = sr & 0x7;  sr >>= 3;
+  xmc[46] = sr & 0x7;  sr >>= 3;
+  xmc[47] = sr & 0x7;  sr >>= 3;
+  sr = *ibuf++;
+  xmc[48] = sr & 0x7;  sr >>= 3;
+  xmc[49] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 2;
+  xmc[50] = sr & 0x7;  sr >>= 3;
+  xmc[51] = sr & 0x7;  sr >>= 3;
+
+  GSM_Decode(&gsm_state, LARc, Nc, bc, Mc, xmaxc, xmc, obuf);
+
+/*
+  carry = sr & 0xf;
+  sr = carry;
+*/
+  /* 2nd frame */
+  sr &= 0xf;
+  sr |= (word)*ibuf++ << 4;			/* 1 */
+  LARc[0] = sr & 0x3f;  sr >>= 6;
+  LARc[1] = sr & 0x3f;  sr >>= 6;
+  sr = *ibuf++;
+  LARc[2] = sr & 0x1f;  sr >>= 5;
+  sr |= (word)*ibuf++ << 3;
+  LARc[3] = sr & 0x1f;  sr >>= 5;
+  LARc[4] = sr & 0xf;  sr >>= 4;
+  sr |= (word)*ibuf++ << 2;
+  LARc[5] = sr & 0xf;  sr >>= 4;
+  LARc[6] = sr & 0x7;  sr >>= 3;
+  LARc[7] = sr & 0x7;  sr >>= 3;
+  sr = *ibuf++;				/* 5 */
+  Nc[0] = sr & 0x7f;  sr >>= 7;
+  sr |= (word)*ibuf++ << 1;
+  bc[0] = sr & 0x3;  sr >>= 2;
+  Mc[0] = sr & 0x3;  sr >>= 2;
+  sr |= (word)*ibuf++ << 5;
+  xmaxc[0] = sr & 0x3f;  sr >>= 6;
+  xmc[0] = sr & 0x7;  sr >>= 3;
+  xmc[1] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 1;
+  xmc[2] = sr & 0x7;  sr >>= 3;
+  xmc[3] = sr & 0x7;  sr >>= 3;
+  xmc[4] = sr & 0x7;  sr >>= 3;
+  sr = *ibuf++;
+  xmc[5] = sr & 0x7;  sr >>= 3;
+  xmc[6] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 2;			/* 10 */
+  xmc[7] = sr & 0x7;  sr >>= 3;
+  xmc[8] = sr & 0x7;  sr >>= 3;
+  xmc[9] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 1;
+  xmc[10] = sr & 0x7;  sr >>= 3;
+  xmc[11] = sr & 0x7;  sr >>= 3;
+  xmc[12] = sr & 0x7;  sr >>= 3;
+  sr = *ibuf++;
+  Nc[1] = sr & 0x7f;  sr >>= 7;
+  sr |= (word)*ibuf++ << 1;
+  bc[1] = sr & 0x3;  sr >>= 2;
+  Mc[1] = sr & 0x3;  sr >>= 2;
+  sr |= (word)*ibuf++ << 5;
+  xmaxc[1] = sr & 0x3f;  sr >>= 6;
+  xmc[13] = sr & 0x7;  sr >>= 3;
+  xmc[14] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 1;			/* 15 */
+  xmc[15] = sr & 0x7;  sr >>= 3;
+  xmc[16] = sr & 0x7;  sr >>= 3;
+  xmc[17] = sr & 0x7;  sr >>= 3;
+  sr = *ibuf++;
+  xmc[18] = sr & 0x7;  sr >>= 3;
+  xmc[19] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 2;
+  xmc[20] = sr & 0x7;  sr >>= 3;
+  xmc[21] = sr & 0x7;  sr >>= 3;
+  xmc[22] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 1;
+  xmc[23] = sr & 0x7;  sr >>= 3;
+  xmc[24] = sr & 0x7;  sr >>= 3;
+  xmc[25] = sr & 0x7;  sr >>= 3;
+  sr = *ibuf++;
+  Nc[2] = sr & 0x7f;  sr >>= 7;
+  sr |= (word)*ibuf++ << 1;			/* 20 */
+  bc[2] = sr & 0x3;  sr >>= 2;
+  Mc[2] = sr & 0x3;  sr >>= 2;
+  sr |= (word)*ibuf++ << 5;
+  xmaxc[2] = sr & 0x3f;  sr >>= 6;
+  xmc[26] = sr & 0x7;  sr >>= 3;
+  xmc[27] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 1;	
+  xmc[28] = sr & 0x7;  sr >>= 3;
+  xmc[29] = sr & 0x7;  sr >>= 3;
+  xmc[30] = sr & 0x7;  sr >>= 3;
+  sr = *ibuf++;
+  xmc[31] = sr & 0x7;  sr >>= 3;
+  xmc[32] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 2;
+  xmc[33] = sr & 0x7;  sr >>= 3;
+  xmc[34] = sr & 0x7;  sr >>= 3;
+  xmc[35] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 1;			/* 25 */
+  xmc[36] = sr & 0x7;  sr >>= 3;
+  xmc[37] = sr & 0x7;  sr >>= 3;
+  xmc[38] = sr & 0x7;  sr >>= 3;
+  sr = *ibuf++;
+  Nc[3] = sr & 0x7f;  sr >>= 7;
+  sr |= (word)*ibuf++ << 1;		
+  bc[3] = sr & 0x3;  sr >>= 2;
+  Mc[3] = sr & 0x3;  sr >>= 2;
+  sr |= (word)*ibuf++ << 5;
+  xmaxc[3] = sr & 0x3f;  sr >>= 6;
+  xmc[39] = sr & 0x7;  sr >>= 3;
+  xmc[40] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 1;
+  xmc[41] = sr & 0x7;  sr >>= 3;
+  xmc[42] = sr & 0x7;  sr >>= 3;
+  xmc[43] = sr & 0x7;  sr >>= 3;
+  sr = (word)*ibuf++;				/* 30 */
+  xmc[44] = sr & 0x7;  sr >>= 3;
+  xmc[45] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 2;
+  xmc[46] = sr & 0x7;  sr >>= 3;
+  xmc[47] = sr & 0x7;  sr >>= 3;
+  xmc[48] = sr & 0x7;  sr >>= 3;
+  sr |= (word)*ibuf++ << 1;
+  xmc[49] = sr & 0x7;  sr >>= 3;
+  xmc[50] = sr & 0x7;  sr >>= 3;
+  xmc[51] = sr & 0x7;  sr >>= 3;
+
+  GSM_Decode(&gsm_state, LARc, Nc, bc, Mc, xmaxc, xmc, &obuf[160]);
+
+  /* Return number of source bytes consumed and output samples produced */
+//  *icnt = 65;		
+//  *ocnt = 320;
+  return;
+}
+
+#define GSM_MAGIC 0xd
+
+void XA_GSM_Decoder(unsigned char *ibuf,unsigned short *obuf)
+{ word  LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];	
+
+	/* Sanity */
+  if (((*ibuf >> 4) & 0x0F) != GSM_MAGIC)
+  { int i;
+    for(i=0;i<160;i++) obuf[i] = 0;
+//    *icnt = 33;
+//    *ocnt = 160;
+    return;
+  }
+
+  LARc[0]  = (*ibuf++ & 0xF) << 2;           /* 1 */
+  LARc[0] |= (*ibuf >> 6) & 0x3;
+  LARc[1]  = *ibuf++ & 0x3F;
+  LARc[2]  = (*ibuf >> 3) & 0x1F;
+  LARc[3]  = (*ibuf++ & 0x7) << 2;
+  LARc[3] |= (*ibuf >> 6) & 0x3;
+  LARc[4]  = (*ibuf >> 2) & 0xF;
+  LARc[5]  = (*ibuf++ & 0x3) << 2;
+  LARc[5] |= (*ibuf >> 6) & 0x3;
+  LARc[6]  = (*ibuf >> 3) & 0x7;
+  LARc[7]  = *ibuf++ & 0x7;
+
+  Nc[0]  = (*ibuf >> 1) & 0x7F;
+
+  bc[0]  = (*ibuf++ & 0x1) << 1;
+  bc[0] |= (*ibuf >> 7) & 0x1;
+
+  Mc[0]  = (*ibuf >> 5) & 0x3;
+
+  xmaxc[0]  = (*ibuf++ & 0x1F) << 1;
+  xmaxc[0] |= (*ibuf >> 7) & 0x1;
+
+  xmc[0]  = (*ibuf >> 4) & 0x7;
+  xmc[1]  = (*ibuf >> 1) & 0x7;
+  xmc[2]  = (*ibuf++ & 0x1) << 2;
+  xmc[2] |= (*ibuf >> 6) & 0x3;
+  xmc[3]  = (*ibuf >> 3) & 0x7;
+  xmc[4]  = *ibuf++ & 0x7;
+  xmc[5]  = (*ibuf >> 5) & 0x7;
+  xmc[6]  = (*ibuf >> 2) & 0x7;
+  xmc[7]  = (*ibuf++ & 0x3) << 1;            /* 10 */
+  xmc[7] |= (*ibuf >> 7) & 0x1;
+  xmc[8]  = (*ibuf >> 4) & 0x7;
+  xmc[9]  = (*ibuf >> 1) & 0x7;
+  xmc[10]  = (*ibuf++ & 0x1) << 2;
+  xmc[10] |= (*ibuf >> 6) & 0x3;
+  xmc[11]  = (*ibuf >> 3) & 0x7;
+  xmc[12]  = *ibuf++ & 0x7;
+
+  Nc[1]  = (*ibuf >> 1) & 0x7F;
+
+  bc[1]  = (*ibuf++ & 0x1) << 1;
+  bc[1] |= (*ibuf >> 7) & 0x1;
+
+  Mc[1]  = (*ibuf >> 5) & 0x3;
+
+  xmaxc[1]  = (*ibuf++ & 0x1F) << 1;
+  xmaxc[1] |= (*ibuf >> 7) & 0x1;
+
+
+  xmc[13]  = (*ibuf >> 4) & 0x7;
+  xmc[14]  = (*ibuf >> 1) & 0x7;
+  xmc[15]  = (*ibuf++ & 0x1) << 2;
+  xmc[15] |= (*ibuf >> 6) & 0x3;
+  xmc[16]  = (*ibuf >> 3) & 0x7;
+  xmc[17]  = *ibuf++ & 0x7;
+  xmc[18]  = (*ibuf >> 5) & 0x7;
+  xmc[19]  = (*ibuf >> 2) & 0x7;
+  xmc[20]  = (*ibuf++ & 0x3) << 1;
+  xmc[20] |= (*ibuf >> 7) & 0x1;
+  xmc[21]  = (*ibuf >> 4) & 0x7;
+  xmc[22]  = (*ibuf >> 1) & 0x7;
+  xmc[23]  = (*ibuf++ & 0x1) << 2;
+  xmc[23] |= (*ibuf >> 6) & 0x3;
+  xmc[24]  = (*ibuf >> 3) & 0x7;
+  xmc[25]  = *ibuf++ & 0x7;
+
+  Nc[2]  = (*ibuf >> 1) & 0x7F;
+
+  bc[2]  = (*ibuf++ & 0x1) << 1;             /* 20 */
+  bc[2] |= (*ibuf >> 7) & 0x1;
+
+  Mc[2]  = (*ibuf >> 5) & 0x3;
+
+  xmaxc[2]  = (*ibuf++ & 0x1F) << 1;
+  xmaxc[2] |= (*ibuf >> 7) & 0x1;
+
+
+  xmc[26]  = (*ibuf >> 4) & 0x7;
+  xmc[27]  = (*ibuf >> 1) & 0x7;
+  xmc[28]  = (*ibuf++ & 0x1) << 2;
+  xmc[28] |= (*ibuf >> 6) & 0x3;
+  xmc[29]  = (*ibuf >> 3) & 0x7;
+  xmc[30]  = *ibuf++ & 0x7;
+  xmc[31]  = (*ibuf >> 5) & 0x7;
+  xmc[32]  = (*ibuf >> 2) & 0x7;
+  xmc[33]  = (*ibuf++ & 0x3) << 1;
+  xmc[33] |= (*ibuf >> 7) & 0x1;
+  xmc[34]  = (*ibuf >> 4) & 0x7;
+  xmc[35]  = (*ibuf >> 1) & 0x7;
+  xmc[36]  = (*ibuf++ & 0x1) << 2;
+  xmc[36] |= (*ibuf >> 6) & 0x3;
+  xmc[37]  = (*ibuf >> 3) & 0x7;
+  xmc[38]  = *ibuf++ & 0x7;
+
+  Nc[3]  = (*ibuf >> 1) & 0x7F;
+
+  bc[3]  = (*ibuf++ & 0x1) << 1;
+  bc[3] |= (*ibuf >> 7) & 0x1;
+
+  Mc[3]  = (*ibuf >> 5) & 0x3;
+
+  xmaxc[3]  = (*ibuf++ & 0x1F) << 1;
+  xmaxc[3] |= (*ibuf >> 7) & 0x1;
+
+  xmc[39]  = (*ibuf >> 4) & 0x7;
+  xmc[40]  = (*ibuf >> 1) & 0x7;
+  xmc[41]  = (*ibuf++ & 0x1) << 2;
+  xmc[41] |= (*ibuf >> 6) & 0x3;
+  xmc[42]  = (*ibuf >> 3) & 0x7;
+  xmc[43]  = *ibuf++ & 0x7;                  /* 30  */
+  xmc[44]  = (*ibuf >> 5) & 0x7;
+  xmc[45]  = (*ibuf >> 2) & 0x7;
+  xmc[46]  = (*ibuf++ & 0x3) << 1;
+  xmc[46] |= (*ibuf >> 7) & 0x1;
+  xmc[47]  = (*ibuf >> 4) & 0x7;
+  xmc[48]  = (*ibuf >> 1) & 0x7;
+  xmc[49]  = (*ibuf++ & 0x1) << 2;
+  xmc[49] |= (*ibuf >> 6) & 0x3;
+  xmc[50]  = (*ibuf >> 3) & 0x7;
+  xmc[51]  = *ibuf & 0x7;                    /* 33 */
+
+  GSM_Decode(&gsm_state, LARc, Nc, bc, Mc, xmaxc, xmc, obuf);
+
+  /* Return number of source bytes consumed and output samples produced */
+//  *icnt = 33;
+//  *ocnt = 160;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xa/xa_gsm.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,6 @@
+
+void XA_MSGSM_Decoder(unsigned char *ibuf,unsigned short *obuf);
+void XA_GSM_Decoder(unsigned char *ibuf,unsigned short *obuf);
+void GSM_Init();
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xa/xa_gsm_int.h	Sat Feb 24 20:28:24 2001 +0000
@@ -0,0 +1,114 @@
+/********************************************************************
+ *
+ * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
+ * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for
+ * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
+ *
+ ********************************************************************/
+
+#include "xa_gsm.h"
+
+
+typedef short			word;		/* 16 bit signed int	*/
+typedef int			longword;	/* 32 bit signed int	*/
+
+typedef unsigned short		uword;		/* unsigned word	*/
+typedef unsigned int		ulongword;	/* unsigned longword	*/
+
+typedef struct {
+
+	word		dp0[ 280 ];
+
+	word		z1;		/* preprocessing.c, Offset_com. */
+	longword	L_z2;		/*                  Offset_com. */
+	int		mp;		/*                  Preemphasis	*/
+
+	word		u[8];		/* short_term_aly_filter.c	*/
+	word		LARpp[2][8]; 	/*                              */
+	word		j;		/*                              */
+
+	word            ltp_cut;        /* long_term.c, LTP crosscorr.  */
+	word		nrp; /* 40 */	/* long_term.c, synthesis	*/
+	word		v[9];		/* short_term.c, synthesis	*/
+	word		msr;		/* decoder.c,	Postprocessing	*/
+
+	char		verbose;	/* only used if !NDEBUG		*/
+	char		fast;		/* only used if FAST		*/
+
+	char		wav_fmt;	/* only used if WAV49 defined	*/
+	unsigned char	frame_index;	/*            odd/even chaining	*/
+	unsigned char	frame_chain;	/*   half-byte to carry forward	*/
+} XA_GSM_STATE;
+
+
+#define	MIN_WORD	(-32767 - 1)
+#define	MAX_WORD	  32767
+
+#define	MIN_LONGWORD	(-2147483647 - 1)
+#define	MAX_LONGWORD	  2147483647
+
+#ifdef	SASR		/* flag: >> is a signed arithmetic shift right */
+#undef	SASR
+#define	SASR(x, by)	((x) >> (by))
+#else
+#define	SASR(x, by)	((x) >= 0 ? (x) >> (by) : (~(-((x) + 1) >> (by))))
+#endif	/* SASR */
+
+
+
+/*
+ *  Inlined functions from add.h 
+ */
+
+/* 
+ * #define GSM_MULT_R(a, b) (* word a, word b, !(a == b == MIN_WORD) *)	\
+ *	(0x0FFFF & SASR(((longword)(a) * (longword)(b) + 16384), 15))
+ */
+#define GSM_MULT_R(a, b) /* word a, word b, !(a == b == MIN_WORD) */	\
+	(SASR( ((longword)(a) * (longword)(b) + 16384), 15 ))
+
+# define GSM_MULT(a,b)	 /* word a, word b, !(a == b == MIN_WORD) */	\
+	(SASR( ((longword)(a) * (longword)(b)), 15 ))
+
+# define GSM_L_MULT(a, b) /* word a, word b */	\
+	(((longword)(a) * (longword)(b)) << 1)
+
+# define GSM_L_ADD(a, b)	\
+	( (a) <  0 ? ( (b) >= 0 ? (a) + (b)	\
+		 : (utmp = (ulongword)-((a) + 1) + (ulongword)-((b) + 1)) \
+		   >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)utmp-2 )   \
+	: ((b) <= 0 ? (a) + (b)   \
+	          : (utmp = (ulongword)(a) + (ulongword)(b)) >= MAX_LONGWORD \
+		    ? MAX_LONGWORD : utmp))
+
+/*
+ * # define GSM_ADD(a, b)	\
+ * 	((ltmp = (longword)(a) + (longword)(b)) >= MAX_WORD \
+ * 	? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
+ */
+/* Nonportable, but faster: */
+
+#define	GSM_ADD(a, b)	\
+	((ulongword)((ltmp = (longword)(a) + (longword)(b)) - MIN_WORD) > \
+		MAX_WORD - MIN_WORD ? (ltmp > 0 ? MAX_WORD : MIN_WORD) : ltmp)
+
+# define GSM_SUB(a, b)	\
+	((ltmp = (longword)(a) - (longword)(b)) >= MAX_WORD \
+	? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
+
+# define GSM_ABS(a)	((a) < 0 ? ((a) == MIN_WORD ? MAX_WORD : -(a)) : (a))
+
+/* Use these if necessary:
+
+# define GSM_MULT_R(a, b)	gsm_mult_r(a, b)
+# define GSM_MULT(a, b)		gsm_mult(a, b)
+# define GSM_L_MULT(a, b)	gsm_L_mult(a, b)
+
+# define GSM_L_ADD(a, b)	gsm_L_add(a, b)
+# define GSM_ADD(a, b)		gsm_add(a, b)
+# define GSM_SUB(a, b)		gsm_sub(a, b)
+
+# define GSM_ABS(a)		gsm_abs(a)
+
+*/
+