Browse Source

--- Merging r16017 into '.':
U packages/hermes/Makefile.fpc
U packages/hermes/src/p_gca.inc
U packages/hermes/src/p_gac.inc
U packages/hermes/src/p_muhmu.inc
U packages/hermes/src/p_cpy.inc
U packages/hermes/src/hermdef.inc
A packages/hermes/src/hermes_converter.inc
A packages/hermes/src/hermes_factory.inc
U packages/hermes/src/p_gcc.inc
A packages/hermes/src/hermes_list.inc
A packages/hermes/src/hermes_clearer.inc
U packages/hermes/src/headp.inc
U packages/hermes/src/i386/x86p_cpy.as
U packages/hermes/src/i386/headi386.inc
U packages/hermes/src/i386/mmx_clr.as
U packages/hermes/src/i386/x8616lut.as
U packages/hermes/src/i386/x86pscpy.as
U packages/hermes/src/i386/mmx_main.as
U packages/hermes/src/i386/mmxp_32.as
U packages/hermes/src/i386/x86_clr.as
U packages/hermes/src/i386/x86p_i8.as
U packages/hermes/src/i386/mmxp2_32.as
U packages/hermes/src/i386/headmmx.inc
U packages/hermes/src/i386/x86_main.as
U packages/hermes/src/i386/x86p_32.as
U packages/hermes/src/i386/x86p_16.as
U packages/hermes/src/i386/x86p_s32.as
D packages/hermes/src/dither.inc
D packages/hermes/src/convert.inc
D packages/hermes/src/utility.inc
D packages/hermes/src/clear.inc
D packages/hermes/src/debug.inc
D packages/hermes/src/factory.inc
D packages/hermes/src/malloc.inc
D packages/hermes/src/format.inc
D packages/hermes/src/list.inc
D packages/hermes/src/palette.inc
A packages/hermes/src/hermes_dither.inc
U packages/hermes/src/d_32.inc
U packages/hermes/src/hermes.pp
A packages/hermes/src/hermes_debug.inc
A packages/hermes/src/hermes_format.inc
U packages/hermes/src/p_clr.inc
U packages/hermes/src/p_i8.inc
A packages/hermes/src/hermes_palette.inc
U packages/hermes/src/hermconf.inc
U packages/hermes/src/factconv.inc
U packages/hermes/src/p_32.inc
U packages/hermes/src/p_24.inc
U packages/hermes/src/p_16.inc
U packages/hermes/src/p_cnv.inc
U packages/hermes/src/p_g.inc
A packages/hermes/src/hermes_utility.inc
U packages/hermes/src/p_ga.inc
C packages/hermes/Makefile
--- Merging r16018 into '.':
A packages/ptc/tests/convtest.pp
A packages/ptc/tests/endian.inc
U packages/ptc/tests/view.pp
D packages/ptc/tests/endian.pas
D packages/ptc/tests/convtest.pas
U packages/ptc/Makefile.fpc
UU packages/ptc/src/win32/directx/primaryd.inc
UU packages/ptc/src/win32/directx/libraryd.inc
UU packages/ptc/src/win32/directx/directxconsoled.inc
UU packages/ptc/src/win32/directx/displayd.inc
UU packages/ptc/src/win32/directx/check.inc
UU packages/ptc/src/win32/directx/translate.inc
A packages/ptc/src/win32/directx/directxconsolei.inc
UU packages/ptc/src/win32/directx/hook.inc
UU packages/ptc/src/win32/directx/primary.inc
UU packages/ptc/src/win32/directx/hookd.inc
UU packages/ptc/src/win32/directx/library.inc
UU packages/ptc/src/win32/directx/display.inc
A packages/ptc/src/win32/directx/p_ddraw.pp
D packages/ptc/src/colord.inc
D packages/ptc/src/timerd.inc
D packages/ptc/src/basesurfaced.inc
D packages/ptc/src/colori.inc
D packages/ptc/src/moded.inc
D packages/ptc/src/timeri.inc
D packages/ptc/src/cleard.inc
D packages/ptc/src/surfaced.inc
D packages/ptc/src/basesurfacei.inc
D packages/ptc/src/keyd.inc
D packages/ptc/src/errord.inc
D packages/ptc/src/modei.inc
D packages/ptc/src/coreimplementation.inc
D packages/ptc/src/cleari.inc
D packages/ptc/src/keyi.inc
D packages/ptc/src/baseconsoled.inc
D packages/ptc/src/surfacei.inc
D packages/ptc/src/errori.inc
D packages/ptc/src/paletted.inc
D packages/ptc/src/consoled.inc
D packages/ptc/src/baseconsolei.inc
D packages/ptc/src/palettei.inc
D packages/ptc/src/coreinterface.inc
D packages/ptc/src/consolei.inc
D packages/ptc/src/aread.inc
D packages/ptc/src/copyd.inc
D packages/ptc/src/log.inc
D packages/ptc/src/areai.inc
D packages/ptc/src/copyi.inc
D packages/ptc/src/eventd.inc
D packages/ptc/src/win32/directx/directxconsole.inc
D packages/ptc/src/eventi.inc
D packages/ptc/src/formatd.inc
D packages/ptc/src/keyeventd.inc
D packages/ptc/src/mouseeventd.inc
D packages/ptc/src/formati.inc
D packages/ptc/src/clipperd.inc
D packages/ptc/src/mouseeventi.inc
D packages/ptc/src/keyeventi.inc
D packages/ptc/src/clipperi.inc
D packages/ptc/src/win32/directx/directdr.pp
UU packages/ptc/src/win32/gdi/gdiconsoled.inc
UU packages/ptc/src/win32/gdi/win32dibi.inc
UU packages/ptc/src/win32/gdi/gdiconsolei.inc
UU packages/ptc/src/win32/gdi/win32dibd.inc
UU packages/ptc/src/win32/base/window.inc
UU packages/ptc/src/win32/base/windowd.inc
UU packages/ptc/src/win32/base/cursor.inc
A packages/ptc/src/win32/base/cursord.inc
UU packages/ptc/src/win32/base/event.inc
UU packages/ptc/src/win32/base/eventd.inc
A packages/ptc/src/win32/base/cursormoded.inc
UU packages/ptc/src/win32/base/monitor.inc
UU packages/ptc/src/win32/base/monitord.inc
UU packages/ptc/src/win32/base/moused.inc
UU packages/ptc/src/win32/base/hook.inc
UU packages/ptc/src/win32/base/kbd.inc
UU packages/ptc/src/win32/base/mousei.inc
UU packages/ptc/src/win32/base/kbdd.inc
UU packages/ptc/src/win32/base/hookd.inc
U packages/ptc/src/ptc.pp
UU packages/ptc/src/dos/textfx2/textfx2.pp
A packages/ptc/src/dos/textfx2/textfx2consoled.inc
A packages/ptc/src/dos/textfx2/textfx2consolei.inc
D packages/ptc/src/dos/fakemode
D packages/ptc/src/dos/textfx2/console.inc
D packages/ptc/src/dos/textfx2/consoled.inc
A packages/ptc/src/dos/base/go32fix.pp
A packages/ptc/src/dos/base/mouse33h.pp
A packages/ptc/src/dos/base/moused.inc
UU packages/ptc/src/dos/base/kbd.inc
A packages/ptc/src/dos/base/mousei.inc
UU packages/ptc/src/dos/base/kbdd.inc
UU packages/ptc/src/dos/cga/cga.pp
A packages/ptc/src/dos/cga/cgaconsoled.inc
A packages/ptc/src/dos/cga/cgaconsolei.inc
D packages/ptc/src/dos/cga/console.inc
D packages/ptc/src/dos/cga/consoled.inc
A packages/ptc/src/dos/vga
A packages/ptc/src/dos/vga/vgaconsolei.inc
A packages/ptc/src/dos/vga/vga.pp
A packages/ptc/src/dos/vga/vgaconsoled.inc
A packages/ptc/src/dos/includes.inc
UU packages/ptc/src/dos/timeunit/timeunit.pp
A packages/ptc/src/dos/vesa/vesaconsolei.inc
UU packages/ptc/src/dos/vesa/vesa.pp
A packages/ptc/src/dos/vesa/vesaconsoled.inc
D packages/ptc/src/dos/vesa/console.inc
D packages/ptc/src/dos/vesa/consoled.inc
UU packages/ptc/src/wince/gapi/wincegapiconsoled.inc
UU packages/ptc/src/wince/gapi/wincegapiconsolei.inc
UU packages/ptc/src/wince/gapi/p_gx.pp
A packages/ptc/src/wince/directx/ddraw.pas
UU packages/ptc/src/wince/gdi/wincebitmapinfoi.inc
UU packages/ptc/src/wince/gdi/wincegdiconsoled.inc
UU packages/ptc/src/wince/gdi/wincebitmapinfod.inc
UU packages/ptc/src/wince/gdi/wincegdiconsolei.inc
UU packages/ptc/src/wince/base/wincemousei.inc
UU packages/ptc/src/wince/base/wincekeyboardd.inc
UU packages/ptc/src/wince/base/wincekeyboardi.inc
UU packages/ptc/src/wince/base/wincewindowd.inc
UU packages/ptc/src/wince/base/wincemoused.inc
UU packages/ptc/src/wince/base/wincewindowi.inc
U packages/ptc/src/wince/includes.inc
A packages/ptc/src/ptcwrapper
A packages/ptc/src/ptcwrapper/ptcwrapper.pp
A packages/ptc/src/ptcwrapper/ptceventqueue.pp
A packages/ptc/src/core
A packages/ptc/src/core/clipperi.inc
A packages/ptc/src/core/coreinterface.inc
A packages/ptc/src/core/aread.inc
A packages/ptc/src/core/copyd.inc
A packages/ptc/src/core/log.inc
A packages/ptc/src/core/areai.inc
A packages/ptc/src/core/colord.inc
A packages/ptc/src/core/copyi.inc
A packages/ptc/src/core/timerd.inc
A packages/ptc/src/core/basesurfaced.inc
A packages/ptc/src/core/colori.inc
A packages/ptc/src/core/timeri.inc
A packages/ptc/src/core/cleard.inc
A packages/ptc/src/core/formatd.inc
A packages/ptc/src/core/basesurfacei.inc
A packages/ptc/src/core/surfaced.inc
A packages/ptc/src/core/errord.inc
A packages/ptc/src/core/coreimplementation.inc
A packages/ptc/src/core/keyeventd.inc
A packages/ptc/src/core/mouseeventd.inc
A packages/ptc/src/core/cleari.inc
A packages/ptc/src/core/surfacei.inc
A packages/ptc/src/core/baseconsoled.inc
A packages/ptc/src/core/formati.inc
A packages/ptc/src/core/errori.inc
A packages/ptc/src/core/paletted.inc
A packages/ptc/src/core/keyeventi.inc
A packages/ptc/src/core/mouseeventi.inc
A packages/ptc/src/core/consoled.inc
A packages/ptc/src/core/baseconsolei.inc
A packages/ptc/src/core/palettei.inc
A packages/ptc/src/core/consolei.inc
A packages/ptc/src/core/eventd.inc
A packages/ptc/src/core/moded.inc
A packages/ptc/src/core/eventi.inc
A packages/ptc/src/core/modei.inc
A packages/ptc/src/core/clipperd.inc
U packages/ptc/src/ptcpas.cfg
UU packages/ptc/src/x11/x11displayi.inc
UU packages/ptc/src/x11/x11modesi.inc
UU packages/ptc/src/x11/check.inc
U packages/ptc/src/x11/x11dgadisplayd.inc
UU packages/ptc/src/x11/x11imaged.inc
U packages/ptc/src/x11/x11dgadisplayi.inc
UU packages/ptc/src/x11/x11imagei.inc
UU packages/ptc/src/x11/x11windowdisplayd.inc
UU packages/ptc/src/x11/xunikey.inc
U packages/ptc/src/x11/extensions.inc
UU packages/ptc/src/x11/x11windowdisplayi.inc
UU packages/ptc/src/x11/x11consoled.inc
UU packages/ptc/src/x11/x11dga1displayd.inc
UU packages/ptc/src/x11/x11dga2displayd.inc
UU packages/ptc/src/x11/x11displayd.inc
UU packages/ptc/src/x11/x11modesd.inc
UU packages/ptc/src/x11/x11dga1displayi.inc
UU packages/ptc/src/x11/x11consolei.inc
UU packages/ptc/src/x11/x11dga2displayi.inc
U packages/ptc/src/x11/includes.inc
UU packages/ptc/src/tinyptc/tinyptc.pp
U packages/ptc/src/c_api/index.inc
U packages/ptc/src/c_api/area.inc
U packages/ptc/src/c_api/copy.inc
U packages/ptc/src/c_api/aread.inc
U packages/ptc/src/c_api/color.inc
U packages/ptc/src/c_api/copyd.inc
U packages/ptc/src/c_api/timer.inc
U packages/ptc/src/c_api/colord.inc
U packages/ptc/src/c_api/timerd.inc
U packages/ptc/src/c_api/mode.inc
U packages/ptc/src/c_api/clear.inc
U packages/ptc/src/c_api/surface.inc
U packages/ptc/src/c_api/moded.inc
U packages/ptc/src/c_api/key.inc
U packages/ptc/src/c_api/format.inc
U packages/ptc/src/c_api/except.inc
U packages/ptc/src/c_api/error.inc
U packages/ptc/src/c_api/cleard.inc
U packages/ptc/src/c_api/exceptd.inc
U packages/ptc/src/c_api/formatd.inc
U packages/ptc/src/c_api/keyd.inc
U packages/ptc/src/c_api/surfaced.inc
U packages/ptc/src/c_api/errord.inc
U packages/ptc/src/c_api/clipper.inc
U packages/ptc/src/c_api/palette.inc
U packages/ptc/src/c_api/console.inc
U packages/ptc/src/c_api/clipperd.inc
U packages/ptc/src/c_api/paletted.inc
U packages/ptc/src/c_api/consoled.inc
A packages/ptc/docs/AUTHORS.txt
U packages/ptc/docs/TODO.txt
A packages/ptc/docs/INSTALL.txt
A packages/ptc/docs/CHANGES.txt
A packages/ptc/docs/INTRO.txt
U packages/ptc/docs/README.txt
U packages/ptc/docs/lgpl.txt
A packages/ptc/docs/modified_lgpl.txt
D packages/ptc/docs/AUTHORS
D packages/ptc/docs/INTRO
D packages/ptc/docs/INSTALL
D packages/ptc/docs/CHANGES
C packages/ptc/Makefile
U packages/ptc/examples/mojo.pp
U packages/ptc/examples/tunnel.pp
U packages/ptc/examples/area.pp
U packages/ptc/examples/land.pp
U packages/ptc/examples/timer.pp
U packages/ptc/examples/random.pp
U packages/ptc/examples/clear.pp
A packages/ptc/examples/mouse.pp
U packages/ptc/examples/lights.pp
U packages/ptc/examples/tunnel3d.pp
U packages/ptc/examples/palette.pp
U packages/ptc/examples/hicolor.pp
U packages/ptc/examples/keyboard.pp
U packages/ptc/examples/console.pp
U packages/ptc/examples/modes.pp
U packages/ptc/examples/buffer.pp
U packages/ptc/examples/stretch.pp
U packages/ptc/examples/pixel.pp
A packages/ptc/examples/keyboard2.pp
U packages/ptc/examples/image.pp
U packages/ptc/examples/fire.pp
U packages/ptc/examples/clip.pp
U packages/ptc/examples/con_info.pp
U packages/ptc/examples/texwarp.pp
U packages/ptc/examples/flower.pp
U packages/ptc/examples/save.pp
D packages/ptc/examples/keybrd2.pp
--- Merging r16019 into '.':
A packages/graph/src/ptcgraph
A packages/graph/src/ptcgraph/ptcgraph.pp
A packages/graph/src/ptcgraph/ptccrt.pp
D packages/graph/src/ptcgraph.pp
--- Merging r16020 into '.':
U packages/graph/Makefile.fpc
C packages/graph/Makefile
C packages/Makefile
C packages/Makefile.fpc
--- Merging r16022 into '.':
G packages/ptc/Makefile.fpc
G packages/ptc/Makefile
--- Merging r16023 into '.':
G packages/hermes/Makefile.fpc
C packages/hermes/Makefile
--- Merging r16024 into '.':
G packages/hermes/src/hermdef.inc
--- Merging r16025 into '.':
G packages/hermes/Makefile.fpc
C packages/hermes/Makefile
--- Merging r16027 into '.':
G packages/hermes/src/i386/x86p_16.as
--- Merging r16028 into '.':
G packages/ptc/Makefile.fpc
C packages/ptc/Makefile
--- Merging r16029 into '.':
C packages/Makefile
C packages/Makefile.fpc
--- Merging r16030 into '.':
G packages/graph/Makefile.fpc
C packages/graph/Makefile
G packages/Makefile
G packages/Makefile.fpc
--- Merging r16034 into '.':
G packages/graph/Makefile.fpc
C packages/graph/Makefile
C packages/Makefile
C packages/Makefile.fpc
Summary of conflicts:
Text conflicts: 14

# revisions: 16017,16018,16019,16020,16022,16023,16024,16025,16027,16028,16029,16030,16034
------------------------------------------------------------------------
r16017 | nickysn | 2010-09-19 22:38:50 +0200 (Sun, 19 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/hermes/Makefile
M /trunk/packages/hermes/Makefile.fpc
D /trunk/packages/hermes/src/clear.inc
D /trunk/packages/hermes/src/convert.inc
M /trunk/packages/hermes/src/d_32.inc
D /trunk/packages/hermes/src/debug.inc
D /trunk/packages/hermes/src/dither.inc
M /trunk/packages/hermes/src/factconv.inc
D /trunk/packages/hermes/src/factory.inc
D /trunk/packages/hermes/src/format.inc
M /trunk/packages/hermes/src/headp.inc
M /trunk/packages/hermes/src/hermconf.inc
M /trunk/packages/hermes/src/hermdef.inc
M /trunk/packages/hermes/src/hermes.pp
A /trunk/packages/hermes/src/hermes_clearer.inc (from /trunk/packages/hermes/src/clear.inc:16015)
A /trunk/packages/hermes/src/hermes_converter.inc (from /trunk/packages/hermes/src/convert.inc:16015)
A /trunk/packages/hermes/src/hermes_debug.inc (from /trunk/packages/hermes/src/debug.inc:16015)
A /trunk/packages/hermes/src/hermes_dither.inc (from /trunk/packages/hermes/src/dither.inc:16015)
A /trunk/packages/hermes/src/hermes_factory.inc (from /trunk/packages/hermes/src/factory.inc:16015)
A /trunk/packages/hermes/src/hermes_format.inc (from /trunk/packages/hermes/src/format.inc:16015)
A /trunk/packages/hermes/src/hermes_list.inc (from /trunk/packages/hermes/src/list.inc:16015)
A /trunk/packages/hermes/src/hermes_palette.inc (from /trunk/packages/hermes/src/palette.inc:16015)
A /trunk/packages/hermes/src/hermes_utility.inc (from /trunk/packages/hermes/src/utility.inc:16015)
M /trunk/packages/hermes/src/i386/headi386.inc
M /trunk/packages/hermes/src/i386/headmmx.inc
M /trunk/packages/hermes/src/i386/mmx_clr.as
M /trunk/packages/hermes/src/i386/mmx_main.as
M /trunk/packages/hermes/src/i386/mmxp2_32.as
M /trunk/packages/hermes/src/i386/mmxp_32.as
M /trunk/packages/hermes/src/i386/x8616lut.as
M /trunk/packages/hermes/src/i386/x86_clr.as
M /trunk/packages/hermes/src/i386/x86_main.as
M /trunk/packages/hermes/src/i386/x86p_16.as
M /trunk/packages/hermes/src/i386/x86p_32.as
M /trunk/packages/hermes/src/i386/x86p_cpy.as
M /trunk/packages/hermes/src/i386/x86p_i8.as
M /trunk/packages/hermes/src/i386/x86p_s32.as
M /trunk/packages/hermes/src/i386/x86pscpy.as
D /trunk/packages/hermes/src/list.inc
D /trunk/packages/hermes/src/malloc.inc
M /trunk/packages/hermes/src/p_16.inc
M /trunk/packages/hermes/src/p_24.inc
M /trunk/packages/hermes/src/p_32.inc
M /trunk/packages/hermes/src/p_clr.inc
M /trunk/packages/hermes/src/p_cnv.inc
M /trunk/packages/hermes/src/p_cpy.inc
M /trunk/packages/hermes/src/p_g.inc
M /trunk/packages/hermes/src/p_ga.inc
M /trunk/packages/hermes/src/p_gac.inc
M /trunk/packages/hermes/src/p_gca.inc
M /trunk/packages/hermes/src/p_gcc.inc
M /trunk/packages/hermes/src/p_i8.inc
M /trunk/packages/hermes/src/p_muhmu.inc
D /trunk/packages/hermes/src/palette.inc
D /trunk/packages/hermes/src/utility.inc

* updated hermes to latest version from trunk
------------------------------------------------------------------------
------------------------------------------------------------------------
r16018 | nickysn | 2010-09-20 00:10:28 +0200 (Mon, 20 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/ptc/Makefile
M /trunk/packages/ptc/Makefile.fpc
D /trunk/packages/ptc/docs/AUTHORS
A /trunk/packages/ptc/docs/AUTHORS.txt (from /trunk/packages/ptc/docs/AUTHORS:16015)
D /trunk/packages/ptc/docs/CHANGES
A /trunk/packages/ptc/docs/CHANGES.txt (from /trunk/packages/ptc/docs/CHANGES:16015)
D /trunk/packages/ptc/docs/INSTALL
A /trunk/packages/ptc/docs/INSTALL.txt (from /trunk/packages/ptc/docs/INSTALL:16015)
D /trunk/packages/ptc/docs/INTRO
A /trunk/packages/ptc/docs/INTRO.txt (from /trunk/packages/ptc/docs/INTRO:16015)
M /trunk/packages/ptc/docs/README.txt
M /trunk/packages/ptc/docs/TODO.txt
M /trunk/packages/ptc/docs/lgpl.txt
A /trunk/packages/ptc/docs/modified_lgpl.txt
M /trunk/packages/ptc/examples/area.pp
M /trunk/packages/ptc/examples/buffer.pp
M /trunk/packages/ptc/examples/clear.pp
M /trunk/packages/ptc/examples/clip.pp
M /trunk/packages/ptc/examples/con_info.pp
M /trunk/packages/ptc/examples/console.pp
M /trunk/packages/ptc/examples/fire.pp
M /trunk/packages/ptc/examples/flower.pp
M /trunk/packages/ptc/examples/hicolor.pp
M /trunk/packages/ptc/examples/image.pp
M /trunk/packages/ptc/examples/keyboard.pp
A /trunk/packages/ptc/examples/keyboard2.pp (from /trunk/packages/ptc/examples/keybrd2.pp:16015)
D /trunk/packages/ptc/examples/keybrd2.pp
M /trunk/packages/ptc/examples/land.pp
M /trunk/packages/ptc/examples/lights.pp
M /trunk/packages/ptc/examples/modes.pp
M /trunk/packages/ptc/examples/mojo.pp
A /trunk/packages/ptc/examples/mouse.pp
M /trunk/packages/ptc/examples/palette.pp
M /trunk/packages/ptc/examples/pixel.pp
M /trunk/packages/ptc/examples/random.pp
M /trunk/packages/ptc/examples/save.pp
M /trunk/packages/ptc/examples/stretch.pp
M /trunk/packages/ptc/examples/texwarp.pp
M /trunk/packages/ptc/examples/timer.pp
M /trunk/packages/ptc/examples/tunnel.pp
M /trunk/packages/ptc/examples/tunnel3d.pp
D /trunk/packages/ptc/src/aread.inc
D /trunk/packages/ptc/src/areai.inc
D /trunk/packages/ptc/src/baseconsoled.inc
D /trunk/packages/ptc/src/baseconsolei.inc
D /trunk/packages/ptc/src/basesurfaced.inc
D /trunk/packages/ptc/src/basesurfacei.inc
M /trunk/packages/ptc/src/c_api/area.inc
M /trunk/packages/ptc/src/c_api/aread.inc
M /trunk/packages/ptc/src/c_api/clear.inc
M /trunk/packages/ptc/src/c_api/cleard.inc
M /trunk/packages/ptc/src/c_api/clipper.inc
M /trunk/packages/ptc/src/c_api/clipperd.inc
M /trunk/packages/ptc/src/c_api/color.inc
M /trunk/packages/ptc/src/c_api/colord.inc
M /trunk/packages/ptc/src/c_api/console.inc
M /trunk/packages/ptc/src/c_api/consoled.inc
M /trunk/packages/ptc/src/c_api/copy.inc
M /trunk/packages/ptc/src/c_api/copyd.inc
M /trunk/packages/ptc/src/c_api/error.inc
M /trunk/packages/ptc/src/c_api/errord.inc
M /trunk/packages/ptc/src/c_api/except.inc
M /trunk/packages/ptc/src/c_api/exceptd.inc
M /trunk/packages/ptc/src/c_api/format.inc
M /trunk/packages/ptc/src/c_api/formatd.inc
M /trunk/packages/ptc/src/c_api/index.inc
M /trunk/packages/ptc/src/c_api/key.inc
M /trunk/packages/ptc/src/c_api/keyd.inc
M /trunk/packages/ptc/src/c_api/mode.inc
M /trunk/packages/ptc/src/c_api/moded.inc
M /trunk/packages/ptc/src/c_api/palette.inc
M /trunk/packages/ptc/src/c_api/paletted.inc
M /trunk/packages/ptc/src/c_api/surface.inc
M /trunk/packages/ptc/src/c_api/surfaced.inc
M /trunk/packages/ptc/src/c_api/timer.inc
M /trunk/packages/ptc/src/c_api/timerd.inc
D /trunk/packages/ptc/src/cleard.inc
D /trunk/packages/ptc/src/cleari.inc
D /trunk/packages/ptc/src/clipperd.inc
D /trunk/packages/ptc/src/clipperi.inc
D /trunk/packages/ptc/src/colord.inc
D /trunk/packages/ptc/src/colori.inc
D /trunk/packages/ptc/src/consoled.inc
D /trunk/packages/ptc/src/consolei.inc
D /trunk/packages/ptc/src/copyd.inc
D /trunk/packages/ptc/src/copyi.inc
A /trunk/packages/ptc/src/core
A /trunk/packages/ptc/src/core/aread.inc (from /trunk/packages/ptc/src/aread.inc:16015)
A /trunk/packages/ptc/src/core/areai.inc (from /trunk/packages/ptc/src/areai.inc:16015)
A /trunk/packages/ptc/src/core/baseconsoled.inc (from /trunk/packages/ptc/src/baseconsoled.inc:16015)
A /trunk/packages/ptc/src/core/baseconsolei.inc (from /trunk/packages/ptc/src/baseconsolei.inc:16015)
A /trunk/packages/ptc/src/core/basesurfaced.inc (from /trunk/packages/ptc/src/basesurfaced.inc:16015)
A /trunk/packages/ptc/src/core/basesurfacei.inc (from /trunk/packages/ptc/src/basesurfacei.inc:16015)
A /trunk/packages/ptc/src/core/cleard.inc (from /trunk/packages/ptc/src/cleard.inc:16015)
A /trunk/packages/ptc/src/core/cleari.inc (from /trunk/packages/ptc/src/cleari.inc:16015)
A /trunk/packages/ptc/src/core/clipperd.inc (from /trunk/packages/ptc/src/clipperd.inc:16015)
A /trunk/packages/ptc/src/core/clipperi.inc (from /trunk/packages/ptc/src/clipperi.inc:16015)
A /trunk/packages/ptc/src/core/colord.inc (from /trunk/packages/ptc/src/colord.inc:16015)
A /trunk/packages/ptc/src/core/colori.inc (from /trunk/packages/ptc/src/colori.inc:16015)
A /trunk/packages/ptc/src/core/consoled.inc (from /trunk/packages/ptc/src/consoled.inc:16015)
A /trunk/packages/ptc/src/core/consolei.inc (from /trunk/packages/ptc/src/consolei.inc:16015)
A /trunk/packages/ptc/src/core/copyd.inc (from /trunk/packages/ptc/src/copyd.inc:16015)
A /trunk/packages/ptc/src/core/copyi.inc (from /trunk/packages/ptc/src/copyi.inc:16015)
A /trunk/packages/ptc/src/core/coreimplementation.inc (from /trunk/packages/ptc/src/coreimplementation.inc:16015)
A /trunk/packages/ptc/src/core/coreinterface.inc (from /trunk/packages/ptc/src/coreinterface.inc:16015)
A /trunk/packages/ptc/src/core/errord.inc (from /trunk/packages/ptc/src/errord.inc:16015)
A /trunk/packages/ptc/src/core/errori.inc (from /trunk/packages/ptc/src/errori.inc:16015)
A /trunk/packages/ptc/src/core/eventd.inc (from /trunk/packages/ptc/src/eventd.inc:16015)
A /trunk/packages/ptc/src/core/eventi.inc (from /trunk/packages/ptc/src/eventi.inc:16015)
A /trunk/packages/ptc/src/core/formatd.inc (from /trunk/packages/ptc/src/formatd.inc:16015)
A /trunk/packages/ptc/src/core/formati.inc (from /trunk/packages/ptc/src/formati.inc:16015)
A /trunk/packages/ptc/src/core/keyeventd.inc (from /trunk/packages/ptc/src/keyeventd.inc:16015)
A /trunk/packages/ptc/src/core/keyeventi.inc (from /trunk/packages/ptc/src/keyeventi.inc:16015)
A /trunk/packages/ptc/src/core/log.inc (from /trunk/packages/ptc/src/log.inc:16015)
A /trunk/packages/ptc/src/core/moded.inc (from /trunk/packages/ptc/src/moded.inc:16015)
A /trunk/packages/ptc/src/core/modei.inc (from /trunk/packages/ptc/src/modei.inc:16015)
A /trunk/packages/ptc/src/core/mouseeventd.inc (from /trunk/packages/ptc/src/mouseeventd.inc:16015)
A /trunk/packages/ptc/src/core/mouseeventi.inc (from /trunk/packages/ptc/src/mouseeventi.inc:16015)
A /trunk/packages/ptc/src/core/paletted.inc (from /trunk/packages/ptc/src/paletted.inc:16015)
A /trunk/packages/ptc/src/core/palettei.inc (from /trunk/packages/ptc/src/palettei.inc:16015)
A /trunk/packages/ptc/src/core/surfaced.inc (from /trunk/packages/ptc/src/surfaced.inc:16015)
A /trunk/packages/ptc/src/core/surfacei.inc (from /trunk/packages/ptc/src/surfacei.inc:16015)
A /trunk/packages/ptc/src/core/timerd.inc (from /trunk/packages/ptc/src/timerd.inc:16015)
A /trunk/packages/ptc/src/core/timeri.inc (from /trunk/packages/ptc/src/timeri.inc:16015)
D /trunk/packages/ptc/src/coreimplementation.inc
D /trunk/packages/ptc/src/coreinterface.inc
A /trunk/packages/ptc/src/dos/base/go32fix.pp
M /trunk/packages/ptc/src/dos/base/kbd.inc
M /trunk/packages/ptc/src/dos/base/kbdd.inc
A /trunk/packages/ptc/src/dos/base/mouse33h.pp
A /trunk/packages/ptc/src/dos/base/moused.inc
A /trunk/packages/ptc/src/dos/base/mousei.inc
M /trunk/packages/ptc/src/dos/cga/cga.pp
A /trunk/packages/ptc/src/dos/cga/cgaconsoled.inc (from /trunk/packages/ptc/src/dos/cga/console.inc:16015)
A /trunk/packages/ptc/src/dos/cga/cgaconsolei.inc (from /trunk/packages/ptc/src/dos/cga/consoled.inc:16015)
D /trunk/packages/ptc/src/dos/cga/console.inc
D /trunk/packages/ptc/src/dos/cga/consoled.inc
D /trunk/packages/ptc/src/dos/fakemode
A /trunk/packages/ptc/src/dos/includes.inc
D /trunk/packages/ptc/src/dos/textfx2/console.inc
D /trunk/packages/ptc/src/dos/textfx2/consoled.inc
M /trunk/packages/ptc/src/dos/textfx2/textfx2.pp
A /trunk/packages/ptc/src/dos/textfx2/textfx2consoled.inc (from /trunk/packages/ptc/src/dos/textfx2/consoled.inc:16015)
A /trunk/packages/ptc/src/dos/textfx2/textfx2consolei.inc (from /trunk/packages/ptc/src/dos/textfx2/console.inc:16015)
M /trunk/packages/ptc/src/dos/timeunit/timeunit.pp
D /trunk/packages/ptc/src/dos/vesa/console.inc
D /trunk/packages/ptc/src/dos/vesa/consoled.inc
M /trunk/packages/ptc/src/dos/vesa/vesa.pp
A /trunk/packages/ptc/src/dos/vesa/vesaconsoled.inc (from /trunk/packages/ptc/src/dos/vesa/consoled.inc:16015)
A /trunk/packages/ptc/src/dos/vesa/vesaconsolei.inc (from /trunk/packages/ptc/src/dos/vesa/console.inc:16015)
A /trunk/packages/ptc/src/dos/vga (from /trunk/packages/ptc/src/dos/fakemode:16015)
D /trunk/packages/ptc/src/dos/vga/console.inc
D /trunk/packages/ptc/src/dos/vga/consoled.inc
M /trunk/packages/ptc/src/dos/vga/vga.pp
A /trunk/packages/ptc/src/dos/vga/vgaconsoled.inc (from /trunk/packages/ptc/src/dos/fakemode/consoled.inc:16015)
A /trunk/packages/ptc/src/dos/vga/vgaconsolei.inc (from /trunk/packages/ptc/src/dos/fakemode/console.inc:16015)
D /trunk/packages/ptc/src/errord.inc
D /trunk/packages/ptc/src/errori.inc
D /trunk/packages/ptc/src/eventd.inc
D /trunk/packages/ptc/src/eventi.inc
D /trunk/packages/ptc/src/formatd.inc
D /trunk/packages/ptc/src/formati.inc
D /trunk/packages/ptc/src/keyd.inc
D /trunk/packages/ptc/src/keyeventd.inc
D /trunk/packages/ptc/src/keyeventi.inc
D /trunk/packages/ptc/src/keyi.inc
D /trunk/packages/ptc/src/log.inc
D /trunk/packages/ptc/src/moded.inc
D /trunk/packages/ptc/src/modei.inc
D /trunk/packages/ptc/src/mouseeventd.inc
D /trunk/packages/ptc/src/mouseeventi.inc
D /trunk/packages/ptc/src/paletted.inc
D /trunk/packages/ptc/src/palettei.inc
M /trunk/packages/ptc/src/ptc.pp
M /trunk/packages/ptc/src/ptcpas.cfg
A /trunk/packages/ptc/src/ptcwrapper
A /trunk/packages/ptc/src/ptcwrapper/ptceventqueue.pp
A /trunk/packages/ptc/src/ptcwrapper/ptcwrapper.pp
D /trunk/packages/ptc/src/surfaced.inc
D /trunk/packages/ptc/src/surfacei.inc
D /trunk/packages/ptc/src/timerd.inc
D /trunk/packages/ptc/src/timeri.inc
M /trunk/packages/ptc/src/tinyptc/tinyptc.pp
M /trunk/packages/ptc/src/win32/base/cursor.inc
A /trunk/packages/ptc/src/win32/base/cursord.inc
A /trunk/packages/ptc/src/win32/base/cursormoded.inc
M /trunk/packages/ptc/src/win32/base/event.inc
M /trunk/packages/ptc/src/win32/base/eventd.inc
M /trunk/packages/ptc/src/win32/base/hook.inc
M /trunk/packages/ptc/src/win32/base/hookd.inc
M /trunk/packages/ptc/src/win32/base/kbd.inc
M /trunk/packages/ptc/src/win32/base/kbdd.inc
M /trunk/packages/ptc/src/win32/base/monitor.inc
M /trunk/packages/ptc/src/win32/base/monitord.inc
M /trunk/packages/ptc/src/win32/base/moused.inc
M /trunk/packages/ptc/src/win32/base/mousei.inc
M /trunk/packages/ptc/src/win32/base/window.inc
M /trunk/packages/ptc/src/win32/base/windowd.inc
M /trunk/packages/ptc/src/win32/directx/check.inc
D /trunk/packages/ptc/src/win32/directx/directdr.pp
D /trunk/packages/ptc/src/win32/directx/directxconsole.inc
M /trunk/packages/ptc/src/win32/directx/directxconsoled.inc
A /trunk/packages/ptc/src/win32/directx/directxconsolei.inc (from /trunk/packages/ptc/src/win32/directx/directxconsole.inc:16015)
M /trunk/packages/ptc/src/win32/directx/display.inc
M /trunk/packages/ptc/src/win32/directx/displayd.inc
M /trunk/packages/ptc/src/win32/directx/hook.inc
M /trunk/packages/ptc/src/win32/directx/hookd.inc
M /trunk/packages/ptc/src/win32/directx/library.inc
M /trunk/packages/ptc/src/win32/directx/libraryd.inc
A /trunk/packages/ptc/src/win32/directx/p_ddraw.pp (from /trunk/packages/ptc/src/win32/directx/directdr.pp:16015)
M /trunk/packages/ptc/src/win32/directx/primary.inc
M /trunk/packages/ptc/src/win32/directx/primaryd.inc
M /trunk/packages/ptc/src/win32/directx/translate.inc
M /trunk/packages/ptc/src/win32/gdi/gdiconsoled.inc
M /trunk/packages/ptc/src/win32/gdi/gdiconsolei.inc
M /trunk/packages/ptc/src/win32/gdi/win32dibd.inc
M /trunk/packages/ptc/src/win32/gdi/win32dibi.inc
M /trunk/packages/ptc/src/wince/base/wincekeyboardd.inc
M /trunk/packages/ptc/src/wince/base/wincekeyboardi.inc
M /trunk/packages/ptc/src/wince/base/wincemoused.inc
M /trunk/packages/ptc/src/wince/base/wincemousei.inc
M /trunk/packages/ptc/src/wince/base/wincewindowd.inc
M /trunk/packages/ptc/src/wince/base/wincewindowi.inc
A /trunk/packages/ptc/src/wince/directx/ddraw.pas
M /trunk/packages/ptc/src/wince/gapi/p_gx.pp
M /trunk/packages/ptc/src/wince/gapi/wincegapiconsoled.inc
M /trunk/packages/ptc/src/wince/gapi/wincegapiconsolei.inc
M /trunk/packages/ptc/src/wince/gdi/wincebitmapinfod.inc
M /trunk/packages/ptc/src/wince/gdi/wincebitmapinfoi.inc
M /trunk/packages/ptc/src/wince/gdi/wincegdiconsoled.inc
M /trunk/packages/ptc/src/wince/gdi/wincegdiconsolei.inc
M /trunk/packages/ptc/src/wince/includes.inc
M /trunk/packages/ptc/src/x11/check.inc
M /trunk/packages/ptc/src/x11/extensions.inc
M /trunk/packages/ptc/src/x11/includes.inc
M /trunk/packages/ptc/src/x11/x11consoled.inc
M /trunk/packages/ptc/src/x11/x11consolei.inc
M /trunk/packages/ptc/src/x11/x11dga1displayd.inc
M /trunk/packages/ptc/src/x11/x11dga1displayi.inc
M /trunk/packages/ptc/src/x11/x11dga2displayd.inc
M /trunk/packages/ptc/src/x11/x11dga2displayi.inc
M /trunk/packages/ptc/src/x11/x11dgadisplayd.inc
M /trunk/packages/ptc/src/x11/x11dgadisplayi.inc
M /trunk/packages/ptc/src/x11/x11displayd.inc
M /trunk/packages/ptc/src/x11/x11displayi.inc
M /trunk/packages/ptc/src/x11/x11imaged.inc
M /trunk/packages/ptc/src/x11/x11imagei.inc
M /trunk/packages/ptc/src/x11/x11modesd.inc
M /trunk/packages/ptc/src/x11/x11modesi.inc
M /trunk/packages/ptc/src/x11/x11windowdisplayd.inc
M /trunk/packages/ptc/src/x11/x11windowdisplayi.inc
M /trunk/packages/ptc/src/x11/xunikey.inc
D /trunk/packages/ptc/tests/convtest.pas
A /trunk/packages/ptc/tests/convtest.pp (from /trunk/packages/ptc/tests/convtest.pas:16015)
A /trunk/packages/ptc/tests/endian.inc (from /trunk/packages/ptc/tests/endian.pas:16015)
D /trunk/packages/ptc/tests/endian.pas
M /trunk/packages/ptc/tests/view.pp

* updated ptc
------------------------------------------------------------------------
------------------------------------------------------------------------
r16019 | nickysn | 2010-09-20 00:44:57 +0200 (Mon, 20 Sep 2010) | 1 line
Changed paths:
A /trunk/packages/graph/src/ptcgraph
A /trunk/packages/graph/src/ptcgraph/ptccrt.pp
A /trunk/packages/graph/src/ptcgraph/ptcgraph.pp (from /trunk/packages/graph/src/ptcgraph.pp:16015)
D /trunk/packages/graph/src/ptcgraph.pp

* updated ptcgraph and added ptccrt
------------------------------------------------------------------------
------------------------------------------------------------------------
r16020 | nickysn | 2010-09-20 00:55:47 +0200 (Mon, 20 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/Makefile
M /trunk/packages/Makefile.fpc
M /trunk/packages/graph/Makefile
M /trunk/packages/graph/Makefile.fpc

* enabled build of ptc and ptcgraph on linux; hermes enabled on all platforms
------------------------------------------------------------------------
------------------------------------------------------------------------
r16022 | nickysn | 2010-09-20 01:29:19 +0200 (Mon, 20 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/ptc/Makefile
M /trunk/packages/ptc/Makefile.fpc

* added missing target unit ptceventqueue to ptc makefiles
------------------------------------------------------------------------
------------------------------------------------------------------------
r16023 | jonas | 2010-09-20 01:35:20 +0200 (Mon, 20 Sep 2010) | 5 lines
Changed paths:
M /trunk/packages/hermes/Makefile
M /trunk/packages/hermes/Makefile.fpc

- disabled assembler loaders for Darwin/i386 because they require a GNU
binutils assembler to be installed (and they don't respect the Darwin/i386
ABI). Also disabled for a few other (seldom used) i386 platforms since
they have to be enabled per platform.

------------------------------------------------------------------------
------------------------------------------------------------------------
r16024 | nickysn | 2010-09-20 02:36:50 +0200 (Mon, 20 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/hermes/src/hermdef.inc

* disabled the i386 loaders by default, unless -dI386_ASSEMBLER compiler option is specified
------------------------------------------------------------------------
------------------------------------------------------------------------
r16025 | nickysn | 2010-09-20 02:44:53 +0200 (Mon, 20 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/hermes/Makefile
M /trunk/packages/hermes/Makefile.fpc

* added -dI386_ASSEMBLER for the platforms, which have the i386 loaders enabled
------------------------------------------------------------------------
------------------------------------------------------------------------
r16027 | nickysn | 2010-09-20 14:51:50 +0200 (Mon, 20 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/hermes/src/i386/x86p_16.as

* fixed path to include file x8616lut.as in hermes i386 loader x86p_16.as (fixes hermes build on i386)
------------------------------------------------------------------------
------------------------------------------------------------------------
r16028 | nickysn | 2010-09-20 14:53:24 +0200 (Mon, 20 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/ptc/Makefile
M /trunk/packages/ptc/Makefile.fpc

* fixed ptc build on win32 and win64
------------------------------------------------------------------------
------------------------------------------------------------------------
r16029 | nickysn | 2010-09-20 14:58:20 +0200 (Mon, 20 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/Makefile
M /trunk/packages/Makefile.fpc

* enabled ptc build on win32 and win64
------------------------------------------------------------------------
------------------------------------------------------------------------
r16030 | nickysn | 2010-09-20 15:45:19 +0200 (Mon, 20 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/Makefile
M /trunk/packages/Makefile.fpc
M /trunk/packages/graph/Makefile
M /trunk/packages/graph/Makefile.fpc

+ enabled build of ptcgraph on win32
------------------------------------------------------------------------
------------------------------------------------------------------------
r16034 | nickysn | 2010-09-21 00:31:30 +0200 (Tue, 21 Sep 2010) | 1 line
Changed paths:
M /trunk/packages/Makefile
M /trunk/packages/Makefile.fpc
M /trunk/packages/graph/Makefile
M /trunk/packages/graph/Makefile.fpc

+ enabled build of ptcgraph on win64
------------------------------------------------------------------------

git-svn-id: branches/fixes_2_4@16390 -

marco 14 years ago
parent
commit
dcb5f32b17
100 changed files with 15389 additions and 13389 deletions
  1. 177 167
      .gitattributes
  2. 9 0
      .gitignore
  3. 227 120
      packages/Makefile
  4. 27 11
      packages/Makefile.fpc
  5. 210 89
      packages/graph/Makefile
  6. 7 2
      packages/graph/Makefile.fpc
  7. 0 537
      packages/graph/src/ptcgraph.pp
  8. 266 0
      packages/graph/src/ptcgraph/ptccrt.pp
  9. 2783 0
      packages/graph/src/ptcgraph/ptcgraph.pp
  10. 81 175
      packages/hermes/Makefile
  11. 57 17
      packages/hermes/Makefile.fpc
  12. 0 223
      packages/hermes/src/clear.inc
  13. 89 81
      packages/hermes/src/d_32.inc
  14. 0 62
      packages/hermes/src/debug.inc
  15. 0 82
      packages/hermes/src/dither.inc
  16. 134 123
      packages/hermes/src/factconv.inc
  17. 0 398
      packages/hermes/src/factory.inc
  18. 0 138
      packages/hermes/src/format.inc
  19. 18 6
      packages/hermes/src/headp.inc
  20. 41 16
      packages/hermes/src/hermconf.inc
  21. 24 27
      packages/hermes/src/hermdef.inc
  22. 232 213
      packages/hermes/src/hermes.pp
  23. 156 0
      packages/hermes/src/hermes_clearer.inc
  24. 350 427
      packages/hermes/src/hermes_converter.inc
  25. 68 0
      packages/hermes/src/hermes_debug.inc
  26. 92 0
      packages/hermes/src/hermes_dither.inc
  27. 377 0
      packages/hermes/src/hermes_factory.inc
  28. 117 0
      packages/hermes/src/hermes_format.inc
  29. 182 0
      packages/hermes/src/hermes_list.inc
  30. 232 0
      packages/hermes/src/hermes_palette.inc
  31. 119 0
      packages/hermes/src/hermes_utility.inc
  32. 81 43
      packages/hermes/src/i386/headi386.inc
  33. 41 11
      packages/hermes/src/i386/headmmx.inc
  34. 23 25
      packages/hermes/src/i386/mmx_clr.as
  35. 9 12
      packages/hermes/src/i386/mmx_main.as
  36. 27 30
      packages/hermes/src/i386/mmxp2_32.as
  37. 14 14
      packages/hermes/src/i386/mmxp_32.as
  38. 2048 2048
      packages/hermes/src/i386/x8616lut.as
  39. 24 24
      packages/hermes/src/i386/x86_clr.as
  40. 11 11
      packages/hermes/src/i386/x86_main.as
  41. 32 32
      packages/hermes/src/i386/x86p_16.as
  42. 49 49
      packages/hermes/src/i386/x86p_32.as
  43. 13 13
      packages/hermes/src/i386/x86p_cpy.as
  44. 16 22
      packages/hermes/src/i386/x86p_i8.as
  45. 6 8
      packages/hermes/src/i386/x86p_s32.as
  46. 5 7
      packages/hermes/src/i386/x86pscpy.as
  47. 0 212
      packages/hermes/src/list.inc
  48. 0 31
      packages/hermes/src/malloc.inc
  49. 499 511
      packages/hermes/src/p_16.inc
  50. 499 523
      packages/hermes/src/p_24.inc
  51. 625 610
      packages/hermes/src/p_32.inc
  52. 92 89
      packages/hermes/src/p_clr.inc
  53. 30 21
      packages/hermes/src/p_cnv.inc
  54. 93 93
      packages/hermes/src/p_cpy.inc
  55. 570 614
      packages/hermes/src/p_g.inc
  56. 348 364
      packages/hermes/src/p_ga.inc
  57. 57 59
      packages/hermes/src/p_gac.inc
  58. 57 59
      packages/hermes/src/p_gca.inc
  59. 57 59
      packages/hermes/src/p_gcc.inc
  60. 240 219
      packages/hermes/src/p_i8.inc
  61. 611 627
      packages/hermes/src/p_muhmu.inc
  62. 0 348
      packages/hermes/src/palette.inc
  63. 0 111
      packages/hermes/src/utility.inc
  64. 206 685
      packages/ptc/Makefile
  65. 15 8
      packages/ptc/Makefile.fpc
  66. 1 1
      packages/ptc/docs/AUTHORS.txt
  67. 0 22
      packages/ptc/docs/CHANGES
  68. 107 0
      packages/ptc/docs/CHANGES.txt
  69. 0 36
      packages/ptc/docs/INSTALL
  70. 29 0
      packages/ptc/docs/INSTALL.txt
  71. 10 10
      packages/ptc/docs/INTRO.txt
  72. 33 19
      packages/ptc/docs/README.txt
  73. 7 6
      packages/ptc/docs/TODO.txt
  74. 25 0
      packages/ptc/docs/modified_lgpl.txt
  75. 40 45
      packages/ptc/examples/area.pp
  76. 36 41
      packages/ptc/examples/buffer.pp
  77. 40 37
      packages/ptc/examples/clear.pp
  78. 42 46
      packages/ptc/examples/clip.pp
  79. 24 27
      packages/ptc/examples/con_info.pp
  80. 107 103
      packages/ptc/examples/console.pp
  81. 88 97
      packages/ptc/examples/fire.pp
  82. 85 97
      packages/ptc/examples/flower.pp
  83. 37 41
      packages/ptc/examples/hicolor.pp
  84. 99 89
      packages/ptc/examples/image.pp
  85. 47 53
      packages/ptc/examples/keyboard.pp
  86. 63 59
      packages/ptc/examples/keyboard2.pp
  87. 199 214
      packages/ptc/examples/land.pp
  88. 81 86
      packages/ptc/examples/lights.pp
  89. 37 41
      packages/ptc/examples/modes.pp
  90. 554 620
      packages/ptc/examples/mojo.pp
  91. 128 0
      packages/ptc/examples/mouse.pp
  92. 90 86
      packages/ptc/examples/palette.pp
  93. 27 33
      packages/ptc/examples/pixel.pp
  94. 35 39
      packages/ptc/examples/random.pp
  95. 120 126
      packages/ptc/examples/save.pp
  96. 70 71
      packages/ptc/examples/stretch.pp
  97. 229 246
      packages/ptc/examples/texwarp.pp
  98. 36 41
      packages/ptc/examples/timer.pp
  99. 80 96
      packages/ptc/examples/tunnel.pp
  100. 310 355
      packages/ptc/examples/tunnel3d.pp

+ 177 - 167
.gitattributes

@@ -2067,7 +2067,8 @@ packages/graph/src/inc/makefile.inc svneol=native#text/plain
 packages/graph/src/inc/modes.inc svneol=native#text/plain
 packages/graph/src/inc/palette.inc svneol=native#text/plain
 packages/graph/src/macosx/graph.pp svneol=native#text/plain
-packages/graph/src/ptcgraph.pp svneol=native#text/x-pascal
+packages/graph/src/ptcgraph/ptccrt.pp svneol=native#text/plain
+packages/graph/src/ptcgraph/ptcgraph.pp svneol=native#text/x-pascal
 packages/graph/src/sdlgraph/sdlgraph.pp svneol=native#text/plain
 packages/graph/src/unix/ggigraph.pp svneol=native#text/plain
 packages/graph/src/unix/graph.pp svneol=native#text/plain
@@ -2725,18 +2726,21 @@ packages/hash/src/uuid.pas svneol=native#text/plain
 packages/hermes/Makefile svneol=native#text/plain
 packages/hermes/Makefile.fpc svneol=native#text/plain
 packages/hermes/fpmake_disabled.pp svneol=native#text/plain
-packages/hermes/src/clear.inc svneol=native#text/plain
-packages/hermes/src/convert.inc svneol=native#text/plain
 packages/hermes/src/d_32.inc svneol=native#text/plain
-packages/hermes/src/debug.inc svneol=native#text/plain
-packages/hermes/src/dither.inc svneol=native#text/plain
 packages/hermes/src/factconv.inc svneol=native#text/plain
-packages/hermes/src/factory.inc svneol=native#text/plain
-packages/hermes/src/format.inc svneol=native#text/plain
 packages/hermes/src/headp.inc svneol=native#text/plain
 packages/hermes/src/hermconf.inc svneol=native#text/plain
 packages/hermes/src/hermdef.inc svneol=native#text/plain
 packages/hermes/src/hermes.pp svneol=native#text/plain
+packages/hermes/src/hermes_clearer.inc svneol=native#text/plain
+packages/hermes/src/hermes_converter.inc svneol=native#text/plain
+packages/hermes/src/hermes_debug.inc svneol=native#text/plain
+packages/hermes/src/hermes_dither.inc svneol=native#text/plain
+packages/hermes/src/hermes_factory.inc svneol=native#text/plain
+packages/hermes/src/hermes_format.inc svneol=native#text/plain
+packages/hermes/src/hermes_list.inc svneol=native#text/plain
+packages/hermes/src/hermes_palette.inc svneol=native#text/plain
+packages/hermes/src/hermes_utility.inc svneol=native#text/plain
 packages/hermes/src/i386/headi386.inc -text
 packages/hermes/src/i386/headmmx.inc -text
 packages/hermes/src/i386/mmx_clr.as -text
@@ -2752,8 +2756,6 @@ packages/hermes/src/i386/x86p_cpy.as -text
 packages/hermes/src/i386/x86p_i8.as -text
 packages/hermes/src/i386/x86p_s32.as -text
 packages/hermes/src/i386/x86pscpy.as -text
-packages/hermes/src/list.inc svneol=native#text/plain
-packages/hermes/src/malloc.inc svneol=native#text/plain
 packages/hermes/src/p_16.inc svneol=native#text/plain
 packages/hermes/src/p_24.inc svneol=native#text/plain
 packages/hermes/src/p_32.inc svneol=native#text/plain
@@ -2767,8 +2769,6 @@ packages/hermes/src/p_gca.inc svneol=native#text/plain
 packages/hermes/src/p_gcc.inc svneol=native#text/plain
 packages/hermes/src/p_i8.inc svneol=native#text/plain
 packages/hermes/src/p_muhmu.inc svneol=native#text/plain
-packages/hermes/src/palette.inc svneol=native#text/plain
-packages/hermes/src/utility.inc svneol=native#text/plain
 packages/httpd13/Makefile svneol=native#text/plain
 packages/httpd13/Makefile.fpc svneol=native#text/plain
 packages/httpd13/fpmake.pp svneol=native#text/plain
@@ -4440,13 +4440,14 @@ packages/proj4/fpmake.pp svneol=native#text/plain
 packages/proj4/src/proj.pas svneol=native#text/plain
 packages/ptc/Makefile svneol=native#text/plain
 packages/ptc/Makefile.fpc svneol=native#text/plain
-packages/ptc/docs/AUTHORS -text
-packages/ptc/docs/CHANGES -text
-packages/ptc/docs/INSTALL -text
-packages/ptc/docs/INTRO -text
+packages/ptc/docs/AUTHORS.txt svneol=native#text/plain
+packages/ptc/docs/CHANGES.txt svneol=native#text/plain
+packages/ptc/docs/INSTALL.txt svneol=native#text/plain
+packages/ptc/docs/INTRO.txt svneol=native#text/plain
 packages/ptc/docs/README.txt svneol=native#text/plain
 packages/ptc/docs/TODO.txt svneol=native#text/plain
-packages/ptc/docs/lgpl.txt -text
+packages/ptc/docs/lgpl.txt svneol=native#text/plain
+packages/ptc/docs/modified_lgpl.txt svneol=native#text/plain
 packages/ptc/examples/Makefile svneol=native#text/plain
 packages/ptc/examples/Makefile.fpc svneol=native#text/plain
 packages/ptc/examples/area.pp svneol=native#text/plain
@@ -4461,12 +4462,13 @@ packages/ptc/examples/hicolor.pp svneol=native#text/plain
 packages/ptc/examples/image.pp svneol=native#text/plain
 packages/ptc/examples/image.tga -text
 packages/ptc/examples/keyboard.pp svneol=native#text/plain
-packages/ptc/examples/keybrd2.pp svneol=native#text/plain
+packages/ptc/examples/keyboard2.pp svneol=native#text/plain
 packages/ptc/examples/land.pp svneol=native#text/plain
 packages/ptc/examples/lights.pp svneol=native#text/plain
 packages/ptc/examples/modes.pp svneol=native#text/plain
 packages/ptc/examples/mojo.pp svneol=native#text/plain
 packages/ptc/examples/mojo.raw -text svneol=unset#raw/binary
+packages/ptc/examples/mouse.pp svneol=native#text/plain
 packages/ptc/examples/palette.pp svneol=native#text/plain
 packages/ptc/examples/pixel.pp svneol=native#text/plain
 packages/ptc/examples/random.pp svneol=native#text/plain
@@ -4479,161 +4481,169 @@ packages/ptc/examples/tunnel.pp svneol=native#text/plain
 packages/ptc/examples/tunnel3d.pp svneol=native#text/plain
 packages/ptc/examples/tunnel3d.raw -text svneol=unset#raw/binary
 packages/ptc/fpmake.pp svneol=native#text/plain
-packages/ptc/src/aread.inc svneol=native#text/x-pascal
-packages/ptc/src/areai.inc svneol=native#text/x-pascal
-packages/ptc/src/baseconsoled.inc svneol=native#text/x-pascal
-packages/ptc/src/baseconsolei.inc svneol=native#text/x-pascal
-packages/ptc/src/basesurfaced.inc svneol=native#text/x-pascal
-packages/ptc/src/basesurfacei.inc svneol=native#text/x-pascal
-packages/ptc/src/c_api/area.inc -text
-packages/ptc/src/c_api/aread.inc -text
-packages/ptc/src/c_api/clear.inc -text
-packages/ptc/src/c_api/cleard.inc -text
-packages/ptc/src/c_api/clipper.inc -text
-packages/ptc/src/c_api/clipperd.inc -text
-packages/ptc/src/c_api/color.inc -text
-packages/ptc/src/c_api/colord.inc -text
-packages/ptc/src/c_api/console.inc -text
-packages/ptc/src/c_api/consoled.inc -text
-packages/ptc/src/c_api/copy.inc -text
-packages/ptc/src/c_api/copyd.inc -text
-packages/ptc/src/c_api/error.inc -text
-packages/ptc/src/c_api/errord.inc -text
-packages/ptc/src/c_api/except.inc -text
-packages/ptc/src/c_api/exceptd.inc -text
-packages/ptc/src/c_api/format.inc -text
-packages/ptc/src/c_api/formatd.inc -text
-packages/ptc/src/c_api/index.inc -text
-packages/ptc/src/c_api/key.inc -text
-packages/ptc/src/c_api/keyd.inc -text
-packages/ptc/src/c_api/mode.inc -text
-packages/ptc/src/c_api/moded.inc -text
-packages/ptc/src/c_api/palette.inc -text
-packages/ptc/src/c_api/paletted.inc -text
-packages/ptc/src/c_api/surface.inc -text
-packages/ptc/src/c_api/surfaced.inc -text
-packages/ptc/src/c_api/timer.inc -text
-packages/ptc/src/c_api/timerd.inc -text
-packages/ptc/src/cleard.inc svneol=native#text/x-pascal
-packages/ptc/src/cleari.inc svneol=native#text/x-pascal
-packages/ptc/src/clipperd.inc svneol=native#text/x-pascal
-packages/ptc/src/clipperi.inc svneol=native#text/x-pascal
-packages/ptc/src/colord.inc svneol=native#text/x-pascal
-packages/ptc/src/colori.inc svneol=native#text/x-pascal
-packages/ptc/src/consoled.inc svneol=native#text/x-pascal
-packages/ptc/src/consolei.inc svneol=native#text/x-pascal
-packages/ptc/src/copyd.inc svneol=native#text/x-pascal
-packages/ptc/src/copyi.inc svneol=native#text/x-pascal
-packages/ptc/src/coreimplementation.inc svneol=native#text/x-pascal
-packages/ptc/src/coreinterface.inc svneol=native#text/x-pascal
-packages/ptc/src/dos/base/kbd.inc -text
-packages/ptc/src/dos/base/kbdd.inc -text
-packages/ptc/src/dos/cga/cga.pp -text
-packages/ptc/src/dos/cga/console.inc -text
-packages/ptc/src/dos/cga/consoled.inc -text
-packages/ptc/src/dos/fakemode/console.inc -text
-packages/ptc/src/dos/fakemode/consoled.inc -text
-packages/ptc/src/dos/fakemode/vga.pp -text
-packages/ptc/src/dos/textfx2/console.inc -text
-packages/ptc/src/dos/textfx2/consoled.inc -text
-packages/ptc/src/dos/textfx2/textfx2.pp -text
-packages/ptc/src/dos/timeunit/timeunit.pp -text
-packages/ptc/src/dos/vesa/console.inc -text
-packages/ptc/src/dos/vesa/consoled.inc -text
-packages/ptc/src/dos/vesa/vesa.pp -text
-packages/ptc/src/errord.inc svneol=native#text/x-pascal
-packages/ptc/src/errori.inc svneol=native#text/x-pascal
-packages/ptc/src/eventd.inc svneol=native#text/x-pascal
-packages/ptc/src/eventi.inc svneol=native#text/x-pascal
-packages/ptc/src/formatd.inc svneol=native#text/x-pascal
-packages/ptc/src/formati.inc svneol=native#text/x-pascal
-packages/ptc/src/keyd.inc svneol=native#text/x-pascal
-packages/ptc/src/keyeventd.inc svneol=native#text/x-pascal
-packages/ptc/src/keyeventi.inc svneol=native#text/x-pascal
-packages/ptc/src/keyi.inc svneol=native#text/x-pascal
-packages/ptc/src/log.inc svneol=native#text/x-pascal
-packages/ptc/src/moded.inc svneol=native#text/x-pascal
-packages/ptc/src/modei.inc svneol=native#text/x-pascal
-packages/ptc/src/mouseeventd.inc svneol=native#text/x-pascal
-packages/ptc/src/mouseeventi.inc svneol=native#text/x-pascal
-packages/ptc/src/paletted.inc svneol=native#text/x-pascal
-packages/ptc/src/palettei.inc svneol=native#text/x-pascal
+packages/ptc/src/c_api/area.inc svneol=native#text/plain
+packages/ptc/src/c_api/aread.inc svneol=native#text/plain
+packages/ptc/src/c_api/clear.inc svneol=native#text/plain
+packages/ptc/src/c_api/cleard.inc svneol=native#text/plain
+packages/ptc/src/c_api/clipper.inc svneol=native#text/plain
+packages/ptc/src/c_api/clipperd.inc svneol=native#text/plain
+packages/ptc/src/c_api/color.inc svneol=native#text/plain
+packages/ptc/src/c_api/colord.inc svneol=native#text/plain
+packages/ptc/src/c_api/console.inc svneol=native#text/plain
+packages/ptc/src/c_api/consoled.inc svneol=native#text/plain
+packages/ptc/src/c_api/copy.inc svneol=native#text/plain
+packages/ptc/src/c_api/copyd.inc svneol=native#text/plain
+packages/ptc/src/c_api/error.inc svneol=native#text/plain
+packages/ptc/src/c_api/errord.inc svneol=native#text/plain
+packages/ptc/src/c_api/except.inc svneol=native#text/plain
+packages/ptc/src/c_api/exceptd.inc svneol=native#text/plain
+packages/ptc/src/c_api/format.inc svneol=native#text/plain
+packages/ptc/src/c_api/formatd.inc svneol=native#text/plain
+packages/ptc/src/c_api/index.inc svneol=native#text/plain
+packages/ptc/src/c_api/key.inc svneol=native#text/plain
+packages/ptc/src/c_api/keyd.inc svneol=native#text/plain
+packages/ptc/src/c_api/mode.inc svneol=native#text/plain
+packages/ptc/src/c_api/moded.inc svneol=native#text/plain
+packages/ptc/src/c_api/palette.inc svneol=native#text/plain
+packages/ptc/src/c_api/paletted.inc svneol=native#text/plain
+packages/ptc/src/c_api/surface.inc svneol=native#text/plain
+packages/ptc/src/c_api/surfaced.inc svneol=native#text/plain
+packages/ptc/src/c_api/timer.inc svneol=native#text/plain
+packages/ptc/src/c_api/timerd.inc svneol=native#text/plain
+packages/ptc/src/core/aread.inc svneol=native#text/plain
+packages/ptc/src/core/areai.inc svneol=native#text/plain
+packages/ptc/src/core/baseconsoled.inc svneol=native#text/plain
+packages/ptc/src/core/baseconsolei.inc svneol=native#text/plain
+packages/ptc/src/core/basesurfaced.inc svneol=native#text/plain
+packages/ptc/src/core/basesurfacei.inc svneol=native#text/plain
+packages/ptc/src/core/cleard.inc svneol=native#text/plain
+packages/ptc/src/core/cleari.inc svneol=native#text/plain
+packages/ptc/src/core/clipperd.inc svneol=native#text/plain
+packages/ptc/src/core/clipperi.inc svneol=native#text/plain
+packages/ptc/src/core/colord.inc svneol=native#text/plain
+packages/ptc/src/core/colori.inc svneol=native#text/plain
+packages/ptc/src/core/consoled.inc svneol=native#text/plain
+packages/ptc/src/core/consolei.inc svneol=native#text/plain
+packages/ptc/src/core/copyd.inc svneol=native#text/plain
+packages/ptc/src/core/copyi.inc svneol=native#text/plain
+packages/ptc/src/core/coreimplementation.inc svneol=native#text/plain
+packages/ptc/src/core/coreinterface.inc svneol=native#text/plain
+packages/ptc/src/core/errord.inc svneol=native#text/plain
+packages/ptc/src/core/errori.inc svneol=native#text/plain
+packages/ptc/src/core/eventd.inc svneol=native#text/plain
+packages/ptc/src/core/eventi.inc svneol=native#text/plain
+packages/ptc/src/core/formatd.inc svneol=native#text/plain
+packages/ptc/src/core/formati.inc svneol=native#text/plain
+packages/ptc/src/core/keyeventd.inc svneol=native#text/plain
+packages/ptc/src/core/keyeventi.inc svneol=native#text/plain
+packages/ptc/src/core/log.inc svneol=native#text/plain
+packages/ptc/src/core/moded.inc svneol=native#text/plain
+packages/ptc/src/core/modei.inc svneol=native#text/plain
+packages/ptc/src/core/mouseeventd.inc svneol=native#text/plain
+packages/ptc/src/core/mouseeventi.inc svneol=native#text/plain
+packages/ptc/src/core/paletted.inc svneol=native#text/plain
+packages/ptc/src/core/palettei.inc svneol=native#text/plain
+packages/ptc/src/core/surfaced.inc svneol=native#text/plain
+packages/ptc/src/core/surfacei.inc svneol=native#text/plain
+packages/ptc/src/core/timerd.inc svneol=native#text/plain
+packages/ptc/src/core/timeri.inc svneol=native#text/plain
+packages/ptc/src/dos/base/go32fix.pp svneol=native#text/plain
+packages/ptc/src/dos/base/kbd.inc svneol=native#text/plain
+packages/ptc/src/dos/base/kbdd.inc svneol=native#text/plain
+packages/ptc/src/dos/base/mouse33h.pp svneol=native#text/plain
+packages/ptc/src/dos/base/moused.inc svneol=native#text/plain
+packages/ptc/src/dos/base/mousei.inc svneol=native#text/plain
+packages/ptc/src/dos/cga/cga.pp svneol=native#text/plain
+packages/ptc/src/dos/cga/cgaconsoled.inc svneol=native#text/plain
+packages/ptc/src/dos/cga/cgaconsolei.inc svneol=native#text/plain
+packages/ptc/src/dos/includes.inc svneol=native#text/plain
+packages/ptc/src/dos/textfx2/textfx2.pp svneol=native#text/plain
+packages/ptc/src/dos/textfx2/textfx2consoled.inc svneol=native#text/plain
+packages/ptc/src/dos/textfx2/textfx2consolei.inc svneol=native#text/plain
+packages/ptc/src/dos/timeunit/timeunit.pp svneol=native#text/plain
+packages/ptc/src/dos/vesa/vesa.pp svneol=native#text/plain
+packages/ptc/src/dos/vesa/vesaconsoled.inc svneol=native#text/plain
+packages/ptc/src/dos/vesa/vesaconsolei.inc svneol=native#text/plain
+packages/ptc/src/dos/vga/vga.pp svneol=native#text/plain
+packages/ptc/src/dos/vga/vgaconsoled.inc svneol=native#text/plain
+packages/ptc/src/dos/vga/vgaconsolei.inc svneol=native#text/plain
 packages/ptc/src/ptc.pp svneol=native#text/plain
 packages/ptc/src/ptcpas.cfg svneol=native#text/plain
-packages/ptc/src/surfaced.inc svneol=native#text/x-pascal
-packages/ptc/src/surfacei.inc svneol=native#text/x-pascal
-packages/ptc/src/timerd.inc svneol=native#text/x-pascal
-packages/ptc/src/timeri.inc svneol=native#text/x-pascal
-packages/ptc/src/tinyptc/tinyptc.pp -text
-packages/ptc/src/win32/base/cursor.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/base/event.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/base/eventd.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/base/hook.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/base/hookd.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/base/kbd.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/base/kbdd.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/base/monitor.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/base/monitord.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/base/moused.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/base/mousei.inc svneol=native#text/x-pascal
+packages/ptc/src/ptcwrapper/ptceventqueue.pp svneol=native#text/plain
+packages/ptc/src/ptcwrapper/ptcwrapper.pp svneol=native#text/plain
+packages/ptc/src/tinyptc/tinyptc.pp svneol=native#text/plain
+packages/ptc/src/win32/base/cursor.inc svneol=native#text/plain
+packages/ptc/src/win32/base/cursord.inc svneol=native#text/plain
+packages/ptc/src/win32/base/cursormoded.inc svneol=native#text/plain
+packages/ptc/src/win32/base/event.inc svneol=native#text/plain
+packages/ptc/src/win32/base/eventd.inc svneol=native#text/plain
+packages/ptc/src/win32/base/hook.inc svneol=native#text/plain
+packages/ptc/src/win32/base/hookd.inc svneol=native#text/plain
+packages/ptc/src/win32/base/kbd.inc svneol=native#text/plain
+packages/ptc/src/win32/base/kbdd.inc svneol=native#text/plain
+packages/ptc/src/win32/base/monitor.inc svneol=native#text/plain
+packages/ptc/src/win32/base/monitord.inc svneol=native#text/plain
+packages/ptc/src/win32/base/moused.inc svneol=native#text/plain
+packages/ptc/src/win32/base/mousei.inc svneol=native#text/plain
 packages/ptc/src/win32/base/ptcres.rc -text
 packages/ptc/src/win32/base/ptcres.res -text
-packages/ptc/src/win32/base/window.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/base/windowd.inc svneol=native#text/x-pascal
+packages/ptc/src/win32/base/window.inc svneol=native#text/plain
+packages/ptc/src/win32/base/windowd.inc svneol=native#text/plain
 packages/ptc/src/win32/base/windows.ico -text
-packages/ptc/src/win32/directx/check.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/directx/directdr.pp -text
-packages/ptc/src/win32/directx/directxconsole.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/directx/directxconsoled.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/directx/display.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/directx/displayd.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/directx/hook.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/directx/hookd.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/directx/library.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/directx/libraryd.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/directx/primary.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/directx/primaryd.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/directx/translate.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/gdi/gdiconsoled.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/gdi/gdiconsolei.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/gdi/win32dibd.inc svneol=native#text/x-pascal
-packages/ptc/src/win32/gdi/win32dibi.inc svneol=native#text/x-pascal
-packages/ptc/src/wince/base/wincekeyboardd.inc svneol=native#text/x-pascal
-packages/ptc/src/wince/base/wincekeyboardi.inc svneol=native#text/x-pascal
-packages/ptc/src/wince/base/wincemoused.inc svneol=native#text/x-pascal
-packages/ptc/src/wince/base/wincemousei.inc svneol=native#text/x-pascal
-packages/ptc/src/wince/base/wincewindowd.inc svneol=native#text/x-pascal
-packages/ptc/src/wince/base/wincewindowi.inc svneol=native#text/x-pascal
-packages/ptc/src/wince/gapi/p_gx.pp svneol=native#text/x-pascal
-packages/ptc/src/wince/gapi/wincegapiconsoled.inc svneol=native#text/x-pascal
-packages/ptc/src/wince/gapi/wincegapiconsolei.inc svneol=native#text/x-pascal
-packages/ptc/src/wince/gdi/wincebitmapinfod.inc svneol=native#text/x-pascal
-packages/ptc/src/wince/gdi/wincebitmapinfoi.inc svneol=native#text/x-pascal
-packages/ptc/src/wince/gdi/wincegdiconsoled.inc svneol=native#text/x-pascal
-packages/ptc/src/wince/gdi/wincegdiconsolei.inc svneol=native#text/x-pascal
-packages/ptc/src/wince/includes.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/check.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/extensions.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/includes.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/x11consoled.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/x11consolei.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/x11dga1displayd.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/x11dga1displayi.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/x11dga2displayd.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/x11dga2displayi.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/x11dgadisplayd.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/x11dgadisplayi.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/x11displayd.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/x11displayi.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/x11imaged.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/x11imagei.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/x11modesd.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/x11modesi.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/x11windowdisplayd.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/x11windowdisplayi.inc svneol=native#text/x-pascal
-packages/ptc/src/x11/xunikey.inc svneol=native#text/x-pascal
-packages/ptc/tests/convtest.pas svneol=native#text/plain
-packages/ptc/tests/endian.pas svneol=native#text/plain
+packages/ptc/src/win32/directx/check.inc svneol=native#text/plain
+packages/ptc/src/win32/directx/directxconsoled.inc svneol=native#text/plain
+packages/ptc/src/win32/directx/directxconsolei.inc svneol=native#text/plain
+packages/ptc/src/win32/directx/display.inc svneol=native#text/plain
+packages/ptc/src/win32/directx/displayd.inc svneol=native#text/plain
+packages/ptc/src/win32/directx/hook.inc svneol=native#text/plain
+packages/ptc/src/win32/directx/hookd.inc svneol=native#text/plain
+packages/ptc/src/win32/directx/library.inc svneol=native#text/plain
+packages/ptc/src/win32/directx/libraryd.inc svneol=native#text/plain
+packages/ptc/src/win32/directx/p_ddraw.pp svneol=native#text/plain
+packages/ptc/src/win32/directx/primary.inc svneol=native#text/plain
+packages/ptc/src/win32/directx/primaryd.inc svneol=native#text/plain
+packages/ptc/src/win32/directx/translate.inc svneol=native#text/plain
+packages/ptc/src/win32/gdi/gdiconsoled.inc svneol=native#text/plain
+packages/ptc/src/win32/gdi/gdiconsolei.inc svneol=native#text/plain
+packages/ptc/src/win32/gdi/win32dibd.inc svneol=native#text/plain
+packages/ptc/src/win32/gdi/win32dibi.inc svneol=native#text/plain
+packages/ptc/src/wince/base/wincekeyboardd.inc svneol=native#text/plain
+packages/ptc/src/wince/base/wincekeyboardi.inc svneol=native#text/plain
+packages/ptc/src/wince/base/wincemoused.inc svneol=native#text/plain
+packages/ptc/src/wince/base/wincemousei.inc svneol=native#text/plain
+packages/ptc/src/wince/base/wincewindowd.inc svneol=native#text/plain
+packages/ptc/src/wince/base/wincewindowi.inc svneol=native#text/plain
+packages/ptc/src/wince/directx/ddraw.pas svneol=native#text/plain
+packages/ptc/src/wince/gapi/p_gx.pp svneol=native#text/plain
+packages/ptc/src/wince/gapi/wincegapiconsoled.inc svneol=native#text/plain
+packages/ptc/src/wince/gapi/wincegapiconsolei.inc svneol=native#text/plain
+packages/ptc/src/wince/gdi/wincebitmapinfod.inc svneol=native#text/plain
+packages/ptc/src/wince/gdi/wincebitmapinfoi.inc svneol=native#text/plain
+packages/ptc/src/wince/gdi/wincegdiconsoled.inc svneol=native#text/plain
+packages/ptc/src/wince/gdi/wincegdiconsolei.inc svneol=native#text/plain
+packages/ptc/src/wince/includes.inc svneol=native#text/plain
+packages/ptc/src/x11/check.inc svneol=native#text/plain
+packages/ptc/src/x11/extensions.inc svneol=native#text/plain
+packages/ptc/src/x11/includes.inc svneol=native#text/plain
+packages/ptc/src/x11/x11consoled.inc svneol=native#text/plain
+packages/ptc/src/x11/x11consolei.inc svneol=native#text/plain
+packages/ptc/src/x11/x11dga1displayd.inc svneol=native#text/plain
+packages/ptc/src/x11/x11dga1displayi.inc svneol=native#text/plain
+packages/ptc/src/x11/x11dga2displayd.inc svneol=native#text/plain
+packages/ptc/src/x11/x11dga2displayi.inc svneol=native#text/plain
+packages/ptc/src/x11/x11dgadisplayd.inc svneol=native#text/plain
+packages/ptc/src/x11/x11dgadisplayi.inc svneol=native#text/plain
+packages/ptc/src/x11/x11displayd.inc svneol=native#text/plain
+packages/ptc/src/x11/x11displayi.inc svneol=native#text/plain
+packages/ptc/src/x11/x11imaged.inc svneol=native#text/plain
+packages/ptc/src/x11/x11imagei.inc svneol=native#text/plain
+packages/ptc/src/x11/x11modesd.inc svneol=native#text/plain
+packages/ptc/src/x11/x11modesi.inc svneol=native#text/plain
+packages/ptc/src/x11/x11windowdisplayd.inc svneol=native#text/plain
+packages/ptc/src/x11/x11windowdisplayi.inc svneol=native#text/plain
+packages/ptc/src/x11/xunikey.inc svneol=native#text/plain
+packages/ptc/tests/convtest.pp svneol=native#text/plain
+packages/ptc/tests/endian.inc svneol=native#text/plain
 packages/ptc/tests/view.pp svneol=native#text/plain
 packages/pthreads/Makefile svneol=native#text/plain
 packages/pthreads/Makefile.fpc svneol=native#text/plain

+ 9 - 0
.gitignore

@@ -652,6 +652,15 @@ packages/paszlib/*.s
 packages/paszlib/.gdbinit
 packages/paszlib/fpcmade.*
 packages/paszlib/units
+packages/ptc/src/dos/vga/*.bak
+packages/ptc/src/dos/vga/*.exe
+packages/ptc/src/dos/vga/*.o
+packages/ptc/src/dos/vga/*.ppu
+packages/ptc/src/dos/vga/*.s
+packages/ptc/src/dos/vga/Package.fpc
+packages/ptc/src/dos/vga/build-stamp.*
+packages/ptc/src/dos/vga/fpcmade.*
+packages/ptc/src/dos/vga/units
 packages/units
 rtl/*.bak
 rtl/*.exe

File diff suppressed because it is too large
+ 227 - 120
packages/Makefile


+ 27 - 11
packages/Makefile.fpc

@@ -4,8 +4,8 @@
 #
 
 [target]
-dirs=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic bzip2
-dirs_linux_i386=libc unixutil graph pxlib
+dirs=hash pasjpeg paszlib fpmkunit fcl-xml fcl-base fcl-db fcl-image fcl-net fcl-passrc fcl-registry fcl-fpcunit fcl-json  fcl-process unzip regexpr chm fcl-res libgd symbolic bzip2 hermes
+dirs_linux_i386=libc unixutil graph pxlib 
 dirs_i386_linux=graph
 dirs_x86_64_linux=graph
 dirs_powerpc_linux=graph
@@ -44,12 +44,14 @@ dirs_openbsd=fv fcl-web fastcgi fcl-async ibase mysql ncurses zlib oracle odbc
 dirs_linux=fv fcl-web fastcgi fcl-async ibase mysql ncurses unzip zlib oracle dbus odbc postgres sqlite pthreads imagemagick \
                gdbint libpng x11 uuid ldap modplug dts mad  gdbm tcl syslog libcurl opengl cairo gtk1 gtk2 librsvg \
                a52 bfd aspell svgalib newt cdrom users  iconvenc libxml proj4 fcl-extra \
-               imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 pxlib numlib gmp
+               imlib utmp  fpgtk openal lua oggvorbis xforms fftw pcap ggi sdl openssl gnome1 httpd13 httpd20 httpd22 \
+               pxlib numlib gmp ptc
 dirs_win32=fv winunits-base winunits-jedi fcl-web fastcgi ibase mysql zlib oracle odbc postgres sqlite imagemagick \
-               gdbint libpng mad tcl opengl gtk1 gtk2 librsvg a52 cdrom fpgtk openal fftw lua fcl-extra \
-               oggvorbis sdl openssl graph pcap httpd13 httpd20 httpd22 pxlib numlib  cairo libxml gmp opencl
+               gdbint libpng mad tcl opengl gtk1 gtk2 librsvg a52 cdrom fpgtk openal fftw lua fcl-extra  \
+               oggvorbis sdl openssl graph pcap httpd13 httpd20 httpd22 pxlib numlib winceunits cairo libxml \
+               gmp opencl ptc
 dirs_win64=fv winunits-base winunits-jedi fcl-web fastcgi ibase mysql zlib oracle odbc postgres sqlite imagemagick \
-                tcl opengl gtk1 fpgtk fftw sdl openssl cdrom httpd13 httpd20 httpd22 numlib fcl-extra opencl
+               tcl opengl gtk1 fpgtk fftw sdl openssl cdrom httpd13 httpd20 httpd22 numlib fcl-extra opencl ptc graph 
 dirs_wince=winceunits httpd22 fcl-web fastcgi tcl fftw unzip zlib sqlite mysql ibase postgres oracle odbc sdl openssl oggvorbis numlib
 dirs_os2=fv zlib libpng x11 tcl fpgtk rexx os2units gtk1 imlib
 dirs_emx=fv zlib libpng x11 tcl fpgtk rexx os2units gtk1 imlib
@@ -237,6 +239,14 @@ graph_debug: sdl_debug
 graph_release: sdl_release
 endif
 
+ifneq ($(findstring $(OS_TARGET),linux win32 win64),)
+graph_all: ptc_all
+graph_shared: ptc_shared
+graph_smart: ptc_smart
+graph_debug: ptc_debug
+graph_release: ptc_release
+endif
+
 ifneq ($(findstring $(OS_TARGET),linux darwin freebsd openbsd netbsd solaris),)
 gtk1_all: x11_all opengl_all
 gtk1_debug: x11_debug opengl_debug
@@ -301,6 +311,12 @@ opengl_shared: x11_shared
 opengl_smart: x11_smart
 opengl_debug: x11_debug
 opengl_release: x11_release
+
+ptc_all: x11_all
+ptc_shared: x11_shared
+ptc_smart: x11_smart
+ptc_debug: x11_debug
+ptc_release: x11_release
 endif
 
 tcl_all: fcl-base_all
@@ -340,11 +356,11 @@ gnome1_smart: gtk1_smart imlib_smart
 gnome1_debug: gtk1_debug imlib_debug
 gnome1_release: gtk1_release imlib_release
 
-ptc_all: hermes_all x11_all
-ptc_shared: hermes_shared x11_shared
-ptc_smart: hermes_smart x11_smart
-ptc_debug: hermes_debug x11_debug
-ptc_release: hermes_release x11_release
+ptc_all: hermes_all fcl-base_all
+ptc_shared: hermes_shared fcl-base_shared
+ptc_smart: hermes_smart fcl-base_smart
+ptc_debug: hermes_debug fcl-base_debug
+ptc_release: hermes_release fcl-base_release
 
 librsvg_all: gtk2_all
 librsvg_shared: gtk2_shared

+ 210 - 89
packages/graph/Makefile

@@ -1,5 +1,5 @@
 #
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2010/08/25]
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2010/11/19]
 #
 default: all
 MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-solaris x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded mipsel-linux
@@ -289,13 +289,13 @@ GRAPHUNIT_DIR=src/unix
 UNIXINCDEPS=$(UNIXINC)/graph16.inc
 endif
 ifeq ($(FULL_TARGET),i386-linux)
-override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT) sdlgraph
+override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT) ptcgraph ptccrt sdlgraph
 endif
 ifeq ($(FULL_TARGET),i386-go32v2)
 override TARGET_UNITS+=graph
 endif
 ifeq ($(FULL_TARGET),i386-win32)
-override TARGET_UNITS+=graph wincrt winmouse sdlgraph
+override TARGET_UNITS+=graph wincrt winmouse sdlgraph ptcgraph ptccrt
 endif
 ifeq ($(FULL_TARGET),i386-freebsd)
 override TARGET_UNITS+=graph $(GGIGRAPH_UNIT) sdlgraph
@@ -304,7 +304,7 @@ ifeq ($(FULL_TARGET),i386-darwin)
 override TARGET_UNITS+=sdlgraph
 endif
 ifeq ($(FULL_TARGET),m68k-linux)
-override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT)
+override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT) ptcgraph ptccrt
 endif
 ifeq ($(FULL_TARGET),m68k-freebsd)
 override TARGET_UNITS+=graph $(GGIGRAPH_UNIT)
@@ -313,7 +313,7 @@ ifeq ($(FULL_TARGET),m68k-amiga)
 override TARGET_UNITS+=graph
 endif
 ifeq ($(FULL_TARGET),powerpc-linux)
-override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT) sdlgraph
+override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT) ptcgraph ptccrt sdlgraph
 endif
 ifeq ($(FULL_TARGET),powerpc-amiga)
 override TARGET_UNITS+=graph
@@ -322,25 +322,28 @@ ifeq ($(FULL_TARGET),powerpc-darwin)
 override TARGET_UNITS+=sdlgraph
 endif
 ifeq ($(FULL_TARGET),sparc-linux)
-override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT)
+override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT) ptcgraph ptccrt
 endif
 ifeq ($(FULL_TARGET),x86_64-linux)
-override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT)
+override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT) ptcgraph ptccrt
 endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
 override TARGET_UNITS+=graph $(GGIGRAPH_UNIT)
 endif
+ifeq ($(FULL_TARGET),x86_64-win64)
+override TARGET_UNITS+=ptcgraph ptccrt
+endif
 ifeq ($(FULL_TARGET),arm-linux)
-override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT)
+override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT) ptcgraph ptccrt
 endif
 ifeq ($(FULL_TARGET),powerpc64-linux)
-override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT)
+override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT) ptcgraph ptccrt
 endif
 ifeq ($(FULL_TARGET),armeb-linux)
-override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT)
+override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT) ptcgraph ptccrt
 endif
 ifeq ($(FULL_TARGET),mipsel-linux)
-override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT)
+override TARGET_UNITS+=$(GRAPH_UNIT) $(GGIGRAPH_UNIT) ptcgraph ptccrt
 endif
 ifeq ($(FULL_TARGET),i386-linux)
 override CLEAN_UNITS+=$(GGIGRAPH_UNIT) $(GRAPH_UNIT)
@@ -884,184 +887,184 @@ ifeq ($(FULL_TARGET),mipsel-linux)
 override COMPILER_INCLUDEDIR+=src/$(OS_TARGET) src/inc  src/unix
 endif
 ifeq ($(FULL_TARGET),i386-linux)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-go32v2)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-win32)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-os2)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-freebsd)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-beos)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-haiku)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-netbsd)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-solaris)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-qnx)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-netware)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-openbsd)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-wdosx)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-darwin)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-emx)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-watcom)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-netwlibc)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-wince)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-embedded)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),i386-symbian)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),m68k-linux)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),m68k-freebsd)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),m68k-netbsd)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),m68k-amiga)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),m68k-atari)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),m68k-openbsd)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),m68k-palmos)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),m68k-embedded)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),powerpc-linux)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),powerpc-netbsd)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),powerpc-amiga)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),powerpc-macos)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),powerpc-darwin)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),powerpc-morphos)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),powerpc-embedded)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),sparc-linux)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),sparc-netbsd)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),sparc-solaris)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),sparc-embedded)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),x86_64-linux)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),x86_64-solaris)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),x86_64-darwin)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),x86_64-win64)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),x86_64-embedded)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),arm-linux)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),arm-palmos)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),arm-darwin)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),arm-wince)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),arm-gba)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),arm-nds)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),arm-embedded)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),arm-symbian)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),powerpc64-linux)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),powerpc64-darwin)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),powerpc64-embedded)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),avr-embedded)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),armeb-linux)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),armeb-embedded)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 ifeq ($(FULL_TARGET),mipsel-linux)
-override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc tests examples
+override COMPILER_SOURCEDIR+=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 endif
 override SHARED_BUILD=n
 override SHARED_BUILD=n
@@ -1865,8 +1868,11 @@ endif
 override REQUIRE_PACKAGES=rtl 
 ifeq ($(FULL_TARGET),i386-linux)
 REQUIRE_PACKAGES_RTL=1
-REQUIRE_PACKAGES_PTHREADS=1
+REQUIRE_PACKAGES_HERMES=1
+REQUIRE_PACKAGES_FCL-BASE=1
 REQUIRE_PACKAGES_X11=1
+REQUIRE_PACKAGES_PTC=1
+REQUIRE_PACKAGES_PTHREADS=1
 REQUIRE_PACKAGES_SDL=1
 endif
 ifeq ($(FULL_TARGET),i386-go32v2)
@@ -1874,6 +1880,9 @@ REQUIRE_PACKAGES_RTL=1
 endif
 ifeq ($(FULL_TARGET),i386-win32)
 REQUIRE_PACKAGES_RTL=1
+REQUIRE_PACKAGES_HERMES=1
+REQUIRE_PACKAGES_FCL-BASE=1
+REQUIRE_PACKAGES_PTC=1
 REQUIRE_PACKAGES_PTHREADS=1
 REQUIRE_PACKAGES_X11=1
 REQUIRE_PACKAGES_SDL=1
@@ -1937,6 +1946,10 @@ REQUIRE_PACKAGES_RTL=1
 endif
 ifeq ($(FULL_TARGET),m68k-linux)
 REQUIRE_PACKAGES_RTL=1
+REQUIRE_PACKAGES_HERMES=1
+REQUIRE_PACKAGES_FCL-BASE=1
+REQUIRE_PACKAGES_X11=1
+REQUIRE_PACKAGES_PTC=1
 endif
 ifeq ($(FULL_TARGET),m68k-freebsd)
 REQUIRE_PACKAGES_RTL=1
@@ -1961,8 +1974,11 @@ REQUIRE_PACKAGES_RTL=1
 endif
 ifeq ($(FULL_TARGET),powerpc-linux)
 REQUIRE_PACKAGES_RTL=1
-REQUIRE_PACKAGES_PTHREADS=1
+REQUIRE_PACKAGES_HERMES=1
+REQUIRE_PACKAGES_FCL-BASE=1
 REQUIRE_PACKAGES_X11=1
+REQUIRE_PACKAGES_PTC=1
+REQUIRE_PACKAGES_PTHREADS=1
 REQUIRE_PACKAGES_SDL=1
 endif
 ifeq ($(FULL_TARGET),powerpc-netbsd)
@@ -1988,6 +2004,10 @@ REQUIRE_PACKAGES_RTL=1
 endif
 ifeq ($(FULL_TARGET),sparc-linux)
 REQUIRE_PACKAGES_RTL=1
+REQUIRE_PACKAGES_HERMES=1
+REQUIRE_PACKAGES_FCL-BASE=1
+REQUIRE_PACKAGES_X11=1
+REQUIRE_PACKAGES_PTC=1
 endif
 ifeq ($(FULL_TARGET),sparc-netbsd)
 REQUIRE_PACKAGES_RTL=1
@@ -2000,6 +2020,10 @@ REQUIRE_PACKAGES_RTL=1
 endif
 ifeq ($(FULL_TARGET),x86_64-linux)
 REQUIRE_PACKAGES_RTL=1
+REQUIRE_PACKAGES_HERMES=1
+REQUIRE_PACKAGES_FCL-BASE=1
+REQUIRE_PACKAGES_X11=1
+REQUIRE_PACKAGES_PTC=1
 endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
 REQUIRE_PACKAGES_RTL=1
@@ -2012,12 +2036,19 @@ REQUIRE_PACKAGES_RTL=1
 endif
 ifeq ($(FULL_TARGET),x86_64-win64)
 REQUIRE_PACKAGES_RTL=1
+REQUIRE_PACKAGES_HERMES=1
+REQUIRE_PACKAGES_FCL-BASE=1
+REQUIRE_PACKAGES_PTC=1
 endif
 ifeq ($(FULL_TARGET),x86_64-embedded)
 REQUIRE_PACKAGES_RTL=1
 endif
 ifeq ($(FULL_TARGET),arm-linux)
 REQUIRE_PACKAGES_RTL=1
+REQUIRE_PACKAGES_HERMES=1
+REQUIRE_PACKAGES_FCL-BASE=1
+REQUIRE_PACKAGES_X11=1
+REQUIRE_PACKAGES_PTC=1
 endif
 ifeq ($(FULL_TARGET),arm-palmos)
 REQUIRE_PACKAGES_RTL=1
@@ -2042,6 +2073,10 @@ REQUIRE_PACKAGES_RTL=1
 endif
 ifeq ($(FULL_TARGET),powerpc64-linux)
 REQUIRE_PACKAGES_RTL=1
+REQUIRE_PACKAGES_HERMES=1
+REQUIRE_PACKAGES_FCL-BASE=1
+REQUIRE_PACKAGES_X11=1
+REQUIRE_PACKAGES_PTC=1
 endif
 ifeq ($(FULL_TARGET),powerpc64-darwin)
 REQUIRE_PACKAGES_RTL=1
@@ -2054,12 +2089,20 @@ REQUIRE_PACKAGES_RTL=1
 endif
 ifeq ($(FULL_TARGET),armeb-linux)
 REQUIRE_PACKAGES_RTL=1
+REQUIRE_PACKAGES_HERMES=1
+REQUIRE_PACKAGES_FCL-BASE=1
+REQUIRE_PACKAGES_X11=1
+REQUIRE_PACKAGES_PTC=1
 endif
 ifeq ($(FULL_TARGET),armeb-embedded)
 REQUIRE_PACKAGES_RTL=1
 endif
 ifeq ($(FULL_TARGET),mipsel-linux)
 REQUIRE_PACKAGES_RTL=1
+REQUIRE_PACKAGES_HERMES=1
+REQUIRE_PACKAGES_FCL-BASE=1
+REQUIRE_PACKAGES_X11=1
+REQUIRE_PACKAGES_PTC=1
 endif
 ifdef REQUIRE_PACKAGES_RTL
 PACKAGEDIR_RTL:=$(firstword $(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /rtl/Makefile.fpc,$(PACKAGESDIR))))))
@@ -2087,30 +2130,56 @@ ifdef UNITDIR_RTL
 override COMPILER_UNITDIR+=$(UNITDIR_RTL)
 endif
 endif
-ifdef REQUIRE_PACKAGES_PTHREADS
-PACKAGEDIR_PTHREADS:=$(firstword $(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /pthreads/Makefile.fpc,$(PACKAGESDIR))))))
-ifneq ($(PACKAGEDIR_PTHREADS),)
-ifneq ($(wildcard $(PACKAGEDIR_PTHREADS)/units/$(TARGETSUFFIX)),)
-UNITDIR_PTHREADS=$(PACKAGEDIR_PTHREADS)/units/$(TARGETSUFFIX)
+ifdef REQUIRE_PACKAGES_HERMES
+PACKAGEDIR_HERMES:=$(firstword $(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /hermes/Makefile.fpc,$(PACKAGESDIR))))))
+ifneq ($(PACKAGEDIR_HERMES),)
+ifneq ($(wildcard $(PACKAGEDIR_HERMES)/units/$(TARGETSUFFIX)),)
+UNITDIR_HERMES=$(PACKAGEDIR_HERMES)/units/$(TARGETSUFFIX)
 else
-UNITDIR_PTHREADS=$(PACKAGEDIR_PTHREADS)
+UNITDIR_HERMES=$(PACKAGEDIR_HERMES)
 endif
 ifdef CHECKDEPEND
-$(PACKAGEDIR_PTHREADS)/$(FPCMADE):
-	$(MAKE) -C $(PACKAGEDIR_PTHREADS) $(FPCMADE)
-override ALLDEPENDENCIES+=$(PACKAGEDIR_PTHREADS)/$(FPCMADE)
+$(PACKAGEDIR_HERMES)/$(FPCMADE):
+	$(MAKE) -C $(PACKAGEDIR_HERMES) $(FPCMADE)
+override ALLDEPENDENCIES+=$(PACKAGEDIR_HERMES)/$(FPCMADE)
 endif
 else
-PACKAGEDIR_PTHREADS=
-UNITDIR_PTHREADS:=$(subst /Package.fpc,,$(strip $(wildcard $(addsuffix /pthreads/Package.fpc,$(UNITSDIR)))))
-ifneq ($(UNITDIR_PTHREADS),)
-UNITDIR_PTHREADS:=$(firstword $(UNITDIR_PTHREADS))
+PACKAGEDIR_HERMES=
+UNITDIR_HERMES:=$(subst /Package.fpc,,$(strip $(wildcard $(addsuffix /hermes/Package.fpc,$(UNITSDIR)))))
+ifneq ($(UNITDIR_HERMES),)
+UNITDIR_HERMES:=$(firstword $(UNITDIR_HERMES))
 else
-UNITDIR_PTHREADS=
+UNITDIR_HERMES=
 endif
 endif
-ifdef UNITDIR_PTHREADS
-override COMPILER_UNITDIR+=$(UNITDIR_PTHREADS)
+ifdef UNITDIR_HERMES
+override COMPILER_UNITDIR+=$(UNITDIR_HERMES)
+endif
+endif
+ifdef REQUIRE_PACKAGES_FCL-BASE
+PACKAGEDIR_FCL-BASE:=$(firstword $(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /fcl-base/Makefile.fpc,$(PACKAGESDIR))))))
+ifneq ($(PACKAGEDIR_FCL-BASE),)
+ifneq ($(wildcard $(PACKAGEDIR_FCL-BASE)/units/$(TARGETSUFFIX)),)
+UNITDIR_FCL-BASE=$(PACKAGEDIR_FCL-BASE)/units/$(TARGETSUFFIX)
+else
+UNITDIR_FCL-BASE=$(PACKAGEDIR_FCL-BASE)
+endif
+ifdef CHECKDEPEND
+$(PACKAGEDIR_FCL-BASE)/$(FPCMADE):
+	$(MAKE) -C $(PACKAGEDIR_FCL-BASE) $(FPCMADE)
+override ALLDEPENDENCIES+=$(PACKAGEDIR_FCL-BASE)/$(FPCMADE)
+endif
+else
+PACKAGEDIR_FCL-BASE=
+UNITDIR_FCL-BASE:=$(subst /Package.fpc,,$(strip $(wildcard $(addsuffix /fcl-base/Package.fpc,$(UNITSDIR)))))
+ifneq ($(UNITDIR_FCL-BASE),)
+UNITDIR_FCL-BASE:=$(firstword $(UNITDIR_FCL-BASE))
+else
+UNITDIR_FCL-BASE=
+endif
+endif
+ifdef UNITDIR_FCL-BASE
+override COMPILER_UNITDIR+=$(UNITDIR_FCL-BASE)
 endif
 endif
 ifdef REQUIRE_PACKAGES_X11
@@ -2139,6 +2208,58 @@ ifdef UNITDIR_X11
 override COMPILER_UNITDIR+=$(UNITDIR_X11)
 endif
 endif
+ifdef REQUIRE_PACKAGES_PTC
+PACKAGEDIR_PTC:=$(firstword $(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /ptc/Makefile.fpc,$(PACKAGESDIR))))))
+ifneq ($(PACKAGEDIR_PTC),)
+ifneq ($(wildcard $(PACKAGEDIR_PTC)/units/$(TARGETSUFFIX)),)
+UNITDIR_PTC=$(PACKAGEDIR_PTC)/units/$(TARGETSUFFIX)
+else
+UNITDIR_PTC=$(PACKAGEDIR_PTC)
+endif
+ifdef CHECKDEPEND
+$(PACKAGEDIR_PTC)/$(FPCMADE):
+	$(MAKE) -C $(PACKAGEDIR_PTC) $(FPCMADE)
+override ALLDEPENDENCIES+=$(PACKAGEDIR_PTC)/$(FPCMADE)
+endif
+else
+PACKAGEDIR_PTC=
+UNITDIR_PTC:=$(subst /Package.fpc,,$(strip $(wildcard $(addsuffix /ptc/Package.fpc,$(UNITSDIR)))))
+ifneq ($(UNITDIR_PTC),)
+UNITDIR_PTC:=$(firstword $(UNITDIR_PTC))
+else
+UNITDIR_PTC=
+endif
+endif
+ifdef UNITDIR_PTC
+override COMPILER_UNITDIR+=$(UNITDIR_PTC)
+endif
+endif
+ifdef REQUIRE_PACKAGES_PTHREADS
+PACKAGEDIR_PTHREADS:=$(firstword $(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /pthreads/Makefile.fpc,$(PACKAGESDIR))))))
+ifneq ($(PACKAGEDIR_PTHREADS),)
+ifneq ($(wildcard $(PACKAGEDIR_PTHREADS)/units/$(TARGETSUFFIX)),)
+UNITDIR_PTHREADS=$(PACKAGEDIR_PTHREADS)/units/$(TARGETSUFFIX)
+else
+UNITDIR_PTHREADS=$(PACKAGEDIR_PTHREADS)
+endif
+ifdef CHECKDEPEND
+$(PACKAGEDIR_PTHREADS)/$(FPCMADE):
+	$(MAKE) -C $(PACKAGEDIR_PTHREADS) $(FPCMADE)
+override ALLDEPENDENCIES+=$(PACKAGEDIR_PTHREADS)/$(FPCMADE)
+endif
+else
+PACKAGEDIR_PTHREADS=
+UNITDIR_PTHREADS:=$(subst /Package.fpc,,$(strip $(wildcard $(addsuffix /pthreads/Package.fpc,$(UNITSDIR)))))
+ifneq ($(UNITDIR_PTHREADS),)
+UNITDIR_PTHREADS:=$(firstword $(UNITDIR_PTHREADS))
+else
+UNITDIR_PTHREADS=
+endif
+endif
+ifdef UNITDIR_PTHREADS
+override COMPILER_UNITDIR+=$(UNITDIR_PTHREADS)
+endif
+endif
 ifdef REQUIRE_PACKAGES_SDL
 PACKAGEDIR_SDL:=$(firstword $(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /sdl/Makefile.fpc,$(PACKAGESDIR))))))
 ifneq ($(PACKAGEDIR_SDL),)

+ 7 - 2
packages/graph/Makefile.fpc

@@ -8,6 +8,9 @@ version=2.4.3
 
 [require]
 libc=y
+packages_linux=ptc
+packages_win32=ptc
+packages_win64=ptc
 packages_linux_i386=sdl
 packages_linux_powerpc=sdl
 packages_freebsd_i386=sdl
@@ -22,7 +25,7 @@ units=$(GGIGRAPH_UNIT) $(GRAPH_UNIT)
 [target]
 dirs=
 units=
-units_linux=$(GRAPH_UNIT) $(GGIGRAPH_UNIT)
+units_linux=$(GRAPH_UNIT) $(GGIGRAPH_UNIT) ptcgraph ptccrt
 units_freebsd=graph $(GGIGRAPH_UNIT)
 units_win32=graph wincrt winmouse
 units_go32v2=graph
@@ -33,6 +36,8 @@ units_i386_freebsd=sdlgraph
 units_win32=sdlgraph
 units_powerpc_darwin=sdlgraph
 units_i386_darwin=sdlgraph
+units_win32=ptcgraph ptccrt
+units_win64=ptcgraph ptccrt
 
 [compiler]
 options=-S2
@@ -42,7 +47,7 @@ includedir_freebsd=src/unix
 includedir_darwin=src/unix
 includedir_netbsd=src/unix
 includedir_openbsd=src/unix
-sourcedir=src/$(OS_TARGET) src/inc tests examples
+sourcedir=src/$(OS_TARGET) src/inc src/ptcgraph tests examples
 
 [install]
 fpcpackage=y

+ 0 - 537
packages/graph/src/ptcgraph.pp

@@ -1,537 +0,0 @@
-{
-    This file is part of the Free Pascal run time library.
-    Copyright (c) 2007 by Daniel Mantione
-      member of the Free Pascal development team
-
-    This file implements the PTC support for the graph unit
-
-    See the file COPYING.FPC, included in this distribution,
-    for details about the copyright.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
- **********************************************************************}
-unit ptcgraph;
-
-{$define logging}
-
-{******************************************************************************}
-                                    interface
-{******************************************************************************}
-
-{$i graphh.inc}
-
-{Driver number for PTC.}
-const	PTC=22;
-
-{******************************************************************************}
-                                 implementation
-{******************************************************************************}
-
-uses
-  termio,x86,ptc;
-
-const
-  InternalDriverName = 'PTCPas';
-
-{$i graph.inc}
-
-  type
-    PByte = ^Byte;
-    PLongInt = ^LongInt;
-
-    PByteArray = ^TByteArray;
-    TByteArray = array [0..MAXINT - 1] of Byte;
-
-
-
-{ ---------------------------------------------------------------------
-   SVGA bindings.
-
-  ---------------------------------------------------------------------}
-
-Const
-  { Text }
-
-  WRITEMODE_OVERWRITE = 0;
-  WRITEMODE_MASKED    = 1;
-  FONT_EXPANDED       = 0;
-  FONT_COMPRESSED     = 2;
-
- { Types }
- type
-   pvga_modeinfo = ^vga_modeinfo;
-   vga_modeinfo = record
-     width,
-     height,
-     bytesperpixel,
-     colors,
-     linewidth,          { scanline width in bytes }
-     maxlogicalwidth,    { maximum logical scanline width }
-     startaddressrange,  { changeable bits set }
-     maxpixels,          { video memory / bytesperpixel }
-     haveblit,           { mask of blit functions available }
-     flags: Longint;     { other flags }
-    { Extended fields: }
-     chiptype,           { Chiptype detected }
-     memory,             { videomemory in KB }
-     linewidth_unit: Longint;    { Use only a multiple of this as parameter for                                   set_displaystart }
-     linear_aperture: PChar;     { points to mmap secondary mem aperture of card }
-     aperture_size: Longint;     { size of aperture in KB if size>=videomemory.}
-
-     set_aperture_page: procedure (page: Longint);
-            { if aperture_size<videomemory select a memory page }
-     extensions: Pointer;        { points to copy of eeprom for mach32 }
-            { depends from actual driver/chiptype.. etc. }
-     end;
-
-  PGraphicsContext = ^TGraphicsContext;
-  TGraphicsContext = record
-                       ModeType: Byte;
-                       ModeFlags: Byte;
-                       Dummy: Byte;
-                       FlipPage: Byte;
-                       Width: LongInt;
-                       Height: LongInt;
-                       BytesPerPixel: LongInt;
-                       Colors: LongInt;
-                       BitsPerPixel: LongInt;
-                       ByteWidth: LongInt;
-                       VBuf: pointer;
-                       Clip: LongInt;
-                       ClipX1: LongInt;
-                       ClipY1: LongInt;
-                       ClipX2: LongInt;
-                       ClipY2: LongInt;
-                       ff: pointer;
-                     end;
-
-var
-  OldIO : TermIos;
-
-  ptcconsole:TPTCconsole;
-  ptcsurface:TPTCSurface;
-  ptcformat:TPTCFormat;
-
-Procedure SetRawMode(b:boolean);
-Var
-  Tio : Termios;
-Begin
-  if b then
-   begin
-     TCGetAttr(1,Tio);
-     OldIO:=Tio;
-     CFMakeRaw(Tio);
-   end
-  else
-   Tio:=OldIO;
-  TCSetAttr(1,TCSANOW,Tio);
-End;
-
-
-{ ---------------------------------------------------------------------
-    Required procedures
-  ---------------------------------------------------------------------}
-
-var
-  LastColor: smallint;   {Cache the last set color to improve speed}
-
-
-procedure ptc_savevideostate;
-begin
-end;
-
-procedure ptc_restorevideostate;
-begin
-{  vga_setmode(0);}
-end;
-
-{
-const
-  BgiColors: array[0..15] of LongInt
-    = ($000000, $000020, $002000, $002020,
-       $200000, $200020, $202000, $303030,
-       $202020, $00003F, $003F00, $003F3F,
-       $3F0000, $3F003F, $3F3F00, $3F3F3F);
-}
-
-procedure InitColors(nrColors: longint);
-
-var
-  i: smallint;
-begin
-{  for i:=0 to nrColors do
-    vga_setpalette(I,DefaultColors[i].red shr 2,
-      DefaultColors[i].green shr 2,DefaultColors[i].blue shr 2)}
-end;
-
-procedure ptc_initmodeproc;
-
-begin
-  writeln('Initializing mode');
-  { create format }
-  ptcformat:=TPTCFormat.Create(16,$f800,$07e0,$001f);
-  { open the console }
-  ptcconsole.open(paramstr(0),ptcformat);
-  { create surface matching console dimensions }
-  ptcsurface:=TPTCSurface.Create(ptcconsole.width,ptcconsole.height,ptcformat);
-end;
-
-Function ClipCoords (Var X,Y : smallint) : Boolean;
-{ Adapt to viewport, return TRUE if still in viewport,
-  false if outside viewport}
-
-begin
-  X:= X + StartXViewPort;
-  Y:= Y + StartYViewPort;
-  ClipCoords:=Not ClipPixels;
-  if ClipPixels then
-    Begin
-    ClipCoords:=(X < StartXViewPort) or (X > (StartXViewPort + ViewWidth));
-    ClipCoords:=ClipCoords or
-               ((Y < StartYViewPort) or (Y > (StartYViewPort + ViewHeight)));
-    ClipCoords:=Not ClipCoords;
-    end;
-end;
-
-
-procedure ptc_directpixelproc_16bpp(X,Y: smallint);
-
-var color:word;
-    pixels:Pword;
-
-begin
-  case CurrentWriteMode of
-    XORPut:
-      begin
-      { getpixel wants local/relative coordinates }
-      Color := GetPixel(x-StartXViewPort,y-StartYViewPort);
-      Color := CurrentColor Xor Color;
-      end;
-    OrPut:
-      begin
-      { getpixel wants local/relative coordinates }
-      Color := GetPixel(x-StartXViewPort,y-StartYViewPort);
-      Color := CurrentColor Or Color;
-      end;
-    AndPut:
-      begin
-      { getpixel wants local/relative coordinates }
-      Color := GetPixel(x-StartXViewPort,y-StartYViewPort);
-      Color := CurrentColor And Color;
-      end;
-    NotPut:
-      begin
-      Color := Not Color;
-      end
-  else
-    Color:=CurrentColor;
-  end;
-  pixels:=ptcsurface.lock;
-  {Plot the pixel on the surface.}
-  pixels[x+y*ptcsurface.width]:=color;
-  ptcsurface.unlock;
-  { copy to console }
-  ptcsurface.copy(ptcconsole);
-  { update console }
-  ptcconsole.update;
-end;
-
-procedure ptc_putpixelproc_16bpp(X,Y:smallint;Color:Word);
-
-var pixels:Pword;
-
-begin
-  if clipcoords(X,Y) then
-    begin
-      pixels:=ptcsurface.lock;
-{      pixels:=ptcconsole.lock;}
-      {Plot the pixel on the surface.}
-      pixels[x+y*ptcsurface.width]:=color;
-      ptcsurface.unlock;
-      { copy to console }
-      ptcsurface.copy(ptcconsole);
-      { update console }
-      ptcconsole.update;
-    end;
-end;
-
-function ptc_getpixelproc_16bpp(X,Y: smallint):word;
-
-var pixels:Pword;
-
-begin
-  if clipcoords(X,Y) then
-    begin
-      pixels:=ptcsurface.lock;
-      {Get the pixel from the surface.}
-      ptc_getpixelproc_16bpp:=pixels[x+y*ptcsurface.width];
-      ptcsurface.unlock;
-    end;
-end;
-
-
-{ Bitmap utilities }
-{type
-  PBitmap = ^TBitmap;
-  TBitmap = record
-            Width, Height: smallint;
-            Data: record end;
-            end;
-}
-
-procedure ptc_putimageproc (X,Y: smallint; var Bitmap; BitBlt: Word);
-begin
-end;
-
-procedure ptc_getimageproc (X1,Y1,X2,Y2: smallint; Var Bitmap);
-begin
-end;
-
-function  ptc_imagesizeproc (X1,Y1,X2,Y2: smallint): longint;
-begin
-end;
-
-procedure ptc_hlineproc_16bpp(x, x2,y : smallint);
-
-var pixels:Pword;
-    i:word;
-
-begin
-  {Clip.}
-  if (y<0) or (y>viewheight) then
-    exit;
-  if x<0 then
-    x:=0;
-  if x>viewwidth then
-    x:=viewwidth;
-  if x2<0 then
-    x2:=0;
-  if x>viewwidth then
-    x2:=viewwidth;
-  pixels:=ptcsurface.lock;
-  inc(x,StartXViewPort);
-  inc(x2,StartXViewPort);
-  inc(y,StartXViewPort);
-  {Plot the pixel on the surface.}
-  for i:=x to x2 do
-    pixels[i+y*ptcsurface.width]:=$ffff;
-  ptcsurface.unlock;
-  { copy to console }
-  ptcsurface.copy(ptcconsole);
-  { update console }
-  ptcconsole.update;
-end;
-
-procedure ptc_vlineproc (x,y,y2: smallint);
-begin
-end;
-
-procedure ptc_clrviewproc_16bpp;
-
-Var I,Xmax : longint;
-
-begin
-  Xmax:=StartXViewPort+ViewWidth-1;
-  For i:=StartYViewPort to StartYViewPort+ViewHeight-1 do
-    ptc_hlineproc_16bpp(0,viewwidth,i);
-  { reset coordinates }
-  CurrentX := 0;
-  CurrentY := 0;
-end;
-
-procedure ptc_patternlineproc (x1,x2,y: smallint);
-begin
-end;
-
-procedure ptc_ellipseproc  (X,Y: smallint;XRadius: word;
-  YRadius:word; stAngle,EndAngle: word; fp: PatternLineProc);
-begin
-end;
-
-procedure ptc_lineproc (X1, Y1, X2, Y2 : smallint);
-begin
-end;
-
-procedure ptc_getscanlineproc (X1,X2,Y : smallint; var data);
-begin
-end;
-
-procedure ptc_setactivepageproc (page: word);
-begin
-end;
-
-procedure ptc_setvisualpageproc (page: word);
-begin
-end;
-
-
-procedure ptc_savestateproc;
-begin
-end;
-
-procedure ptc_restorestateproc;
-begin
-end;
-
-procedure ptc_setrgbpaletteproc(ColorNum, RedValue, GreenValue, BlueValue: smallint);
-begin
-{  vga_setpalette(ColorNum,RedValue shr 2,GreenValue shr 2,BlueValue shr 2);}
-end;
-
-procedure ptc_getrgbpaletteproc (ColorNum: smallint;
-                                    var RedValue, GreenValue, BlueValue: smallint);
-
-Var R,G,B : longint;
-
-begin
-{  vga_getpalette(ColorNum,R,G,B);}
-  RedValue:=R * 255 div 63;
-  GreenValue:=G * 255 div 63;
-  BlueValue:=B * 255 div 63;
-end;
-
-{************************************************************************}
-{*                       General routines                               *}
-{************************************************************************}
-
- procedure CloseGraph;
- Begin
-    If not isgraphmode then
-      begin
-        _graphresult := grnoinitgraph;
-        exit
-      end;
-    SetRawMode(False);
-    RestoreVideoState;
-    isgraphmode := false;
- end;
-
-  function QueryAdapterInfo:PModeInfo;
-  { This routine returns the head pointer to the list }
-  { of supported graphics modes.                      }
-  { Returns nil if no graphics mode supported.        }
-  { This list is READ ONLY!                           }
-   var
-    graphmode:Tmodeinfo;
-    ptcmode: PPTCmode;
-    d,i : longint;
-    ws,hs:string[5];
-
-   const depths:array[0..3] of byte=(8,16,24,32);
-         colours:array[0..3] of longint=(256,65536,16777216,16777216);
-         depth_names:array[0..3] of string[5]=('256','64K','16M','16M32');
-
-   begin
-     QueryAdapterInfo := ModeList;
-     { If the mode listing already exists... }
-     { simply return it, without changing    }
-     { anything...                           }
-     if assigned(ModeList) then
-       exit;
-     SaveVideoState:=@ptc_savevideostate;
-     RestoreVideoState:=@ptc_restorevideostate;
-     ptcconsole:=TPTCconsole.create;
-     ptcmode:=ptcconsole.modes;
-     i:=0;
-     initmode(graphmode);
-     with graphmode do
-       begin
-         modenumber:=0;
-         drivernumber:=ptcgraph.ptc;
-         maxx:=639;
-         maxy:=479;
-         modename:='PTC_640x480x64K';
-         maxcolor:=65536;
-         palettesize:=65536;
-         hardwarepages:=0;
-         InitMode       := @ptc_InitModeProc;
-         DirectPutPixel := @ptc_DirectPixelProc_16bpp;
-         GetPixel       := @ptc_GetPixelProc_16bpp;
-         PutPixel       := @ptc_PutPixelProc_16bpp;
-         SetRGBPalette  := @ptc_SetRGBPaletteProc;
-         GetRGBPalette  := @ptc_GetRGBPaletteProc;
-       end;
-     addmode(graphmode);
-(*
-     writeln('processing modes');
-     while ptcmode^.valid do
-       begin
-         for d:=low(depths) to high(depths) do
-           begin
-             InitMode(graphmode);
-             with graphmode do
-               begin
-                 ModeNumber:=I;
-                 DriverNumber:=ptcgraph.PTC;
-                 { MaxX is number of pixels in X direction - 1}
-                 MaxX:=ptcmode^.width-1;
-                 { same for MaxY}
-                 MaxY:=ptcmode^.height-1;
-                 str(ptcmode^.width,ws);
-                 str(ptcmode^.height,hs);
-                 modename:='PTC_'+ws+'x'+hs+'x'+depth_names[d];
-                 MaxColor := 1 shl ptcmode^.format.r * 1 shl ptcmode^.format.g *1 shl ptcmode^.format.b;
-                 writeln('mode ',modename,' ',maxcolor,'kleuren');
-                 PaletteSize := MaxColor;
-                 HardwarePages := 0;
-*)
-                 { necessary hooks ...}
-(*
-                 if (MaxColor = 16) and
-                   (LongInt(ModeInfo.Width) * LongInt(ModeInfo.Height) < 65536*4*2) then
-                  begin
-                   {Use optimized graphics routines for 4 bit EGA/VGA modes.}
-                   ScrWidth := ModeInfo.Width div 8;
-                   DirectPutPixel := @DirectPutPixel16;
-                   PutPixel := @PutPixel16;
-                   GetPixel := @GetPixel16;
-                   HLine := @HLine16;
-                   VLine := @VLine16;
-                   GetScanLine := @GetScanLine16;
-                 end
-               else
-*)
-(*
-                 begin
-                   DirectPutPixel := @ptc_DirectPixelProc;
-                   GetPixel       := @ptc_GetPixelProc;
-                   PutPixel       := @ptc_PutPixelProc;
-                   { May be implemented later:
-                   HLine          := @libvga_HLineProc;
-                   VLine          := @libvga_VLineProc;
-                   GetScanLine    := @libvga_GetScanLineProc;}
-                   ClearViewPort  := @ptc_ClrViewProc;
-                 end;
-                 SetRGBPalette  := @ptc_SetRGBPaletteProc;
-                 GetRGBPalette  := @ptc_GetRGBPaletteProc;
-                 { These are not really implemented yet:
-                 PutImage       := @libvga_PutImageProc;
-                 GetImage       := @libvga_GetImageProc;}
-{                If you use the default getimage/putimage, you also need the default
-                 imagesize! (JM)
-                 ImageSize      := @libvga_ImageSizeProc; }
-                 { Add later maybe ?
-                 SetVisualPage  := SetVisualPageProc;
-                 SetActivePage  := SetActivePageProc;
-                 Line           := @libvga_LineProc;
-                 InternalEllipse:= @libvga_EllipseProc;
-                 PatternLine    := @libvga_PatternLineProc;
-                 }
-                 InitMode       := @ptc_InitModeProc;
-               end;
-           AddMode(graphmode);
-           inc(i);
-         end;
-     end;
-*)
-  end;
-
-initialization
-  ptcconsole:=TPTCconsole.create;
-  InitializeGraph;
-finalization
-  ptcconsole.destroy;
-end.

+ 266 - 0
packages/graph/src/ptcgraph/ptccrt.pp

@@ -0,0 +1,266 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2010 by Nikolay Nikolov ([email protected])
+
+    This file implements keyboard input support for ptcgraph
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+unit ptccrt;
+
+{$MODE objfpc}
+{$DEFINE HasCRT}
+
+{$IFDEF WinCE}
+  {$UNDEF HasCRT}
+{$ENDIF WinCE}
+
+interface
+
+{$IFDEF HasCRT}
+uses
+  crt;
+{$ENDIF HasCRT}
+
+type
+{$IFDEF HasCRT}
+  tcrtcoord = crt.tcrtcoord;
+{$ELSE HasCRT}
+  tcrtcoord = 1..255;
+{$ENDIF HasCRT}
+
+var
+  DirectVideo: Boolean {$IFDEF HasCRT}absolute crt.DirectVideo{$ENDIF HasCRT};
+  TextAttr: Byte {$IFDEF HasCRT}absolute crt.TextAttr{$ENDIF HasCRT};
+
+function KeyPressed: Boolean;
+function ReadKey: Char;
+procedure ClrScr;
+procedure ClrEol;
+procedure GotoXY(X, Y: tcrtcoord);
+procedure TextColor(Color: Byte);
+procedure TextBackground(Color: Byte);
+procedure Delay(MS: Word);
+procedure Sound(HZ: Word);
+procedure NoSound;
+
+implementation
+
+uses
+  ptcgraph, ptc, ptcwrapper
+  {$IFDEF UNIX}
+  , baseunix
+  {$ENDIF UNIX}
+  {$IF defined(Win32) or defined(Win64) or defined(WinCE)}
+  , windows
+  {$ENDIF defined(Win32) or defined(Win64) or defined(WinCE)}
+  ;
+
+function InGraphMode: Boolean;
+begin
+  Result := (PTCWrapperObject <> nil) and (PTCWrapperObject.IsOpen);
+end;
+
+var
+  KeyBuffer: array[0..64] of Char;
+  KeyBufHead, KeyBufTail: Integer;
+
+function KeyBufEmpty: Boolean;
+begin
+  Result := KeyBufHead = KeyBufTail;
+end;
+
+procedure KeyBufAdd(Ch: Char);
+begin
+  {todo: overflow checking}
+  KeyBuffer[KeyBufTail] := Ch;
+  Inc(KeyBufTail);
+  if KeyBufTail > High(KeyBuffer) then
+    KeyBufTail := Low(KeyBuffer);
+end;
+
+procedure KeyBufAdd(S: String);
+var
+  I: Integer;
+begin
+  for I := 1 to Length(S) do
+    KeyBufAdd(S[I]);
+end;
+
+function KeyBufGet: Char;
+begin
+  if KeyBufHead <> KeyBufTail then
+  begin
+    Result := KeyBuffer[KeyBufHead];
+    Inc(KeyBufHead);
+    if KeyBufHead > High(KeyBuffer) then
+      KeyBufHead := Low(KeyBuffer);
+  end;
+end;
+
+procedure GetKeyEvents;
+var
+  ev: TPTCEvent;
+  KeyEv: TPTCKeyEvent;
+begin
+  ev := nil;
+  try
+    repeat
+      PTCWrapperObject.NextEvent(ev, False, [PTCKeyEvent]);
+      if ev <> nil then
+      begin
+        KeyEv := TPTCKeyEvent(ev);
+        if KeyEv.Press then
+        begin
+          case KeyEv.Code of
+            PTCKEY_BACKSPACE:
+              if KeyEv.Control then
+                KeyBufAdd(#127)
+              else
+                KeyBufAdd(#8);
+            PTCKEY_ENTER:  KeyBufAdd(#13);
+            PTCKEY_ESCAPE: KeyBufAdd(#27);
+            PTCKEY_INSERT: KeyBufAdd(#0#82);
+            PTCKEY_DELETE: KeyBufAdd(#0#83);
+            PTCKEY_LEFT:   KeyBufAdd(#0#75);
+            PTCKEY_UP:     KeyBufAdd(#0#72);
+            PTCKEY_RIGHT:  KeyBufAdd(#0#77);
+            PTCKEY_DOWN:   KeyBufAdd(#0#80);
+            PTCKEY_HOME:     KeyBufAdd(#0#71);
+            PTCKEY_END:      KeyBufAdd(#0#79);
+            PTCKEY_PAGEUP:   KeyBufAdd(#0#73);
+            PTCKEY_PAGEDOWN: KeyBufAdd(#0#81);
+            PTCKEY_F1:     KeyBufAdd(#0#59);
+            PTCKEY_F2:     KeyBufAdd(#0#60);
+            PTCKEY_F3:     KeyBufAdd(#0#61);
+            PTCKEY_F4:     KeyBufAdd(#0#62);
+            PTCKEY_F5:     KeyBufAdd(#0#63);
+            PTCKEY_F6:     KeyBufAdd(#0#64);
+            PTCKEY_F7:     KeyBufAdd(#0#65);
+            PTCKEY_F8:     KeyBufAdd(#0#66);
+            PTCKEY_F9:     KeyBufAdd(#0#67);
+            PTCKEY_F10:    KeyBufAdd(#0#68);
+            else
+              if (KeyEv.Unicode >= 32) and (KeyEv.Unicode <= 127) then
+                KeyBufAdd(Chr(KeyEv.Unicode));
+          end;
+        end;
+      end;
+    until ev = nil;
+  finally
+    ev.Free;
+  end;
+end;
+
+function KeyPressed: Boolean;
+begin
+  if not InGraphMode then
+  begin
+{$IFDEF HasCRT}
+    Result := crt.KeyPressed
+{$ELSE HasCRT}
+    Result := False;
+{$ENDIF HasCRT}
+  end
+  else
+  begin
+    GetKeyEvents;
+    Result := not KeyBufEmpty;
+  end;
+end;
+
+function ReadKey: Char;
+{$IFDEF UNIX}
+var
+  req, rem: TTimeSpec;
+{$ENDIF UNIX}
+begin
+  if not InGraphMode then
+  begin
+{$IFDEF HasCRT}
+    Result := crt.ReadKey;
+{$ELSE HasCRT}
+    Result := #0;
+{$ENDIF HasCRT}
+  end
+  else
+  begin
+    while not KeyPressed do
+    begin
+{$IFDEF UNIX}
+      req.tv_sec := 0;
+      req.tv_nsec := 1000000;
+      fpnanosleep(@req, @rem);
+{$ENDIF UNIX}
+{$IF defined(Win32) or defined(Win64) or defined(WinCE)}
+      Sleep(1);
+{$ENDIF defined(Win32) or defined(Win64) or defined(WinCE)}
+    end;
+    Result := KeyBufGet;
+  end;
+end;
+
+procedure ClrScr;
+begin
+{$IFDEF HasCRT}
+  crt.ClrScr;
+{$ENDIF HasCRT}
+end;
+
+procedure ClrEol;
+begin
+{$IFDEF HasCRT}
+  crt.ClrEol;
+{$ENDIF HasCRT}
+end;
+
+procedure GotoXY(X, Y: tcrtcoord);
+begin
+{$IFDEF HasCRT}
+  crt.GotoXY(X, Y);
+{$ENDIF HasCRT}
+end;
+
+procedure TextColor(Color: Byte);
+begin
+{$IFDEF HasCRT}
+  crt.TextColor(Color);
+{$ENDIF HasCRT}
+end;
+
+procedure TextBackground(Color: Byte);
+begin
+{$IFDEF HasCRT}
+  crt.TextBackground(Color);
+{$ENDIF HasCRT}
+end;
+
+procedure Delay(MS: Word);
+begin
+{$IFDEF HasCRT}
+  crt.Delay(MS);
+{$ENDIF HasCRT}
+end;
+
+procedure Sound(HZ: Word);
+begin
+{$IFDEF HasCRT}
+  crt.Sound(HZ);
+{$ENDIF HasCRT}
+end;
+
+procedure NoSound;
+begin
+{$IFDEF HasCRT}
+  crt.NoSound;
+{$ENDIF HasCRT}
+end;
+
+end.

+ 2783 - 0
packages/graph/src/ptcgraph/ptcgraph.pp

@@ -0,0 +1,2783 @@
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2010 by Nikolay Nikolov ([email protected])
+    Copyright (c) 2007 by Daniel Mantione
+      member of the Free Pascal development team
+
+    This file implements the PTC support for the graph unit
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+unit ptcgraph;
+
+{$define logging}
+
+{******************************************************************************}
+                                    interface
+{******************************************************************************}
+
+uses
+  ptc, ptcwrapper;
+
+{$i graphh.inc}
+
+{Driver number for PTC.}
+const
+  _PTC=22;
+
+//  CGA      = 1;
+//  MCGA     = 2;
+//  EGA      = 3;
+//  EGA64    = 4;
+//  EGAMono  = 5;
+  IBM8514  = 6;
+//  HercMono = 7;
+  ATT400   = 8;
+//  VGA      = 9;
+  PC3270   = 10;
+  LastDriverNum = 10;
+
+//  CGAC0 = 0;
+//  CGAC1 = 1;
+//  CGAC2 = 2;
+//  CGAC3 = 3;
+//  CGAHi = 4;
+
+//  MCGAC0  = 0;
+//  MCGAC1  = 1;
+//  MCGAC2  = 2;
+//  MCGAC3  = 3;
+//  MCGAMed = 4;
+//  MCGAHi  = 5;
+
+//  EGALo = 0;
+//  EGAHi = 1;
+
+//  EGA64Lo = 0;
+//  EGA64Hi = 1;
+
+//  EGAMonoHi = 3;
+
+  IBM8514Lo = 0;
+  IBM8514Hi = 1;
+
+//  HercMonoHi = 0;
+
+  ATT400C0  = 0;
+  ATT400C1  = 1;
+  ATT400C2  = 2;
+  ATT400C3  = 3;
+  ATT400Med = 4;
+  ATT400Hi  = 5;
+
+//  VGALo  = 0;
+//  VGAMed = 1;
+//  VGAHi  = 2;
+
+
+
+  m640x200x16       = VGALo;
+  m640x400x16       = VGAMed;
+  m640x480x16       = VGAHi;
+
+  { VESA Specific video modes. }
+  m320x200x32k      = $10D;
+  m320x200x64k      = $10E;
+
+  m640x400x256      = $100;
+
+  m640x480x256      = $101;
+  m640x480x32k      = $110;
+  m640x480x64k      = $111;
+
+  m800x600x16       = $102;
+  m800x600x256      = $103;
+  m800x600x32k      = $113;
+  m800x600x64k      = $114;
+
+  m1024x768x16      = $104;
+  m1024x768x256     = $105;
+  m1024x768x32k     = $116;
+  m1024x768x64k     = $117;
+
+  m1280x1024x16     = $106;
+  m1280x1024x256    = $107;
+  m1280x1024x32k    = $119;
+  m1280x1024x64k    = $11A;
+
+const
+  FullscreenGraph: Boolean = False;
+
+var
+  PTCWrapperObject: TPTCWrapperThread;
+
+{******************************************************************************}
+                                 implementation
+{******************************************************************************}
+
+//uses
+//  termio{,x86};
+
+const
+  InternalDriverName = 'PTCPas';
+
+var
+  Has320x200: Boolean;
+  Has320x240: Boolean;
+  charmessagehandler: Pointer;  { dummy, for compatibility with graph.inc, which initializes this to nil under win32 }
+  hasVesa: Boolean = false;  { dummy, for compatibility with graph.inc, which checks it in its ExitProc under go32v2 }
+  VesaInfo: record { dummy, for compatibility with graph.inc under go32v2 }
+    ModeList: PInteger;
+  end;
+
+{$i graph.inc}
+
+type
+  PByte = ^Byte;
+  PLongInt = ^LongInt;
+
+  PByteArray = ^TByteArray;
+  TByteArray = array [0..MAXINT - 1] of Byte;
+
+  TEGAPalette = array [0..15] of 0..63;
+  TVGAPalette = array [0..255, 0..2] of 0..63;
+
+{ ---------------------------------------------------------------------
+   SVGA bindings.
+
+  ---------------------------------------------------------------------}
+
+const
+  DefaultEGAPalette: TEGAPalette =
+    (0, 1, 2, 3, 4, 5, 20, 7, 56, 57, 58, 59, 60, 61, 62, 63);
+
+  { default EGA palette for modes 0Dh and 0Eh }
+  DefaultEGAPalette_200: TEGAPalette =
+    (0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23);
+
+  { default VGA palette for modes 04h, 05h, 06h, 0Dh and 0Eh }
+  DefaultVGA16Palette_CGAEmu: TVGAPalette =
+    ((0,0,0),(0,0,42),(0,42,0),(0,42,42),(42,0,0),(42,0,42),(42,21,0),(42,42,42),
+     (0,0,0),(0,0,42),(0,42,0),(0,42,42),(42,0,0),(42,0,42),(42,21,0),(42,42,42),
+     (21,21,21),(21,21,63),(21,63,21),(21,63,63),(63,21,21),(63,21,63),(63,63,21),(63,63,63),
+     (21,21,21),(21,21,63),(21,63,21),(21,63,63),(63,21,21),(63,21,63),(63,63,21),(63,63,63),
+     (0,0,0),(0,0,42),(0,42,0),(0,42,42),(42,0,0),(42,0,42),(42,21,0),(42,42,42),
+     (0,0,0),(0,0,42),(0,42,0),(0,42,42),(42,0,0),(42,0,42),(42,21,0),(42,42,42),
+     (21,21,21),(21,21,63),(21,63,21),(21,63,63),(63,21,21),(63,21,63),(63,63,21),(63,63,63),
+     (21,21,21),(21,21,63),(21,63,21),(21,63,63),(63,21,21),(63,21,63),(63,63,21),(63,63,63),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0));
+
+  { default VGA palette for modes 00h, 01h, 02h, 03h, 10h, 11h, 12h }
+  DefaultVGA16Palette: TVGAPalette =
+    ((0,0,0),(0,0,42),(0,42,0),(0,42,42),(42,0,0),(42,0,42),(42,42,0),(42,42,42),
+     (0,0,21),(0,0,63),(0,42,21),(0,42,63),(42,0,21),(42,0,63),(42,42,21),(42,42,63),
+     (0,21,0),(0,21,42),(0,63,0),(0,63,42),(42,21,0),(42,21,42),(42,63,0),(42,63,42),
+     (0,21,21),(0,21,63),(0,63,21),(0,63,63),(42,21,21),(42,21,63),(42,63,21),(42,63,63),
+     (21,0,0),(21,0,42),(21,42,0),(21,42,42),(63,0,0),(63,0,42),(63,42,0),(63,42,42),
+     (21,0,21),(21,0,63),(21,42,21),(21,42,63),(63,0,21),(63,0,63),(63,42,21),(63,42,63),
+     (21,21,0),(21,21,42),(21,63,0),(21,63,42),(63,21,0),(63,21,42),(63,63,0),(63,63,42),
+     (21,21,21),(21,21,63),(21,63,21),(21,63,63),(63,21,21),(63,21,63),(63,63,21),(63,63,63),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),
+     (0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0));
+
+  { default VGA palette for mode 13h }
+  DefaultVGA256Palette: TVGAPalette =
+   ((0,0,0),(0,0,42),(0,42,0),(0,42,42),(42,0,0),(42,0,42),(42,21,0),(42,42,42),(21,21,21),(21,21,63),(21,63,21),(21,63,63),(63,21,21),
+    (63,21,63),(63,63,21),(63,63,63),(0,0,0),(5,5,5),(8,8,8),(11,11,11),(14,14,14),(17,17,17),(20,20,20),(24,24,24),(28,28,28),(32,32,32),
+    (36,36,36),(40,40,40),(45,45,45),(50,50,50),(56,56,56),(63,63,63),(0,0,63),(16,0,63),(31,0,63),(47,0,63),(63,0,63),(63,0,47),(63,0,31),
+    (63,0,16),(63,0,0),(63,16,0),(63,31,0),(63,47,0),(63,63,0),(47,63,0),(31,63,0),(16,63,0),(0,63,0),(0,63,16),(0,63,31),(0,63,47),(0,63,63),
+    (0,47,63),(0,31,63),(0,16,63),(31,31,63),(39,31,63),(47,31,63),(55,31,63),(63,31,63),(63,31,55),(63,31,47),(63,31,39),(63,31,31),(63,39,31),
+    (63,47,31),(63,55,31),(63,63,31),(55,63,31),(47,63,31),(39,63,31),(31,63,31),(31,63,39),(31,63,47),(31,63,55),(31,63,63),(31,55,63),(31,47,63),
+    (31,39,63),(45,45,63),(49,45,63),(54,45,63),(58,45,63),(63,45,63),(63,45,58),(63,45,54),(63,45,49),(63,45,45),(63,49,45),(63,54,45),(63,58,45),
+    (63,63,45),(58,63,45),(54,63,45),(49,63,45),(45,63,45),(45,63,49),(45,63,54),(45,63,58),(45,63,63),(45,58,63),(45,54,63),(45,49,63),(0,0,28),
+    (7,0,28),(14,0,28),(21,0,28),(28,0,28),(28,0,21),(28,0,14),(28,0,7),(28,0,0),(28,7,0),(28,14,0),(28,21,0),(28,28,0),(21,28,0),(14,28,0),(7,28,0),
+    (0,28,0),(0,28,7),(0,28,14),(0,28,21),(0,28,28),(0,21,28),(0,14,28),(0,7,28),(14,14,28),(17,14,28),(21,14,28),(24,14,28),(28,14,28),(28,14,24),
+    (28,14,21),(28,14,17),(28,14,14),(28,17,14),(28,21,14),(28,24,14),(28,28,14),(24,28,14),(21,28,14),(17,28,14),(14,28,14),(14,28,17),(14,28,21),
+    (14,28,24),(14,28,28),(14,24,28),(14,21,28),(14,17,28),(20,20,28),(22,20,28),(24,20,28),(26,20,28),(28,20,28),(28,20,26),(28,20,24),(28,20,22),
+    (28,20,20),(28,22,20),(28,24,20),(28,26,20),(28,28,20),(26,28,20),(24,28,20),(22,28,20),(20,28,20),(20,28,22),(20,28,24),(20,28,26),(20,28,28),
+    (20,26,28),(20,24,28),(20,22,28),(0,0,16),(4,0,16),(8,0,16),(12,0,16),(16,0,16),(16,0,12),(16,0,8),(16,0,4),(16,0,0),(16,4,0),(16,8,0),(16,12,0),
+    (16,16,0),(12,16,0),(8,16,0),(4,16,0),(0,16,0),(0,16,4),(0,16,8),(0,16,12),(0,16,16),(0,12,16),(0,8,16),(0,4,16),(8,8,16),(10,8,16),(12,8,16),
+    (14,8,16),(16,8,16),(16,8,14),(16,8,12),(16,8,10),(16,8,8),(16,10,8),(16,12,8),(16,14,8),(16,16,8),(14,16,8),(12,16,8),(10,16,8),(8,16,8),
+    (8,16,10),(8,16,12),(8,16,14),(8,16,16),(8,14,16),(8,12,16),(8,10,16),(11,11,16),(12,11,16),(13,11,16),(15,11,16),(16,11,16),(16,11,15),
+    (16,11,13),(16,11,12),(16,11,11),(16,12,11),(16,13,11),(16,15,11),(16,16,11),(15,16,11),(13,16,11),(12,16,11),(11,16,11),(11,16,12),(11,16,13),
+    (11,16,15),(11,16,16),(11,15,16),(11,13,16),(11,12,16),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0));
+
+  { Text }
+
+  WRITEMODE_OVERWRITE = 0;
+  WRITEMODE_MASKED    = 1;
+  FONT_EXPANDED       = 0;
+  FONT_COMPRESSED     = 2;
+
+ { Types }
+ type
+   pvga_modeinfo = ^vga_modeinfo;
+   vga_modeinfo = record
+     width,
+     height,
+     bytesperpixel,
+     colors,
+     linewidth,          { scanline width in bytes }
+     maxlogicalwidth,    { maximum logical scanline width }
+     startaddressrange,  { changeable bits set }
+     maxpixels,          { video memory / bytesperpixel }
+     haveblit,           { mask of blit functions available }
+     flags: Longint;     { other flags }
+    { Extended fields: }
+     chiptype,           { Chiptype detected }
+     memory,             { videomemory in KB }
+     linewidth_unit: Longint;    { Use only a multiple of this as parameter for                                   set_displaystart }
+     linear_aperture: PChar;     { points to mmap secondary mem aperture of card }
+     aperture_size: Longint;     { size of aperture in KB if size>=videomemory.}
+
+     set_aperture_page: procedure (page: Longint);
+            { if aperture_size<videomemory select a memory page }
+     extensions: Pointer;        { points to copy of eeprom for mach32 }
+            { depends from actual driver/chiptype.. etc. }
+     end;
+
+  PGraphicsContext = ^TGraphicsContext;
+  TGraphicsContext = record
+                       ModeType: Byte;
+                       ModeFlags: Byte;
+                       Dummy: Byte;
+                       FlipPage: Byte;
+                       Width: LongInt;
+                       Height: LongInt;
+                       BytesPerPixel: LongInt;
+                       Colors: LongInt;
+                       BitsPerPixel: LongInt;
+                       ByteWidth: LongInt;
+                       VBuf: pointer;
+                       Clip: LongInt;
+                       ClipX1: LongInt;
+                       ClipY1: LongInt;
+                       ClipX2: LongInt;
+                       ClipY2: LongInt;
+                       ff: pointer;
+                     end;
+
+var
+//  OldIO: TermIos;
+
+{  ptcconsole: TPTCConsole = nil;
+  ptcsurface: TPTCSurface = nil;
+  ptcpalette: TPTCPalette = nil;
+  ptcformat: TPTCFormat = nil;}
+  PTCWidth: Integer;
+  PTCHeight: Integer;
+  PTCFormat8: TPTCFormat;
+  PTCFormat15: TPTCFormat;
+  PTCFormat16: TPTCFormat;
+
+  EGAPaletteEnabled: Boolean;
+  EGAPalette: TEGAPalette;
+  VGAPalette: TVGAPalette;
+
+  CurrentActivePage: Integer;
+  ColorMask: Word;
+
+  DummyHGCBkColor: Word;
+  CurrentCGABkColor: Word;
+
+procedure FreeAndNil(var q);
+var
+  tmp : TObject;
+begin
+  tmp := TObject(q);
+  Pointer(q) := Nil;
+  tmp.Free;
+end;
+
+const
+  Double640x200 = True;
+
+function Double320x200: Boolean;
+begin
+  Double320x200 := not (Has320x200 and FullscreenGraph);
+end;
+
+function Double320x240: Boolean;
+begin
+  Double320x240 := not (Has320x240 and FullscreenGraph);
+end;
+
+function ptc_palette_lock: Pointer;
+begin
+  ptc_palette_lock := PTCWrapperObject.PaletteLock;
+end;
+
+procedure ptc_palette_unlock;
+begin
+  PTCWrapperObject.PaletteUnlock;
+end;
+
+function ptc_surface_lock: Pointer;
+begin
+  ptc_surface_lock := PTCWrapperObject.Lock(CurrentActivePage);
+end;
+
+procedure ptc_surface_unlock;
+begin
+  PTCWrapperObject.Unlock;
+end;
+
+procedure ptc_update;
+begin
+  { copy to console }
+//  ptcsurface.copy(ptcconsole);
+  { update console }
+//  ptcconsole.update;
+end;
+
+{Procedure SetRawMode(b:boolean);
+Var
+  Tio : Termios;
+Begin
+  if b then
+   begin
+     TCGetAttr(1,Tio);
+     OldIO:=Tio;
+     CFMakeRaw(Tio);
+   end
+  else
+   Tio:=OldIO;
+  TCSetAttr(1,TCSANOW,Tio);
+End;}
+
+
+{ ---------------------------------------------------------------------
+    Required procedures
+  ---------------------------------------------------------------------}
+
+var
+  LastColor: smallint;   {Cache the last set color to improve speed}
+
+
+procedure ptc_savevideostate;
+begin
+end;
+
+procedure ptc_restorevideostate;
+begin
+  if PTCWrapperObject <> nil then
+    PTCWrapperObject.Close;
+end;
+
+{
+const
+  BgiColors: array[0..15] of LongInt
+    = ($000000, $000020, $002000, $002020,
+       $200000, $200020, $202000, $303030,
+       $202020, $00003F, $003F00, $003F3F,
+       $3F0000, $3F003F, $3F3F00, $3F3F3F);
+}
+
+procedure InitColors(nrColors: longint);
+
+var
+  i: smallint;
+begin
+{  for i:=0 to nrColors do
+    vga_setpalette(I,DefaultColors[i].red shr 2,
+      DefaultColors[i].green shr 2,DefaultColors[i].blue shr 2)}
+end;
+
+procedure ptc_initmodeproc;
+
+begin
+//  writeln('Initializing mode');
+  { create format }
+{  FreeAndNil(PTCFormat);
+  PTCFormat:=TPTCFormat.Create(16,$f800,$07e0,$001f);}
+  { open the console }
+{  ptcconsole.open(paramstr(0),ptcformat);}
+  { create surface matching console dimensions }
+{  FreeAndNil(PTCSurface);
+  PTCSurface:=TPTCSurface.Create(ptcconsole.width,ptcconsole.height,ptcformat);}
+end;
+
+function VGA6to8(dac6: Uint32): Uint32;
+begin
+  VGA6to8 := dac6 shl 2;
+end;
+
+procedure ptc_InitPalette16(UseCGAEmuPalette: Boolean);
+var
+  PaletteData: PUint32;
+  I: Integer;
+  r, g, b: Uint32;
+begin
+  if UseCGAEmuPalette then
+  begin
+    VGAPalette := DefaultVGA16Palette_CGAEmu;
+    EGAPalette := DefaultEGAPalette_200;
+  end
+  else
+  begin
+    VGAPalette := DefaultVGA16Palette;
+    EGAPalette := DefaultEGAPalette;
+  end;
+  EGAPaletteEnabled := True;
+
+  PaletteData := ptc_palette_lock;
+
+  FillChar(PaletteData^, 256*4, 0);
+  for I := 0 to 15 do
+  begin
+    r := VGA6to8(VGAPalette[EGAPalette[I], 0]);
+    g := VGA6to8(VGAPalette[EGAPalette[I], 1]);
+    b := VGA6to8(VGAPalette[EGAPalette[I], 2]);
+    PaletteData[I] := (r shl 16) or (g shl 8) or b;
+  end;
+
+  ptc_palette_unlock;
+end;
+
+procedure ptc_InitPalette256;
+var
+  PaletteData: PUint32;
+  I: Integer;
+  r, g, b: Uint32;
+begin
+  EGAPaletteEnabled := False;
+  VGAPalette := DefaultVGA256Palette;
+
+  PaletteData := ptc_palette_lock;
+  for I := 0 to 255 do
+  begin
+    r := VGA6to8(VGAPalette[I, 0]);
+    g := VGA6to8(VGAPalette[I, 1]);
+    b := VGA6to8(VGAPalette[I, 2]);
+    PaletteData[I] := (r shl 16) or (g shl 8) or b;
+  end;
+  ptc_palette_unlock;
+end;
+
+procedure ptc_SetEGAPalette(ColorNum, Color: Integer);
+var
+  PaletteData: PUint32;
+  r, g, b: Uint32;
+begin
+  if EGAPalette[ColorNum] <> Color then
+  begin
+    if (VGAPalette[EGAPalette[ColorNum], 0] <> VGAPalette[Color, 0]) or
+       (VGAPalette[EGAPalette[ColorNum], 1] <> VGAPalette[Color, 1]) or
+       (VGAPalette[EGAPalette[ColorNum], 2] <> VGAPalette[Color, 2]) then
+    begin
+      EGAPalette[ColorNum] := Color;
+      r := VGA6to8(VGAPalette[Color, 0]);
+      g := VGA6to8(VGAPalette[Color, 1]);
+      b := VGA6to8(VGAPalette[Color, 2]);
+
+      PaletteData := ptc_palette_lock;
+      PaletteData[ColorNum] := (r shl 16) or (g shl 8) or b;
+      ptc_palette_unlock;
+    end
+    else
+      EGAPalette[ColorNum] := Color;
+  end;
+end;
+
+procedure ptc_SetVGAPalette(ColorNum, ARed, AGreen, ABlue: Integer);
+var
+  PaletteData: PUint32;
+  r, g, b: Uint32;
+  I: Integer;
+begin
+  if (VGAPalette[ColorNum, 0] <> ARed) or
+     (VGAPalette[ColorNum, 1] <> AGreen) or
+     (VGAPalette[ColorNum, 2] <> ABlue) then
+  begin
+    VGAPalette[ColorNum, 0] := ARed;
+    VGAPalette[ColorNum, 1] := AGreen;
+    VGAPalette[ColorNum, 2] := ABlue;
+    if EGAPaletteEnabled then
+    begin
+      for I := 0 to 15 do
+        if EGAPalette[I] = ColorNum then
+        begin
+          PaletteData := ptc_palette_lock;
+          PaletteData[I] := (VGA6to8(ARed) shl 16) or (VGA6to8(AGreen) shl 8) or VGA6to8(ABlue);
+          ptc_palette_unlock;
+        end;
+    end
+    else
+    begin
+      PaletteData := ptc_palette_lock;
+      PaletteData[ColorNum] := (VGA6to8(ARed) shl 16) or (VGA6to8(AGreen) shl 8) or VGA6to8(ABlue);
+      ptc_palette_unlock;
+    end;
+  end;
+end;
+
+procedure ptc_InitPaletteCGA(CGAPalette: Integer);
+var
+  PaletteData: PUint32;
+  I: Integer;
+  r, g, b: Uint32;
+begin
+  VGAPalette := DefaultVGA16Palette_CGAEmu;
+  FillChar(EGAPalette, SizeOf(EGAPalette), 0);
+  EGAPaletteEnabled := True;
+
+  case CGAPalette of
+    0:
+      begin
+        EGAPalette[1] := $12;
+        EGAPalette[2] := $14;
+        EGAPalette[3] := $16;
+      end;
+    1:
+      begin
+        EGAPalette[1] := $13;
+        EGAPalette[2] := $15;
+        EGAPalette[3] := $17;
+      end;
+    2:
+      begin
+        EGAPalette[1] := $02;
+        EGAPalette[2] := $04;
+        EGAPalette[3] := $06;
+      end;
+    3:
+      begin
+        EGAPalette[1] := $03;
+        EGAPalette[2] := $05;
+        EGAPalette[3] := $07;
+      end;
+  end;
+
+  PaletteData := ptc_palette_lock;
+  FillChar(PaletteData^, 256*4, 0);
+  for I := 0 to 3 do
+  begin
+    r := VGA6to8(VGAPalette[EGAPalette[I], 0]);
+    g := VGA6to8(VGAPalette[EGAPalette[I], 1]);
+    b := VGA6to8(VGAPalette[EGAPalette[I], 2]);
+    PaletteData[I] := (r shl 16) or (g shl 8) or b;
+  end;
+  ptc_palette_unlock;
+  CurrentCGABkColor := 0;
+end;
+
+procedure ptc_InitPaletteCGA2;
+var
+  PaletteData: PUint32;
+  I: Integer;
+  r, g, b: Uint32;
+begin
+  VGAPalette := DefaultVGA16Palette_CGAEmu;
+  FillChar(EGAPalette, SizeOf(EGAPalette), 0);
+  EGAPaletteEnabled := True;
+
+  for I := 1 to 15 do
+    EGAPalette[I] := 63;
+
+  PaletteData := ptc_palette_lock;
+  FillChar(PaletteData^, 256*4, 0);
+  for I := 0 to 1 do
+  begin
+    r := VGA6to8(VGAPalette[EGAPalette[I], 0]);
+    g := VGA6to8(VGAPalette[EGAPalette[I], 1]);
+    b := VGA6to8(VGAPalette[EGAPalette[I], 2]);
+    PaletteData[I] := (r shl 16) or (g shl 8) or b;
+  end;
+  ptc_palette_unlock;
+  CurrentCGABkColor := 0;
+end;
+
+procedure ptc_InternalOpen(const ATitle: string; AWidth, AHeight: Integer; AFormat: TPTCFormat; AVirtualPages: Integer);
+var
+  ConsoleWidth, ConsoleHeight: Integer;
+begin
+  ConsoleWidth := AWidth;
+  ConsoleHeight := AHeight;
+
+  if Double320x200 and (AWidth = 320) and (AHeight = 200) then
+  begin
+    ConsoleWidth := 640;
+    ConsoleHeight := 400;
+  end;
+
+  if Double320x240 and (AWidth = 320) and (AHeight = 240) then
+  begin
+    ConsoleWidth := 640;
+    ConsoleHeight := 480;
+  end;
+
+  if Double640x200 and (AWidth = 640) and (AHeight = 200) then
+  begin
+    ConsoleWidth := 640;
+    ConsoleHeight := 400;
+  end;
+
+  if FullscreenGraph then
+    PTCWrapperObject.Option('fullscreen output')
+  else
+    PTCWrapperObject.Option('windowed output');
+
+  PTCWrapperObject.Open(ATitle, AWidth, AHeight, ConsoleWidth, ConsoleHeight, AFormat, AVirtualPages, 0);
+end;
+
+procedure ptc_InternalInitMode16(XResolution, YResolution, Pages: LongInt; UseCGAEmuPalette: Boolean);
+begin
+{$IFDEF logging}
+  LogLn('Initializing mode ' + strf(XResolution) + ', ' + strf(YResolution) + ' 16 colours');
+{$ENDIF logging}
+  { open the console }
+  ptc_InternalOpen(ParamStr(0), XResolution, YResolution, PTCFormat8, Pages);
+  PTCWidth := XResolution;
+  PTCHeight := YResolution;
+  CurrentActivePage := 0;
+  { create palette }
+  ptc_InitPalette16(UseCGAEmuPalette);
+  ColorMask := 15;
+end;
+
+procedure ptc_InitMode16(XResolution, YResolution, Pages: LongInt);
+begin
+  ptc_InternalInitMode16(XResolution, YResolution, Pages, False);
+end;
+
+procedure ptc_InitMode16_CGAEmu(XResolution, YResolution, Pages: LongInt);
+begin
+  ptc_InternalInitMode16(XResolution, YResolution, Pages, True);
+end;
+
+procedure ptc_InitMode256(XResolution, YResolution, Pages: LongInt);
+begin
+{$IFDEF logging}
+  LogLn('Initializing mode ' + strf(XResolution) + ', ' + strf(YResolution) + ' 256 colours');
+{$ENDIF logging}
+  { open the console }
+  ptc_InternalOpen(ParamStr(0), XResolution, YResolution, PTCFormat8, Pages);
+  PTCWidth := XResolution;
+  PTCHeight := YResolution;
+  CurrentActivePage := 0;
+  { create palette }
+  ptc_InitPalette256;
+  ColorMask := 255;
+end;
+
+procedure ptc_InitModeCGA4(XResolution, YResolution, CGAPalette: LongInt);
+begin
+{$IFDEF logging}
+  LogLn('Initializing mode ' + strf(XResolution) + ', ' + strf(YResolution) + ' 4 colours, palette ' + strf(CGAPalette));
+{$ENDIF logging}
+  { open the console }
+  ptc_InternalOpen(ParamStr(0), XResolution, YResolution, PTCFormat8, 1);
+  PTCWidth := XResolution;
+  PTCHeight := YResolution;
+  CurrentActivePage := 0;
+  { create palette }
+  ptc_InitPaletteCGA(CGAPalette);
+  ColorMask := 3;
+end;
+
+procedure ptc_InitModeCGA2(XResolution, YResolution, Pages: LongInt);
+begin
+{$IFDEF logging}
+  LogLn('Initializing mode ' + strf(XResolution) + ', ' + strf(YResolution) + ' 2 colours');
+{$ENDIF logging}
+  { open the console }
+  ptc_InternalOpen(ParamStr(0), XResolution, YResolution, PTCFormat8, Pages);
+  PTCWidth := XResolution;
+  PTCHeight := YResolution;
+  CurrentActivePage := 0;
+  { create palette }
+  ptc_InitPaletteCGA2;
+  ColorMask := 1;
+end;
+
+procedure ptc_InitMode32k(XResolution, YResolution, Pages: LongInt);
+begin
+{$IFDEF logging}
+  LogLn('Initializing mode ' + strf(XResolution) + ', ' + strf(YResolution) + ' 32768 colours');
+{$ENDIF logging}
+  { open the console }
+  ptc_InternalOpen(ParamStr(0), XResolution, YResolution, PTCFormat15, Pages);
+  PTCWidth := XResolution;
+  PTCHeight := YResolution;
+  CurrentActivePage := 0;
+  ColorMask := 32767;
+end;
+
+procedure ptc_InitMode64k(XResolution, YResolution, Pages: LongInt);
+begin
+{$IFDEF logging}
+  LogLn('Initializing mode ' + strf(XResolution) + ', ' + strf(YResolution) + ' 65536 colours');
+{$ENDIF logging}
+  { open the console }
+  ptc_InternalOpen(ParamStr(0), XResolution, YResolution, PTCFormat16, Pages);
+  PTCWidth := XResolution;
+  PTCHeight := YResolution;
+  CurrentActivePage := 0;
+  ColorMask := 65535;
+end;
+
+
+procedure ptc_Init640x200x16;
+begin
+  ptc_InitMode16_CGAEmu(640, 200, 3);
+end;
+
+procedure ptc_Init640x350x16;
+begin
+  ptc_InitMode16(640, 350, 2);
+end;
+
+procedure ptc_Init640x480x16;
+begin
+  ptc_InitMode16(640, 480, 1);
+end;
+
+procedure ptc_Init800x600x16;
+begin
+  ptc_InitMode16(800, 600, 2);
+end;
+
+procedure ptc_Init1024x768x16;
+begin
+  ptc_InitMode16(1024, 768, 2);
+end;
+
+procedure ptc_Init1280x1024x16;
+begin
+  ptc_InitMode16(1280, 1024, 2);
+end;
+
+procedure ptc_Init320x200x4cgaC0;
+begin
+  ptc_InitModeCGA4(320, 200, 0);
+end;
+
+procedure ptc_Init320x200x4cgaC1;
+begin
+  ptc_InitModeCGA4(320, 200, 1);
+end;
+
+procedure ptc_Init320x200x4cgaC2;
+begin
+  ptc_InitModeCGA4(320, 200, 2);
+end;
+
+procedure ptc_Init320x200x4cgaC3;
+begin
+  ptc_InitModeCGA4(320, 200, 3);
+end;
+
+procedure ptc_Init640x200x2;
+begin
+  ptc_InitModeCGA2(640, 200, 1);
+end;
+
+procedure ptc_Init640x480x2;
+begin
+  ptc_InitModeCGA2(640, 480, 1);
+end;
+
+procedure ptc_Init720x348x2;
+begin
+  DummyHGCBkColor := 0;
+  ptc_InitModeCGA2(720, 348, 2);
+end;
+
+procedure ptc_Init320x200x256;
+begin
+  ptc_InitMode256(320, 200, 4);
+end;
+
+procedure ptc_Init640x400x256;
+begin
+  ptc_InitMode256(640, 400, 2);
+end;
+
+procedure ptc_Init640x480x256;
+begin
+  ptc_InitMode256(640, 480, 2);
+end;
+
+procedure ptc_Init800x600x256;
+begin
+  ptc_InitMode256(800, 600, 2);
+end;
+
+procedure ptc_Init1024x768x256;
+begin
+  ptc_InitMode256(1024, 768, 2);
+end;
+
+procedure ptc_Init1280x1024x256;
+begin
+  ptc_InitMode256(1280, 1024, 2);
+end;
+
+procedure ptc_Init320x200x32k;
+begin
+  ptc_InitMode32k(320, 200, 2);
+end;
+
+procedure ptc_Init640x480x32k;
+begin
+  ptc_InitMode32k(640, 480, 2);
+end;
+
+procedure ptc_Init800x600x32k;
+begin
+  ptc_InitMode32k(800, 600, 2);
+end;
+
+procedure ptc_Init1024x768x32k;
+begin
+  ptc_InitMode32k(1024, 768, 2);
+end;
+
+procedure ptc_Init1280x1024x32k;
+begin
+  ptc_InitMode32k(1280, 1024, 2);
+end;
+
+procedure ptc_Init320x200x64k;
+begin
+  ptc_InitMode64k(320, 200, 2);
+end;
+
+procedure ptc_Init640x480x64k;
+begin
+  ptc_InitMode64k(640, 480, 2);
+end;
+
+procedure ptc_Init800x600x64k;
+begin
+  ptc_InitMode64k(800, 600, 2);
+end;
+
+procedure ptc_Init1024x768x64k;
+begin
+  ptc_InitMode64k(1024, 768, 2);
+end;
+
+procedure ptc_Init1280x1024x64k;
+begin
+  ptc_InitMode64k(1280, 1024, 2);
+end;
+
+procedure ptc_SetVisualPage(page: word);
+begin
+  if page > HardwarePages then
+    exit;
+
+  PTCWrapperObject.SetVisualPage(page);
+end;
+
+procedure ptc_SetActivePage(page: word);
+begin
+  if page > HardwarePages then
+    exit;
+
+  CurrentActivePage := page;
+end;
+
+{ compatible with TP7's HERC.BGI }
+procedure SetBkColorHGC720(ColorNum: Word);
+begin
+  if ColorNum > 15 then
+    exit;
+  DummyHGCBkColor := ColorNum;
+end;
+
+{ compatible with TP7's HERC.BGI }
+function GetBkColorHGC720: Word;
+begin
+  GetBkColorHGC720 := DummyHGCBkColor;
+end;
+
+procedure SetBkColorCGA320(ColorNum: Word);
+begin
+  if ColorNum > 15 then
+    exit;
+  CurrentCGABkColor := ColorNum;
+
+  ptc_SetEGAPalette(0, ((ColorNum shl 1) and $10) or (ColorNum and $07));
+end;
+
+function GetBkColorCGA320: Word;
+begin
+  GetBkColorCGA320 := CurrentCGABkColor;
+end;
+
+{yes, TP7 CGA.BGI behaves *exactly* like that}
+procedure SetBkColorCGA640(ColorNum: Word);
+begin
+  if ColorNum > 15 then
+    exit;
+  CurrentCGABkColor := ColorNum;
+  if ColorNum = 0 then
+    exit;
+  ptc_SetEGAPalette(1, ((ColorNum shl 1) and $10) or (ColorNum and $07));
+end;
+
+function GetBkColorCGA640: Word;
+begin
+  GetBkColorCGA640 := CurrentCGABkColor;
+end;
+
+Function ClipCoords (Var X,Y : smallint) : Boolean;
+{ Adapt to viewport, return TRUE if still in viewport,
+  false if outside viewport}
+
+begin
+  X:= X + StartXViewPort;
+  Y:= Y + StartYViewPort;
+  ClipCoords:=Not ClipPixels;
+  if ClipPixels then
+    Begin
+    ClipCoords:=(X < StartXViewPort) or (X > (StartXViewPort + ViewWidth));
+    ClipCoords:=ClipCoords or
+               ((Y < StartYViewPort) or (Y > (StartYViewPort + ViewHeight)));
+    ClipCoords:=Not ClipCoords;
+    end;
+end;
+
+procedure ptc_DirectPixelProc_16bpp(X,Y: smallint);
+
+var color:word;
+    pixels:Pword;
+
+begin
+//  Writeln('ptc_DirectPixelProc_16bpp(', X, ', ', Y, ')');
+  pixels := ptc_surface_lock;
+  case CurrentWriteMode of
+    XORPut:
+      begin
+        pixels[x+y*PTCWidth] := pixels[x+y*PTCWidth] xor CurrentColor;
+      end;
+    OrPut:
+      begin
+        pixels[x+y*PTCWidth] := pixels[x+y*PTCWidth] or CurrentColor;
+      end;
+    AndPut:
+      begin
+        pixels[x+y*PTCWidth] := pixels[x+y*PTCWidth] and CurrentColor;
+      end;
+    NotPut:
+      begin
+        pixels[x+y*PTCWidth] := CurrentColor xor $FFFF;
+      end
+  else
+    pixels[x+y*PTCWidth] := CurrentColor;
+  end;
+  ptc_surface_unlock;
+  ptc_update;
+end;
+
+procedure ptc_DirectPixelProc_8bpp(X,Y: smallint);
+
+var color:word;
+    pixels:PByte;
+
+begin
+//  Writeln('ptc_DirectPixelProc_8bpp(', X, ', ', Y, ')');
+  pixels := ptc_surface_lock;
+  case CurrentWriteMode of
+    XORPut:
+      begin
+        pixels[x+y*PTCWidth] := pixels[x+y*PTCWidth] xor (CurrentColor and ColorMask);
+      end;
+    OrPut:
+      begin
+        pixels[x+y*PTCWidth] := pixels[x+y*PTCWidth] or (CurrentColor and ColorMask);
+      end;
+    AndPut:
+      begin
+        pixels[x+y*PTCWidth] := pixels[x+y*PTCWidth] and (CurrentColor and ColorMask);
+      end;
+    NotPut:
+      begin
+        pixels[x+y*PTCWidth] := CurrentColor xor ColorMask;
+      end
+  else
+    pixels[x+y*PTCWidth] := CurrentColor and ColorMask;
+  end;
+  ptc_surface_unlock;
+  ptc_update;
+end;
+
+procedure ptc_putpixelproc_16bpp(X,Y:smallint;Color:Word);
+
+var pixels:Pword;
+
+begin
+//  Writeln('ptc_putpixelproc_16bpp(', X, ', ', Y, ', ', Color, ')');
+  if clipcoords(X,Y) then
+    begin
+      pixels := ptc_surface_lock;
+      {Plot the pixel on the surface.}
+      pixels[x+y*PTCWidth] := color;
+      ptc_surface_unlock;
+      ptc_update;
+    end;
+end;
+
+function ptc_getpixelproc_16bpp(X,Y: smallint):word;
+
+var pixels:Pword;
+
+begin
+  if clipcoords(X,Y) then
+    begin
+      pixels := ptc_surface_lock;
+      {Get the pixel from the surface.}
+      ptc_getpixelproc_16bpp:=pixels[x+y*PTCWidth];
+      ptc_surface_unlock;
+    end;
+end;
+
+procedure ptc_PutPixelProc_8bpp(X,Y:smallint;Color:Word);
+
+var pixels:PByte;
+
+begin
+//  Writeln('ptc_PutPixelProc_8bpp(', X, ', ', Y, ', ', Color, ')');
+  if clipcoords(X,Y) then
+    begin
+      pixels := ptc_surface_lock;
+      {Plot the pixel on the surface.}
+      pixels[x+y*PTCWidth]:=color and ColorMask;
+      ptc_surface_unlock;
+      ptc_update;
+    end;
+end;
+
+function ptc_GetPixelProc_8bpp(X,Y: smallint):word;
+
+var pixels:PByte;
+
+begin
+  if clipcoords(X,Y) then
+    begin
+      pixels := ptc_surface_lock;
+      {Get the pixel from the surface.}
+      ptc_GetPixelProc_8bpp:=pixels[x+y*PTCWidth] and ColorMask;
+      ptc_surface_unlock;
+      ptc_update;
+    end;
+end;
+
+
+{ Bitmap utilities }
+{type
+  PBitmap = ^TBitmap;
+  TBitmap = record
+            Width, Height: smallint;
+            Data: record end;
+            end;
+}
+
+procedure ptc_putimageproc (X,Y: smallint; var Bitmap; BitBlt: Word);
+begin
+end;
+
+procedure ptc_getimageproc (X1,Y1,X2,Y2: smallint; Var Bitmap);
+begin
+end;
+
+function  ptc_imagesizeproc (X1,Y1,X2,Y2: smallint): longint;
+begin
+end;
+
+procedure ptc_HLineProc_16bpp(x, x2,y : smallint);
+
+var pixels:Pword;
+    i:word;
+    xtmp: smallint;
+
+begin
+//  Writeln('ptc_HLineProc_16bpp(', x, ', ', x2, ', ', y, ')');
+  { must we swap the values? }
+  if x >= x2 then
+  begin
+    xtmp := x2;
+    x2 := x;
+    x:= xtmp;
+  end;
+
+  inc(x,StartXViewPort);
+  inc(x2,StartXViewPort);
+  inc(y,StartYViewPort);
+  if ClipPixels then
+  begin
+    if LineClipped(x,y,x2,y,StartXViewPort,StartYViewPort,
+               StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
+      exit;
+  end;
+
+  pixels := ptc_surface_lock;
+
+  case CurrentWriteMode of
+    XORPut:
+      begin
+        for i:=x to x2 do
+          pixels[i+y*PTCWidth] := pixels[i+y*PTCWidth] xor CurrentColor;
+      end;
+    OrPut:
+      begin
+        for i:=x to x2 do
+          pixels[i+y*PTCWidth] := pixels[i+y*PTCWidth] or CurrentColor;
+      end;
+    AndPut:
+      begin
+        for i:=x to x2 do
+          pixels[i+y*PTCWidth] := pixels[i+y*PTCWidth] and CurrentColor;
+      end;
+    NotPut:
+      begin
+        for i:=x to x2 do
+          pixels[i+y*PTCWidth] := CurrentColor xor $FFFF;
+      end
+  else
+    for i:=x to x2 do
+      pixels[i+y*PTCWidth] := CurrentColor;
+  end;
+
+  ptc_surface_unlock;
+  ptc_update;
+end;
+
+procedure ptc_VLineProc_16bpp(x,y,y2 : smallint);
+var pixels:PWord;
+    i:word;
+    ytmp: smallint;
+begin
+  if y >= y2 then
+   begin
+     ytmp := y2;
+     y2 := y;
+     y:= ytmp;
+   end;
+
+  inc(x,StartXViewPort);
+  inc(y,StartYViewPort);
+  inc(y2,StartYViewPort);
+  if ClipPixels then
+  begin
+    if LineClipped(x,y,x,y2,StartXViewPort,StartYViewPort,
+          StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
+      exit;
+  end;
+
+  pixels := ptc_surface_lock;
+
+  case CurrentWriteMode of
+    XORPut:
+      begin
+        for i:=y to y2 do
+          pixels[x+i*PTCWidth] := pixels[x+i*PTCWidth] xor CurrentColor;
+      end;
+    OrPut:
+      begin
+        for i:=y to y2 do
+          pixels[x+i*PTCWidth] := pixels[x+i*PTCWidth] or CurrentColor;
+      end;
+    AndPut:
+      begin
+        for i:=y to y2 do
+          pixels[x+i*PTCWidth] := pixels[x+i*PTCWidth] and CurrentColor;
+      end;
+    NotPut:
+      begin
+        for i:=y to y2 do
+          pixels[x+i*PTCWidth] := CurrentColor xor $FFFF;
+      end
+  else
+    for i:=y to y2 do
+      pixels[x+i*PTCWidth] := CurrentColor;
+  end;
+
+  ptc_surface_unlock;
+  ptc_update;
+end;
+
+procedure ptc_HLineProc_8bpp(x, x2,y : smallint);
+
+var pixels:PByte;
+    i:word;
+    xtmp: smallint;
+
+begin
+//  Writeln('ptc_HLineProc_8bpp(', x, ', ', x2, ', ', y, ')');
+  { must we swap the values? }
+  if x >= x2 then
+  begin
+    xtmp := x2;
+    x2 := x;
+    x:= xtmp;
+  end;
+
+  inc(x,StartXViewPort);
+  inc(x2,StartXViewPort);
+  inc(y,StartYViewPort);
+  if ClipPixels then
+  begin
+    if LineClipped(x,y,x2,y,StartXViewPort,StartYViewPort,
+               StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
+      exit;
+  end;
+
+  pixels := ptc_surface_lock;
+
+  case CurrentWriteMode of
+    XORPut:
+      begin
+        for i:=x to x2 do
+          pixels[i+y*PTCWidth] := pixels[i+y*PTCWidth] xor (CurrentColor and ColorMask);
+      end;
+    OrPut:
+      begin
+        for i:=x to x2 do
+          pixels[i+y*PTCWidth] := pixels[i+y*PTCWidth] or (CurrentColor and ColorMask);
+      end;
+    AndPut:
+      begin
+        for i:=x to x2 do
+          pixels[i+y*PTCWidth] := pixels[i+y*PTCWidth] and (CurrentColor and ColorMask);
+      end;
+    NotPut:
+      begin
+        for i:=x to x2 do
+          pixels[i+y*PTCWidth] := (CurrentColor and ColorMask) xor ColorMask;
+      end
+  else
+    for i:=x to x2 do
+      pixels[i+y*PTCWidth] := CurrentColor and ColorMask;
+  end;
+
+  ptc_surface_unlock;
+  ptc_update;
+end;
+
+procedure ptc_VLineProc_8bpp(x,y,y2 : smallint);
+
+var pixels:PByte;
+    i:word;
+    ytmp: smallint;
+
+begin
+//  Writeln('ptc_VLineProc_8bpp(', x, ', ', y, ', ', y2, ')');
+  { must we swap the values? }
+    if y >= y2 then
+     Begin
+       ytmp := y2;
+       y2 := y;
+       y:= ytmp;
+     end;
+
+  inc(x,StartXViewPort);
+  inc(y,StartYViewPort);
+  inc(y2,StartYViewPort);
+  if ClipPixels then
+  begin
+    if LineClipped(x,y,x,y2,StartXViewPort,StartYViewPort,
+          StartXViewPort+ViewWidth, StartYViewPort+ViewHeight) then
+      exit;
+  end;
+
+  pixels := ptc_surface_lock;
+
+  case CurrentWriteMode of
+    XORPut:
+      begin
+        for i:=y to y2 do
+          pixels[x+i*PTCWidth] := pixels[x+i*PTCWidth] xor (CurrentColor and ColorMask);
+      end;
+    OrPut:
+      begin
+        for i:=y to y2 do
+          pixels[x+i*PTCWidth] := pixels[x+i*PTCWidth] or (CurrentColor and ColorMask);
+      end;
+    AndPut:
+      begin
+        for i:=y to y2 do
+          pixels[x+i*PTCWidth] := pixels[x+i*PTCWidth] and (CurrentColor and ColorMask);
+      end;
+    NotPut:
+      begin
+        for i:=y to y2 do
+          pixels[x+i*PTCWidth] := (CurrentColor and ColorMask) xor ColorMask;
+      end
+  else
+    for i:=y to y2 do
+      pixels[x+i*PTCWidth] := CurrentColor and ColorMask;
+  end;
+
+  ptc_surface_unlock;
+  ptc_update;
+end;
+
+
+
+
+procedure ptc_vlineproc (x,y,y2: smallint);
+begin
+end;
+
+procedure ptc_clrviewproc_16bpp;
+
+Var I,Xmax : longint;
+
+begin
+  Xmax:=StartXViewPort+ViewWidth-1;
+  For i:=StartYViewPort to StartYViewPort+ViewHeight-1 do
+    ptc_HLineProc_16bpp(0,viewwidth,i);
+  { reset coordinates }
+  CurrentX := 0;
+  CurrentY := 0;
+end;
+
+procedure ptc_patternlineproc (x1,x2,y: smallint);
+begin
+end;
+
+procedure ptc_ellipseproc  (X,Y: smallint;XRadius: word;
+  YRadius:word; stAngle,EndAngle: word; fp: PatternLineProc);
+begin
+end;
+
+procedure ptc_lineproc (X1, Y1, X2, Y2 : smallint);
+begin
+end;
+
+procedure ptc_getscanlineproc (X1,X2,Y : smallint; var data);
+begin
+end;
+
+procedure ptc_setactivepageproc (page: word);
+begin
+end;
+
+procedure ptc_setvisualpageproc (page: word);
+begin
+end;
+
+
+procedure ptc_savestateproc;
+begin
+end;
+
+procedure ptc_restorestateproc;
+begin
+end;
+
+procedure ptc_SetRGBAllPaletteProc(const Palette: PaletteType);
+begin
+  {...}
+end;
+
+procedure ptc_setrgbpaletteproc(ColorNum, RedValue, GreenValue, BlueValue: smallint);
+begin
+  { NOTE: this makes the function compatible to the go32v2 graph implementation, but
+    *not* with TP7 }
+  if EGAPaletteEnabled then
+    ColorNum := DefaultEGAPalette[ColorNum and 15];
+
+  ptc_SetVGAPalette(ColorNum,RedValue shr 2,GreenValue shr 2,BlueValue shr 2);
+end;
+
+procedure ptc_getrgbpaletteproc (ColorNum: smallint;
+                                    var RedValue, GreenValue, BlueValue: smallint);
+begin
+  { NOTE: this makes the function compatible to the go32v2 graph implementation, but
+    *not* with TP7 }
+  if EGAPaletteEnabled then
+    ColorNum := DefaultEGAPalette[ColorNum and 15];
+
+  RedValue := VGAPalette[ColorNum, 0] shl 2;
+  GreenValue := VGAPalette[ColorNum, 1] shl 2;
+  BlueValue := VGAPalette[ColorNum, 2] shl 2;
+end;
+
+{************************************************************************}
+{*                       General routines                               *}
+{************************************************************************}
+
+ procedure CloseGraph;
+ Begin
+    If not isgraphmode then
+      begin
+        _graphresult := grnoinitgraph;
+        exit
+      end;
+//    SetRawMode(False);
+    RestoreVideoState;
+    isgraphmode := false;
+ end;
+
+  function QueryAdapterInfo:PModeInfo;
+  { This routine returns the head pointer to the list }
+  { of supported graphics modes.                      }
+  { Returns nil if no graphics mode supported.        }
+  { This list is READ ONLY!                           }
+  var
+    PTCModeList: PPTCMode;
+
+    function ModeListEmpty: Boolean;
+    begin
+      ModeListEmpty := (PTCModeList = nil) or (not PTCModeList[0].Valid);
+    end;
+
+    function ContainsExactResolution(AWidth, AHeight: Integer): Boolean;
+    var
+      I: Integer;
+    begin
+      if ModeListEmpty then
+      begin
+        ContainsExactResolution := False;
+        exit;
+      end;
+
+      I := 0;
+      while (PTCModeList[I].Valid) do
+      begin
+        with PTCModeList[I] do
+          if (Width = AWidth) and
+             (Height = AHeight) then
+          begin
+            ContainsExactResolution := True;
+            exit;
+          end;
+        Inc(I);
+      end;
+      ContainsExactResolution := False;
+    end;
+
+    function ContainsAtLeast(AWidth, AHeight: Integer): Boolean;
+    var
+      I: Integer;
+    begin
+      if ModeListEmpty then
+      begin
+        ContainsAtLeast := False;
+        exit;
+      end;
+
+      I := 0;
+      while (PTCModeList[I].Valid) do
+      begin
+        with PTCModeList[I] do
+          if (Width >= AWidth) and
+             (Height >= AHeight) then
+          begin
+            ContainsAtLeast := True;
+            exit;
+          end;
+        Inc(I);
+      end;
+      ContainsAtLeast := False;
+    end;
+
+   var
+    graphmode:Tmodeinfo;
+    d{,i} : longint;
+    ws,hs:string[5];
+
+   const depths:array[0..3] of byte=(8,16,24,32);
+         colours:array[0..3] of longint=(256,65536,16777216,16777216);
+         depth_names:array[0..3] of string[5]=('256','64K','16M','16M32');
+
+   begin
+     QueryAdapterInfo := ModeList;
+     { If the mode listing already exists... }
+     { simply return it, without changing    }
+     { anything...                           }
+     if assigned(ModeList) then
+       exit;
+
+     PTCModeList := PTCWrapperObject.Modes;
+
+     Has320x200 := ContainsExactResolution(320, 200);
+     Has320x240 := ContainsExactResolution(320, 240);
+
+     SaveVideoState:=@ptc_savevideostate;
+     RestoreVideoState:=@ptc_restorevideostate;
+{     if PTCConsole = nil then
+       PTCConsole := TPTCConsole.Create;}
+//     ptcmode:=ptcconsole.modes;
+//     i:=0;
+{     initmode(graphmode);
+     with graphmode do
+       begin
+         modenumber:=0;
+         drivernumber:=ptcgraph._ptc;
+         maxx:=639;
+         maxy:=479;
+         modename:='PTC_640x480x64K';
+         maxcolor:=65536;
+         palettesize:=65536;
+         hardwarepages:=0;
+         InitMode       := @ptc_InitModeProc;
+         DirectPutPixel := @ptc_DirectPixelProc_16bpp;
+         GetPixel       := @ptc_GetPixelProc_16bpp;
+         PutPixel       := @ptc_PutPixelProc_16bpp;
+         SetRGBPalette  := @ptc_SetRGBPaletteProc;
+         GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+         HLine          := @ptc_HLineProc_16bpp;
+       end;
+     addmode(graphmode);}
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=CGAC0;
+       DriverNumber := CGA;
+       HardwarePages := 0;
+       ModeName:='320 x 200 CGA C0';
+       MaxColor := 4;
+       DirectColor := FALSE;
+       PaletteSize := 16;
+       MaxX := 319;
+       MaxY := 199;
+       InitMode       := @ptc_Init320x200x4cgaC0;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       SetBkColor     := @SetBkColorCGA320;
+       GetBkColor     := @GetBkColorCGA320;
+
+       XAspect := 8333;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=CGAC1;
+       DriverNumber := CGA;
+       HardwarePages := 0;
+       ModeName:='320 x 200 CGA C1';
+       MaxColor := 4;
+       DirectColor := FALSE;
+       PaletteSize := 16;
+       MaxX := 319;
+       MaxY := 199;
+       InitMode       := @ptc_Init320x200x4cgaC1;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       SetBkColor     := @SetBkColorCGA320;
+       GetBkColor     := @GetBkColorCGA320;
+
+       XAspect := 8333;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=CGAC2;
+       DriverNumber := CGA;
+       HardwarePages := 0;
+       ModeName:='320 x 200 CGA C2';
+       MaxColor := 4;
+       DirectColor := FALSE;
+       PaletteSize := 16;
+       MaxX := 319;
+       MaxY := 199;
+       InitMode       := @ptc_Init320x200x4cgaC2;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       SetBkColor     := @SetBkColorCGA320;
+       GetBkColor     := @GetBkColorCGA320;
+
+       XAspect := 8333;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=CGAC3;
+       DriverNumber := CGA;
+       HardwarePages := 0;
+       ModeName:='320 x 200 CGA C3';
+       MaxColor := 4;
+       DirectColor := FALSE;
+       PaletteSize := 16;
+       MaxX := 319;
+       MaxY := 199;
+       InitMode       := @ptc_Init320x200x4cgaC3;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       SetBkColor     := @SetBkColorCGA320;
+       GetBkColor     := @GetBkColorCGA320;
+
+       XAspect := 8333;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=CGAHi;
+       DriverNumber := CGA;
+       HardwarePages := 0;
+       ModeName:='640 x 200 CGA';
+       MaxColor := 2;
+       DirectColor := FALSE;
+       PaletteSize := 16;
+       MaxX := 639;
+       MaxY := 199;
+       InitMode       := @ptc_Init640x200x2;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       SetBkColor     := @SetBkColorCGA640;
+       GetBkColor     := @GetBkColorCGA640;
+
+       XAspect := 4167;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=MCGAC0;
+       DriverNumber := MCGA;
+       HardwarePages := 0;
+       ModeName:='320 x 200 CGA C0';
+       MaxColor := 4;
+       DirectColor := FALSE;
+       PaletteSize := 16;
+       MaxX := 319;
+       MaxY := 199;
+       InitMode       := @ptc_Init320x200x4cgaC0;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       SetBkColor     := @SetBkColorCGA320;
+       GetBkColor     := @GetBkColorCGA320;
+
+       XAspect := 8333;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=MCGAC1;
+       DriverNumber := MCGA;
+       HardwarePages := 0;
+       ModeName:='320 x 200 CGA C1';
+       MaxColor := 4;
+       DirectColor := FALSE;
+       PaletteSize := 16;
+       MaxX := 319;
+       MaxY := 199;
+       InitMode       := @ptc_Init320x200x4cgaC1;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       SetBkColor     := @SetBkColorCGA320;
+       GetBkColor     := @GetBkColorCGA320;
+
+       XAspect := 8333;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=MCGAC2;
+       DriverNumber := MCGA;
+       HardwarePages := 0;
+       ModeName:='320 x 200 CGA C2';
+       MaxColor := 4;
+       DirectColor := FALSE;
+       PaletteSize := 16;
+       MaxX := 319;
+       MaxY := 199;
+       InitMode       := @ptc_Init320x200x4cgaC2;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       SetBkColor     := @SetBkColorCGA320;
+       GetBkColor     := @GetBkColorCGA320;
+
+       XAspect := 8333;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=MCGAC3;
+       DriverNumber := MCGA;
+       HardwarePages := 0;
+       ModeName:='320 x 200 CGA C3';
+       MaxColor := 4;
+       DirectColor := FALSE;
+       PaletteSize := 16;
+       MaxX := 319;
+       MaxY := 199;
+       InitMode       := @ptc_Init320x200x4cgaC3;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       SetBkColor     := @SetBkColorCGA320;
+       GetBkColor     := @GetBkColorCGA320;
+
+       XAspect := 8333;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=MCGAMed;
+       DriverNumber := MCGA;
+       HardwarePages := 0;
+       ModeName:='640 x 200 CGA';
+       MaxColor := 2;
+       DirectColor := FALSE;
+       PaletteSize := 16;
+       MaxX := 639;
+       MaxY := 199;
+       InitMode       := @ptc_Init640x200x2;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       SetBkColor     := @SetBkColorCGA640;
+       GetBkColor     := @GetBkColorCGA640;
+
+       XAspect := 4167;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=MCGAHi;
+       DriverNumber := MCGA;
+       HardwarePages := 0;
+       ModeName:='640 x 480 MCGA';
+       MaxColor := 2;
+       DirectColor := FALSE;
+       PaletteSize := 16;
+       MaxX := 639;
+       MaxY := 479;
+       InitMode       := @ptc_Init640x480x2;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       XAspect := 10000;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     if ContainsAtLeast(720, 348) then
+     begin
+       InitMode(graphmode);
+       with graphmode do
+       begin
+         ModeNumber:=HercMonoHi;
+         DriverNumber := HercMono;
+         HardwarePages := 1;
+         ModeName:='720 x 348 HERCULES';
+         MaxColor := 2;
+         DirectColor := FALSE;
+         PaletteSize := 16;
+         MaxX := 719;
+         MaxY := 347;
+         InitMode       := @ptc_Init720x348x2;
+         DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+         PutPixel       := @ptc_PutPixelProc_8bpp;
+         GetPixel       := @ptc_GetPixelProc_8bpp;
+         SetRGBPalette  := @ptc_SetRGBPaletteProc;
+         GetRGBPalette  := @ptc_GetRGBPaletteProc;
+         HLine          := @ptc_HLineProc_8bpp;
+         VLine          := @ptc_VLineProc_8bpp;
+         SetVisualPage  := @ptc_SetVisualPage;
+         SetActivePage  := @ptc_SetActivePage;
+         SetBkColor     := @SetBkColorHGC720;
+         GetBkColor     := @GetBkColorHGC720;
+         XAspect := 7500;
+         YAspect := 10000;
+       end;
+       AddMode(graphmode);
+     end;
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=EGALo;
+       DriverNumber := EGA;
+       HardwarePages := 2;
+       ModeName:='640 x 200 EGA';
+       MaxColor := 16;
+       DirectColor := FALSE;
+       PaletteSize := MaxColor;
+       MaxX := 639;
+       MaxY := 199;
+       InitMode       := @ptc_Init640x200x16;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       XAspect := 4500;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=EGAHi;
+       DriverNumber := EGA;
+       HardwarePages := 1;
+       ModeName:='640 x 350 EGA';
+       MaxColor := 16;
+       DirectColor := FALSE;
+       PaletteSize := MaxColor;
+       MaxX := 639;
+       MaxY := 349;
+       InitMode       := @ptc_Init640x350x16;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       XAspect := 7750;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=VGALo;
+       DriverNumber := VGA;
+       HardwarePages := 2;
+       ModeName:='640 x 200 EGA';
+       MaxColor := 16;
+       DirectColor := FALSE;
+       PaletteSize := MaxColor;
+       MaxX := 639;
+       MaxY := 199;
+       InitMode       := @ptc_Init640x200x16;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       XAspect := 4500;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=VGAMed;
+       DriverNumber := VGA;
+       HardwarePages := 1;
+       ModeName:='640 x 350 EGA';
+       MaxColor := 16;
+       DirectColor := FALSE;
+       PaletteSize := MaxColor;
+       MaxX := 639;
+       MaxY := 349;
+       InitMode       := @ptc_Init640x350x16;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       XAspect := 7750;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=VGAHi;
+       DriverNumber := VGA;
+       HardwarePages := 0;
+       ModeName:='640 x 480 VGA';
+       MaxColor := 16;
+       DirectColor := FALSE;
+       PaletteSize := MaxColor;
+       MaxX := 639;
+       MaxY := 479;
+       InitMode       := @ptc_Init640x480x16;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       XAspect := 10000;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=0;
+       DriverNumber := LowRes;
+       HardwarePages := 0;
+       ModeName:='320 x 200 VGA';
+       MaxColor := 256;
+       DirectColor := FALSE;
+       PaletteSize := MaxColor;
+       MaxX := 319;
+       MaxY := 199;
+       InitMode       := @ptc_Init320x200x256;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+       //SetAllPalette  := @ptc_SetRGBAllPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       XAspect := 8333;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=1;
+       DriverNumber := LowRes;
+       HardwarePages := 3;
+       ModeName:='320 x 200 ModeX';
+       MaxColor := 256;
+       DirectColor := FALSE;
+       PaletteSize := MaxColor;
+       MaxX := 319;
+       MaxY := 199;
+       InitMode       := @ptc_Init320x200x256;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+       //SetAllPalette  := @ptc_SetRGBAllPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       XAspect := 8333;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=m640x400x256;
+       DriverNumber := VESA;
+       HardwarePages := 1;
+       ModeName:='640 x 400 VESA';
+       MaxColor := 256;
+       DirectColor := FALSE;
+       PaletteSize := MaxColor;
+       MaxX := 639;
+       MaxY := 399;
+       InitMode       := @ptc_Init640x400x256;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+       //SetAllPalette  := @ptc_SetRGBAllPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       XAspect := 8333;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber:=m640x480x256;
+       DriverNumber := VESA;
+       HardwarePages := 1;
+       ModeName:='640 x 480 VESA';
+       MaxColor := 256;
+       DirectColor := FALSE;
+       PaletteSize := MaxColor;
+       MaxX := 639;
+       MaxY := 479;
+       InitMode       := @ptc_Init640x480x256;
+       DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+       PutPixel       := @ptc_PutPixelProc_8bpp;
+       GetPixel       := @ptc_GetPixelProc_8bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+       //SetAllPalette  := @ptc_SetRGBAllPaletteProc;
+
+       HLine          := @ptc_HLineProc_8bpp;
+       VLine          := @ptc_VLineProc_8bpp;
+
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       XAspect := 10000;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber := m320x200x32k;
+       DriverNumber := VESA;
+       HardwarePages := 1;
+       ModeName:='320 x 200 VESA';
+       MaxColor := 32768;
+       DirectColor := TRUE;
+       PaletteSize := MaxColor;
+       MaxX := 319;
+       MaxY := 199;
+       InitMode       := @ptc_Init320x200x32k;
+       DirectPutPixel := @ptc_DirectPixelProc_16bpp;
+       PutPixel       := @ptc_PutPixelProc_16bpp;
+       GetPixel       := @ptc_GetPixelProc_16bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+       HLine          := @ptc_HLineProc_16bpp;
+       VLine          := @ptc_VLineProc_16bpp;
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       XAspect := 8333;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber := m640x480x32k;
+       DriverNumber := VESA;
+       HardwarePages := 1;
+       ModeName:='640 x 480 VESA';
+       MaxColor := 32768;
+       DirectColor := TRUE;
+       PaletteSize := MaxColor;
+       MaxX := 639;
+       MaxY := 479;
+       InitMode       := @ptc_Init640x480x32k;
+       DirectPutPixel := @ptc_DirectPixelProc_16bpp;
+       PutPixel       := @ptc_PutPixelProc_16bpp;
+       GetPixel       := @ptc_GetPixelProc_16bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+       HLine          := @ptc_HLineProc_16bpp;
+       VLine          := @ptc_VLineProc_16bpp;
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       XAspect := 10000;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber := m320x200x64k;
+       DriverNumber := VESA;
+       HardwarePages := 1;
+       ModeName:='320 x 200 VESA';
+       MaxColor := 65536;
+       DirectColor := TRUE;
+       PaletteSize := MaxColor;
+       MaxX := 319;
+       MaxY := 199;
+       InitMode       := @ptc_Init320x200x64k;
+       DirectPutPixel := @ptc_DirectPixelProc_16bpp;
+       PutPixel       := @ptc_PutPixelProc_16bpp;
+       GetPixel       := @ptc_GetPixelProc_16bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+       HLine          := @ptc_HLineProc_16bpp;
+       VLine          := @ptc_VLineProc_16bpp;
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       XAspect := 8333;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     InitMode(graphmode);
+     with graphmode do
+     begin
+       ModeNumber := m640x480x64k;
+       DriverNumber := VESA;
+       HardwarePages := 1;
+       ModeName:='640 x 480 VESA';
+       MaxColor := 65536;
+       DirectColor := TRUE;
+       PaletteSize := MaxColor;
+       MaxX := 639;
+       MaxY := 479;
+       InitMode       := @ptc_Init640x480x64k;
+       DirectPutPixel := @ptc_DirectPixelProc_16bpp;
+       PutPixel       := @ptc_PutPixelProc_16bpp;
+       GetPixel       := @ptc_GetPixelProc_16bpp;
+       SetRGBPalette  := @ptc_SetRGBPaletteProc;
+       GetRGBPalette  := @ptc_GetRGBPaletteProc;
+       HLine          := @ptc_HLineProc_16bpp;
+       VLine          := @ptc_VLineProc_16bpp;
+       SetVisualPage  := @ptc_SetVisualPage;
+       SetActivePage  := @ptc_SetActivePage;
+
+       XAspect := 10000;
+       YAspect := 10000;
+     end;
+     AddMode(graphmode);
+
+     if ContainsAtLeast(800, 600) then
+     begin
+       InitMode(graphmode);
+       with graphmode do
+       begin
+         ModeNumber := m800x600x16;
+         DriverNumber := VESA;
+         HardwarePages := 1;
+         ModeName:='800 x 600 VESA';
+         MaxColor := 16;
+         DirectColor := FALSE;
+         PaletteSize := MaxColor;
+         MaxX := 799;
+         MaxY := 599;
+         InitMode       := @ptc_Init800x600x16;
+         DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+         PutPixel       := @ptc_PutPixelProc_8bpp;
+         GetPixel       := @ptc_GetPixelProc_8bpp;
+         SetRGBPalette  := @ptc_SetRGBPaletteProc;
+         GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+         HLine          := @ptc_HLineProc_8bpp;
+         VLine          := @ptc_VLineProc_8bpp;
+
+         SetVisualPage  := @ptc_SetVisualPage;
+         SetActivePage  := @ptc_SetActivePage;
+
+         XAspect := 10000;
+         YAspect := 10000;
+       end;
+       AddMode(graphmode);
+
+       InitMode(graphmode);
+       with graphmode do
+       begin
+         ModeNumber:=m800x600x256;
+         DriverNumber := VESA;
+         HardwarePages := 1;
+         ModeName:='800 x 600 VESA';
+         MaxColor := 256;
+         DirectColor := FALSE;
+         PaletteSize := MaxColor;
+         MaxX := 799;
+         MaxY := 599;
+         InitMode       := @ptc_Init800x600x256;
+         DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+         PutPixel       := @ptc_PutPixelProc_8bpp;
+         GetPixel       := @ptc_GetPixelProc_8bpp;
+         SetRGBPalette  := @ptc_SetRGBPaletteProc;
+         GetRGBPalette  := @ptc_GetRGBPaletteProc;
+         //SetAllPalette  := @ptc_SetRGBAllPaletteProc;
+
+         HLine          := @ptc_HLineProc_8bpp;
+         VLine          := @ptc_VLineProc_8bpp;
+
+         SetVisualPage  := @ptc_SetVisualPage;
+         SetActivePage  := @ptc_SetActivePage;
+
+         XAspect := 10000;
+         YAspect := 10000;
+       end;
+       AddMode(graphmode);
+
+       InitMode(graphmode);
+       with graphmode do
+       begin
+         ModeNumber := m800x600x32k;
+         DriverNumber := VESA;
+         HardwarePages := 1;
+         ModeName:='800 x 600 VESA';
+         MaxColor := 32768;
+         DirectColor := TRUE;
+         PaletteSize := MaxColor;
+         MaxX := 799;
+         MaxY := 599;
+         InitMode       := @ptc_Init800x600x32k;
+         DirectPutPixel := @ptc_DirectPixelProc_16bpp;
+         PutPixel       := @ptc_PutPixelProc_16bpp;
+         GetPixel       := @ptc_GetPixelProc_16bpp;
+         SetRGBPalette  := @ptc_SetRGBPaletteProc;
+         GetRGBPalette  := @ptc_GetRGBPaletteProc;
+         HLine          := @ptc_HLineProc_16bpp;
+         VLine          := @ptc_VLineProc_16bpp;
+         SetVisualPage  := @ptc_SetVisualPage;
+         SetActivePage  := @ptc_SetActivePage;
+
+         XAspect := 10000;
+         YAspect := 10000;
+       end;
+       AddMode(graphmode);
+
+       InitMode(graphmode);
+       with graphmode do
+       begin
+         ModeNumber := m800x600x64k;
+         DriverNumber := VESA;
+         HardwarePages := 1;
+         ModeName:='800 x 600 VESA';
+         MaxColor := 65536;
+         DirectColor := TRUE;
+         PaletteSize := MaxColor;
+         MaxX := 799;
+         MaxY := 599;
+         InitMode       := @ptc_Init800x600x64k;
+         DirectPutPixel := @ptc_DirectPixelProc_16bpp;
+         PutPixel       := @ptc_PutPixelProc_16bpp;
+         GetPixel       := @ptc_GetPixelProc_16bpp;
+         SetRGBPalette  := @ptc_SetRGBPaletteProc;
+         GetRGBPalette  := @ptc_GetRGBPaletteProc;
+         HLine          := @ptc_HLineProc_16bpp;
+         VLine          := @ptc_VLineProc_16bpp;
+         SetVisualPage  := @ptc_SetVisualPage;
+         SetActivePage  := @ptc_SetActivePage;
+
+         XAspect := 10000;
+         YAspect := 10000;
+       end;
+       AddMode(graphmode);
+     end;
+
+     if ContainsAtLeast(1024, 768) then
+     begin
+       InitMode(graphmode);
+       with graphmode do
+       begin
+         ModeNumber := m1024x768x16;
+         DriverNumber := VESA;
+         HardwarePages := 1;
+         ModeName:='1024 x 768 VESA';
+         MaxColor := 16;
+         DirectColor := FALSE;
+         PaletteSize := MaxColor;
+         MaxX := 1023;
+         MaxY := 767;
+         InitMode       := @ptc_Init1024x768x16;
+         DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+         PutPixel       := @ptc_PutPixelProc_8bpp;
+         GetPixel       := @ptc_GetPixelProc_8bpp;
+         SetRGBPalette  := @ptc_SetRGBPaletteProc;
+         GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+         HLine          := @ptc_HLineProc_8bpp;
+         VLine          := @ptc_VLineProc_8bpp;
+
+         SetVisualPage  := @ptc_SetVisualPage;
+         SetActivePage  := @ptc_SetActivePage;
+
+         XAspect := 10000;
+         YAspect := 10000;
+       end;
+       AddMode(graphmode);
+
+       InitMode(graphmode);
+       with graphmode do
+       begin
+         ModeNumber:=m1024x768x256;
+         DriverNumber := VESA;
+         HardwarePages := 1;
+         ModeName:='1024 x 768 VESA';
+         MaxColor := 256;
+         DirectColor := FALSE;
+         PaletteSize := MaxColor;
+         MaxX := 1023;
+         MaxY := 767;
+         InitMode       := @ptc_Init1024x768x256;
+         DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+         PutPixel       := @ptc_PutPixelProc_8bpp;
+         GetPixel       := @ptc_GetPixelProc_8bpp;
+         SetRGBPalette  := @ptc_SetRGBPaletteProc;
+         GetRGBPalette  := @ptc_GetRGBPaletteProc;
+         //SetAllPalette  := @ptc_SetRGBAllPaletteProc;
+
+         HLine          := @ptc_HLineProc_8bpp;
+         VLine          := @ptc_VLineProc_8bpp;
+
+         SetVisualPage  := @ptc_SetVisualPage;
+         SetActivePage  := @ptc_SetActivePage;
+
+         XAspect := 10000;
+         YAspect := 10000;
+       end;
+       AddMode(graphmode);
+
+       InitMode(graphmode);
+       with graphmode do
+       begin
+         ModeNumber := m1024x768x32k;
+         DriverNumber := VESA;
+         HardwarePages := 1;
+         ModeName:='1024 x 768 VESA';
+         MaxColor := 32768;
+         DirectColor := TRUE;
+         PaletteSize := MaxColor;
+         MaxX := 1023;
+         MaxY := 767;
+         InitMode       := @ptc_Init1024x768x32k;
+         DirectPutPixel := @ptc_DirectPixelProc_16bpp;
+         PutPixel       := @ptc_PutPixelProc_16bpp;
+         GetPixel       := @ptc_GetPixelProc_16bpp;
+         SetRGBPalette  := @ptc_SetRGBPaletteProc;
+         GetRGBPalette  := @ptc_GetRGBPaletteProc;
+         HLine          := @ptc_HLineProc_16bpp;
+         VLine          := @ptc_VLineProc_16bpp;
+         SetVisualPage  := @ptc_SetVisualPage;
+         SetActivePage  := @ptc_SetActivePage;
+
+         XAspect := 10000;
+         YAspect := 10000;
+       end;
+       AddMode(graphmode);
+
+       InitMode(graphmode);
+       with graphmode do
+       begin
+         ModeNumber := m1024x768x64k;
+         DriverNumber := VESA;
+         HardwarePages := 1;
+         ModeName:='1024 x 768 VESA';
+         MaxColor := 65536;
+         DirectColor := TRUE;
+         PaletteSize := MaxColor;
+         MaxX := 1023;
+         MaxY := 767;
+         InitMode       := @ptc_Init1024x768x64k;
+         DirectPutPixel := @ptc_DirectPixelProc_16bpp;
+         PutPixel       := @ptc_PutPixelProc_16bpp;
+         GetPixel       := @ptc_GetPixelProc_16bpp;
+         SetRGBPalette  := @ptc_SetRGBPaletteProc;
+         GetRGBPalette  := @ptc_GetRGBPaletteProc;
+         HLine          := @ptc_HLineProc_16bpp;
+         VLine          := @ptc_VLineProc_16bpp;
+         SetVisualPage  := @ptc_SetVisualPage;
+         SetActivePage  := @ptc_SetActivePage;
+
+         XAspect := 10000;
+         YAspect := 10000;
+       end;
+       AddMode(graphmode);
+     end;
+
+     if ContainsAtLeast(1280, 1024) then
+     begin
+       InitMode(graphmode);
+       with graphmode do
+       begin
+         ModeNumber := m1280x1024x16;
+         DriverNumber := VESA;
+         HardwarePages := 1;
+         ModeName:='1280 x 1024 VESA';
+         MaxColor := 16;
+         DirectColor := FALSE;
+         PaletteSize := MaxColor;
+         MaxX := 1279;
+         MaxY := 1023;
+         InitMode       := @ptc_Init1280x1024x16;
+         DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+         PutPixel       := @ptc_PutPixelProc_8bpp;
+         GetPixel       := @ptc_GetPixelProc_8bpp;
+         SetRGBPalette  := @ptc_SetRGBPaletteProc;
+         GetRGBPalette  := @ptc_GetRGBPaletteProc;
+
+         HLine          := @ptc_HLineProc_8bpp;
+         VLine          := @ptc_VLineProc_8bpp;
+
+         SetVisualPage  := @ptc_SetVisualPage;
+         SetActivePage  := @ptc_SetActivePage;
+
+         XAspect := 10000;
+         YAspect := 10000;
+       end;
+       AddMode(graphmode);
+
+       InitMode(graphmode);
+       with graphmode do
+       begin
+         ModeNumber:=m1280x1024x256;
+         DriverNumber := VESA;
+         HardwarePages := 1;
+         ModeName:='1280 x 1024 VESA';
+         MaxColor := 256;
+         DirectColor := FALSE;
+         PaletteSize := MaxColor;
+         MaxX := 1279;
+         MaxY := 1023;
+         InitMode       := @ptc_Init1280x1024x256;
+         DirectPutPixel := @ptc_DirectPixelProc_8bpp;
+         PutPixel       := @ptc_PutPixelProc_8bpp;
+         GetPixel       := @ptc_GetPixelProc_8bpp;
+         SetRGBPalette  := @ptc_SetRGBPaletteProc;
+         GetRGBPalette  := @ptc_GetRGBPaletteProc;
+         //SetAllPalette  := @ptc_SetRGBAllPaletteProc;
+
+         HLine          := @ptc_HLineProc_8bpp;
+         VLine          := @ptc_VLineProc_8bpp;
+
+         SetVisualPage  := @ptc_SetVisualPage;
+         SetActivePage  := @ptc_SetActivePage;
+
+         XAspect := 10000;
+         YAspect := 10000;
+       end;
+       AddMode(graphmode);
+
+       InitMode(graphmode);
+       with graphmode do
+       begin
+         ModeNumber := m1280x1024x32k;
+         DriverNumber := VESA;
+         HardwarePages := 1;
+         ModeName:='1280 x 1024 VESA';
+         MaxColor := 32768;
+         DirectColor := TRUE;
+         PaletteSize := MaxColor;
+         MaxX := 1279;
+         MaxY := 1023;
+         InitMode       := @ptc_Init1280x1024x32k;
+         DirectPutPixel := @ptc_DirectPixelProc_16bpp;
+         PutPixel       := @ptc_PutPixelProc_16bpp;
+         GetPixel       := @ptc_GetPixelProc_16bpp;
+         SetRGBPalette  := @ptc_SetRGBPaletteProc;
+         GetRGBPalette  := @ptc_GetRGBPaletteProc;
+         HLine          := @ptc_HLineProc_16bpp;
+         VLine          := @ptc_VLineProc_16bpp;
+         SetVisualPage  := @ptc_SetVisualPage;
+         SetActivePage  := @ptc_SetActivePage;
+
+         XAspect := 10000;
+         YAspect := 10000;
+       end;
+       AddMode(graphmode);
+
+       InitMode(graphmode);
+       with graphmode do
+       begin  
+         ModeNumber := m1280x1024x64k;
+         DriverNumber := VESA;
+         HardwarePages := 1;
+         ModeName:='1280 x 1024 VESA';
+         MaxColor := 65536;
+         DirectColor := TRUE;
+         PaletteSize := MaxColor;
+         MaxX := 1279;
+         MaxY := 1023;
+         InitMode       := @ptc_Init1280x1024x64k;
+         DirectPutPixel := @ptc_DirectPixelProc_16bpp;
+         PutPixel       := @ptc_PutPixelProc_16bpp;
+         GetPixel       := @ptc_GetPixelProc_16bpp;
+         SetRGBPalette  := @ptc_SetRGBPaletteProc;
+         GetRGBPalette  := @ptc_GetRGBPaletteProc;
+         HLine          := @ptc_HLineProc_16bpp;
+         VLine          := @ptc_VLineProc_16bpp;
+         SetVisualPage  := @ptc_SetVisualPage;
+         SetActivePage  := @ptc_SetActivePage;
+
+         XAspect := 10000;
+         YAspect := 10000;
+       end;
+       AddMode(graphmode);
+     end;
+
+
+
+(*
+     writeln('processing modes');
+     while ptcmode^.valid do
+       begin
+         for d:=low(depths) to high(depths) do
+           begin
+             InitMode(graphmode);
+             with graphmode do
+               begin
+                 ModeNumber:=I;
+                 DriverNumber:=ptcgraph.PTC;
+                 { MaxX is number of pixels in X direction - 1}
+                 MaxX:=ptcmode^.width-1;
+                 { same for MaxY}
+                 MaxY:=ptcmode^.height-1;
+                 str(ptcmode^.width,ws);
+                 str(ptcmode^.height,hs);
+                 modename:='PTC_'+ws+'x'+hs+'x'+depth_names[d];
+                 MaxColor := 1 shl ptcmode^.format.r * 1 shl ptcmode^.format.g *1 shl ptcmode^.format.b;
+                 writeln('mode ',modename,' ',maxcolor,'kleuren');
+                 PaletteSize := MaxColor;
+                 HardwarePages := 0;
+*)
+                 { necessary hooks ...}
+(*
+                 if (MaxColor = 16) and
+                   (LongInt(ModeInfo.Width) * LongInt(ModeInfo.Height) < 65536*4*2) then
+                  begin
+                   {Use optimized graphics routines for 4 bit EGA/VGA modes.}
+                   ScrWidth := ModeInfo.Width div 8;
+                   DirectPutPixel := @DirectPutPixel16;
+                   PutPixel := @PutPixel16;
+                   GetPixel := @GetPixel16;
+                   HLine := @HLine16;
+                   VLine := @VLine16;
+                   GetScanLine := @GetScanLine16;
+                 end
+               else
+*)
+(*
+                 begin
+                   DirectPutPixel := @ptc_DirectPixelProc;
+                   GetPixel       := @ptc_GetPixelProc;
+                   PutPixel       := @ptc_PutPixelProc;
+                   { May be implemented later:
+                   HLine          := @libvga_HLineProc;
+                   VLine          := @libvga_VLineProc;
+                   GetScanLine    := @libvga_GetScanLineProc;}
+                   ClearViewPort  := @ptc_ClrViewProc;
+                 end;
+                 SetRGBPalette  := @ptc_SetRGBPaletteProc;
+                 GetRGBPalette  := @ptc_GetRGBPaletteProc;
+                 { These are not really implemented yet:
+                 PutImage       := @libvga_PutImageProc;
+                 GetImage       := @libvga_GetImageProc;}
+{                If you use the default getimage/putimage, you also need the default
+                 imagesize! (JM)
+                 ImageSize      := @libvga_ImageSizeProc; }
+                 { Add later maybe ?
+                 SetVisualPage  := SetVisualPageProc;
+                 SetActivePage  := SetActivePageProc;
+                 Line           := @libvga_LineProc;
+                 InternalEllipse:= @libvga_EllipseProc;
+                 PatternLine    := @libvga_PatternLineProc;
+                 }
+                 InitMode       := @ptc_InitModeProc;
+               end;
+           AddMode(graphmode);
+           inc(i);
+         end;
+     end;
+*)
+  end;
+
+initialization
+  PTCFormat8 := TPTCFormat.Create(8);
+  PTCFormat15 := TPTCFormat.Create(16, $7C00, $03E0, $001F);
+  PTCFormat16 := TPTCFormat.Create(16, $F800, $07E0, $001F);
+  PTCWrapperObject := TPTCWrapperThread.Create;
+  InitializeGraph;
+finalization
+  PTCWrapperObject.Terminate;
+  PTCWrapperObject.WaitFor;
+  PTCWrapperObject.Free;
+  PTCFormat16.Free;
+  PTCFormat15.Free;
+  PTCFormat8.Free;
+end.

+ 81 - 175
packages/hermes/Makefile

@@ -1,8 +1,8 @@
 #
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2009/12/31]
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2010/11/19]
 #
 default: all
-MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded
+MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-solaris x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded mipsel-linux
 BSDs = freebsd netbsd openbsd darwin
 UNIXs = linux $(BSDs) solaris qnx haiku
 LIMIT83fs = go32v2 os2 emx watcom
@@ -266,15 +266,6 @@ endif
 PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages $(FPCDIR)/packages/base $(FPCDIR)/packages/extra)
 override PACKAGE_NAME=hermes
 override PACKAGE_VERSION=2.4.3
-I386_LOADERSSRC=src/i386/x86_main.as src/i386/x86p_cpy.as \
-	src/i386/x86pscpy.as src/i386/x86p_16.as \
-	src/i386/x86p_i8.as src/i386/x86_clr.as \
-	src/i386/x86p_32.as src/i386/x86p_s32.as
-ifeq ($(CPU_TARGET),i386)
-CPU_LOADERS=mmx_clr mmxp_32 mmx_main mmxp2_32 hm_i386
-else
-CPU_LOADERS=
-endif
 ifeq ($(FULL_TARGET),i386-linux)
 override TARGET_UNITS+=hermes
 endif
@@ -398,6 +389,9 @@ endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
 override TARGET_UNITS+=hermes
 endif
+ifeq ($(FULL_TARGET),x86_64-solaris)
+override TARGET_UNITS+=hermes
+endif
 ifeq ($(FULL_TARGET),x86_64-darwin)
 override TARGET_UNITS+=hermes
 endif
@@ -449,179 +443,45 @@ endif
 ifeq ($(FULL_TARGET),armeb-embedded)
 override TARGET_UNITS+=hermes
 endif
+ifeq ($(FULL_TARGET),mipsel-linux)
+override TARGET_UNITS+=hermes
+endif
 ifeq ($(FULL_TARGET),i386-linux)
-override TARGET_LOADERS+=$(CPU_LOADERS)
+override TARGET_LOADERS+=mmx_clr mmx_main mmxp2_32 mmxp_32 x8616lut x86_clr x86_main x86p_16 x86p_32 x86p_cpy x86p_i8 x86p_s32 x86pscpy
 endif
 ifeq ($(FULL_TARGET),i386-go32v2)
-override TARGET_LOADERS+=$(CPU_LOADERS)
+override TARGET_LOADERS+=mmx_clr mmx_main mmxp2_32 mmxp_32 x8616lut x86_clr x86_main x86p_16 x86p_32 x86p_cpy x86p_i8 x86p_s32 x86pscpy
 endif
 ifeq ($(FULL_TARGET),i386-win32)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),i386-os2)
-override TARGET_LOADERS+=$(CPU_LOADERS)
+override TARGET_LOADERS+=mmx_clr mmx_main mmxp2_32 mmxp_32 x8616lut x86_clr x86_main x86p_16 x86p_32 x86p_cpy x86p_i8 x86p_s32 x86pscpy
 endif
 ifeq ($(FULL_TARGET),i386-freebsd)
-override TARGET_LOADERS+=$(CPU_LOADERS)
+override TARGET_LOADERS+=mmx_clr mmx_main mmxp2_32 mmxp_32 x8616lut x86_clr x86_main x86p_16 x86p_32 x86p_cpy x86p_i8 x86p_s32 x86pscpy
 endif
 ifeq ($(FULL_TARGET),i386-beos)
-override TARGET_LOADERS+=$(CPU_LOADERS)
+override TARGET_LOADERS+=mmx_clr mmx_main mmxp2_32 mmxp_32 x8616lut x86_clr x86_main x86p_16 x86p_32 x86p_cpy x86p_i8 x86p_s32 x86pscpy
 endif
 ifeq ($(FULL_TARGET),i386-haiku)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),i386-netbsd)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),i386-solaris)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),i386-qnx)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),i386-netware)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),i386-openbsd)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),i386-wdosx)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),i386-darwin)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),i386-emx)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),i386-watcom)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),i386-netwlibc)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),i386-wince)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),i386-embedded)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),i386-symbian)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),m68k-linux)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),m68k-freebsd)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),m68k-netbsd)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),m68k-amiga)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),m68k-atari)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),m68k-openbsd)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),m68k-palmos)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),m68k-embedded)
-override TARGET_LOADERS+=$(CPU_LOADERS)
+override TARGET_LOADERS+=mmx_clr mmx_main mmxp2_32 mmxp_32 x8616lut x86_clr x86_main x86p_16 x86p_32 x86p_cpy x86p_i8 x86p_s32 x86pscpy
 endif
-ifeq ($(FULL_TARGET),powerpc-linux)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),powerpc-netbsd)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),powerpc-amiga)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),powerpc-macos)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),powerpc-darwin)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),powerpc-morphos)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),powerpc-embedded)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),sparc-linux)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),sparc-netbsd)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),sparc-solaris)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),sparc-embedded)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),x86_64-linux)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),x86_64-freebsd)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),x86_64-darwin)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),x86_64-win64)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),x86_64-embedded)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),arm-linux)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),arm-palmos)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),arm-darwin)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),arm-wince)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),arm-gba)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),arm-nds)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),arm-embedded)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),arm-symbian)
-override TARGET_LOADERS+=$(CPU_LOADERS)
-endif
-ifeq ($(FULL_TARGET),powerpc64-linux)
-override TARGET_LOADERS+=$(CPU_LOADERS)
+override INSTALL_FPCPACKAGE=y
+ifeq ($(FULL_TARGET),i386-linux)
+override COMPILER_OPTIONS+=-dI386_ASSEMBLER
 endif
-ifeq ($(FULL_TARGET),powerpc64-darwin)
-override TARGET_LOADERS+=$(CPU_LOADERS)
+ifeq ($(FULL_TARGET),i386-go32v2)
+override COMPILER_OPTIONS+=-dI386_ASSEMBLER
 endif
-ifeq ($(FULL_TARGET),powerpc64-embedded)
-override TARGET_LOADERS+=$(CPU_LOADERS)
+ifeq ($(FULL_TARGET),i386-win32)
+override COMPILER_OPTIONS+=-dI386_ASSEMBLER
 endif
-ifeq ($(FULL_TARGET),avr-embedded)
-override TARGET_LOADERS+=$(CPU_LOADERS)
+ifeq ($(FULL_TARGET),i386-freebsd)
+override COMPILER_OPTIONS+=-dI386_ASSEMBLER
 endif
-ifeq ($(FULL_TARGET),armeb-linux)
-override TARGET_LOADERS+=$(CPU_LOADERS)
+ifeq ($(FULL_TARGET),i386-beos)
+override COMPILER_OPTIONS+=-dI386_ASSEMBLER
 endif
-ifeq ($(FULL_TARGET),armeb-embedded)
-override TARGET_LOADERS+=$(CPU_LOADERS)
+ifeq ($(FULL_TARGET),i386-haiku)
+override COMPILER_OPTIONS+=-dI386_ASSEMBLER
 endif
 ifeq ($(FULL_TARGET),i386-linux)
 override COMPILER_INCLUDEDIR+=src
@@ -746,6 +606,9 @@ endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
 override COMPILER_INCLUDEDIR+=src
 endif
+ifeq ($(FULL_TARGET),x86_64-solaris)
+override COMPILER_INCLUDEDIR+=src
+endif
 ifeq ($(FULL_TARGET),x86_64-darwin)
 override COMPILER_INCLUDEDIR+=src
 endif
@@ -797,6 +660,9 @@ endif
 ifeq ($(FULL_TARGET),armeb-embedded)
 override COMPILER_INCLUDEDIR+=src
 endif
+ifeq ($(FULL_TARGET),mipsel-linux)
+override COMPILER_INCLUDEDIR+=src
+endif
 ifeq ($(FULL_TARGET),i386-linux)
 override COMPILER_SOURCEDIR+=src tests
 endif
@@ -920,6 +786,9 @@ endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
 override COMPILER_SOURCEDIR+=src tests
 endif
+ifeq ($(FULL_TARGET),x86_64-solaris)
+override COMPILER_SOURCEDIR+=src tests
+endif
 ifeq ($(FULL_TARGET),x86_64-darwin)
 override COMPILER_SOURCEDIR+=src tests
 endif
@@ -971,6 +840,9 @@ endif
 ifeq ($(FULL_TARGET),armeb-embedded)
 override COMPILER_SOURCEDIR+=src tests
 endif
+ifeq ($(FULL_TARGET),mipsel-linux)
+override COMPILER_SOURCEDIR+=src tests
+endif
 ifeq ($(FULL_TARGET),i386-linux)
 override COMPILER_TARGETDIR+=.
 endif
@@ -1094,6 +966,9 @@ endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
 override COMPILER_TARGETDIR+=.
 endif
+ifeq ($(FULL_TARGET),x86_64-solaris)
+override COMPILER_TARGETDIR+=.
+endif
 ifeq ($(FULL_TARGET),x86_64-darwin)
 override COMPILER_TARGETDIR+=.
 endif
@@ -1145,6 +1020,9 @@ endif
 ifeq ($(FULL_TARGET),armeb-embedded)
 override COMPILER_TARGETDIR+=.
 endif
+ifeq ($(FULL_TARGET),mipsel-linux)
+override COMPILER_TARGETDIR+=.
+endif
 ifdef REQUIRE_UNITSDIR
 override UNITSDIR+=$(REQUIRE_UNITSDIR)
 endif
@@ -2035,6 +1913,9 @@ endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
 REQUIRE_PACKAGES_RTL=1
 endif
+ifeq ($(FULL_TARGET),x86_64-solaris)
+REQUIRE_PACKAGES_RTL=1
+endif
 ifeq ($(FULL_TARGET),x86_64-darwin)
 REQUIRE_PACKAGES_RTL=1
 endif
@@ -2086,6 +1967,9 @@ endif
 ifeq ($(FULL_TARGET),armeb-embedded)
 REQUIRE_PACKAGES_RTL=1
 endif
+ifeq ($(FULL_TARGET),mipsel-linux)
+REQUIRE_PACKAGES_RTL=1
+endif
 ifdef REQUIRE_PACKAGES_RTL
 PACKAGEDIR_RTL:=$(firstword $(subst /Makefile.fpc,,$(strip $(wildcard $(addsuffix /rtl/Makefile.fpc,$(PACKAGESDIR))))))
 ifneq ($(PACKAGEDIR_RTL),)
@@ -2095,9 +1979,9 @@ else
 UNITDIR_RTL=$(PACKAGEDIR_RTL)
 endif
 ifdef CHECKDEPEND
-$(PACKAGEDIR_RTL)/$(FPCMADE):
-	$(MAKE) -C $(PACKAGEDIR_RTL) $(FPCMADE)
-override ALLDEPENDENCIES+=$(PACKAGEDIR_RTL)/$(FPCMADE)
+$(PACKAGEDIR_RTL)/$(OS_TARGET)/$(FPCMADE):
+	$(MAKE) -C $(PACKAGEDIR_RTL)/$(OS_TARGET) $(FPCMADE)
+override ALLDEPENDENCIES+=$(PACKAGEDIR_RTL)/$(OS_TARGET)/$(FPCMADE)
 endif
 else
 PACKAGEDIR_RTL=
@@ -2494,7 +2378,7 @@ ZIPCMD_CDPACK:=cd $(subst /,$(ZIPPATHSEP),$(PACKDIR))
 ZIPCMD_CDBASE:=cd $(subst /,$(ZIPPATHSEP),$(BASEDIR))
 ifdef USETAR
 ZIPDESTFILE:=$(DIST_DESTDIR)/$(FULLZIPNAME)$(TAREXT)
-ZIPCMD_ZIP:=$(TARPROG) cf$(TAROPT) $(ZIPDESTFILE) *
+ZIPCMD_ZIP:=$(TARPROG) c$(TAROPT)f $(ZIPDESTFILE) *
 else
 ZIPDESTFILE:=$(DIST_DESTDIR)/$(FULLZIPNAME)$(ZIPEXT)
 ZIPCMD_ZIP:=$(subst /,$(ZIPPATHSEP),$(ZIPPROG)) -Dr $(ZIPOPT) $(ZIPDESTFILE) *
@@ -2539,6 +2423,9 @@ fpc_zipdistinstall:
 ifdef EXEFILES
 override CLEANEXEFILES:=$(addprefix $(TARGETDIRPREFIX),$(CLEANEXEFILES))
 endif
+ifdef CLEAN_PROGRAMS
+override CLEANEXEFILES+=$(addprefix $(TARGETDIRPREFIX),$(addsuffix $(EXEEXT), $(CLEAN_PROGRAMS)))
+endif
 ifdef CLEAN_UNITS
 override CLEANPPUFILES+=$(addsuffix $(PPUEXT),$(CLEAN_UNITS))
 endif
@@ -2585,6 +2472,9 @@ endif
 ifdef CLEANRSTFILES
 	-$(DEL) $(addprefix $(UNITTARGETDIRPREFIX),$(CLEANRSTFILES))
 endif
+endif
+ifdef CLEAN_FILES
+	-$(DEL) $(CLEAN_FILES)
 endif
 	-$(DELTREE) units
 	-$(DEL) *$(OEXT) *$(PPUEXT) *$(RSTEXT) *$(ASMEXT) *$(STATICLIBEXT) *$(SHAREDLIBEXT) *$(PPLEXT)
@@ -2735,11 +2625,27 @@ endif
 .NOTPARALLEL:
 mmx_clr$(OEXT):src/$(CPU_TARGET)/mmx_clr.as
 	$(AS) --32 -o $(UNITTARGETDIRPREFIX)mmx_clr$(OEXT) src/$(CPU_TARGET)/mmx_clr.as
-mmxp_32$(OEXT):src/$(CPU_TARGET)/mmxp_32.as
-	$(AS) --32 -o $(UNITTARGETDIRPREFIX)mmxp_32$(OEXT) src/$(CPU_TARGET)/mmxp_32.as
 mmx_main$(OEXT):src/$(CPU_TARGET)/mmx_main.as
 	$(AS) --32 -o $(UNITTARGETDIRPREFIX)mmx_main$(OEXT) src/$(CPU_TARGET)/mmx_main.as
 mmxp2_32$(OEXT):src/$(CPU_TARGET)/mmxp2_32.as
 	$(AS) --32 -o $(UNITTARGETDIRPREFIX)mmxp2_32$(OEXT) src/$(CPU_TARGET)/mmxp2_32.as
-hm_i386$(OEXT): $(I386_LOADERSSRC)
-	$(AS) --32 -o $(UNITTARGETDIRPREFIX)hm_i386$(OEXT) $(I386_LOADERSSRC)
+mmxp_32$(OEXT):src/$(CPU_TARGET)/mmxp_32.as
+	$(AS) --32 -o $(UNITTARGETDIRPREFIX)mmxp_32$(OEXT) src/$(CPU_TARGET)/mmxp_32.as
+x8616lut$(OEXT):src/$(CPU_TARGET)/x8616lut.as
+	$(AS) --32 -o $(UNITTARGETDIRPREFIX)x8616lut$(OEXT) src/$(CPU_TARGET)/x8616lut.as
+x86_clr$(OEXT):src/$(CPU_TARGET)/x86_clr.as
+	$(AS) --32 -o $(UNITTARGETDIRPREFIX)x86_clr$(OEXT) src/$(CPU_TARGET)/x86_clr.as
+x86_main$(OEXT):src/$(CPU_TARGET)/x86_main.as
+	$(AS) --32 -o $(UNITTARGETDIRPREFIX)x86_main$(OEXT) src/$(CPU_TARGET)/x86_main.as
+x86p_16$(OEXT):src/$(CPU_TARGET)/x86p_16.as
+	$(AS) --32 -o $(UNITTARGETDIRPREFIX)x86p_16$(OEXT) src/$(CPU_TARGET)/x86p_16.as
+x86p_32$(OEXT):src/$(CPU_TARGET)/x86p_32.as
+	$(AS) --32 -o $(UNITTARGETDIRPREFIX)x86p_32$(OEXT) src/$(CPU_TARGET)/x86p_32.as
+x86p_cpy$(OEXT):src/$(CPU_TARGET)/x86p_cpy.as
+	$(AS) --32 -o $(UNITTARGETDIRPREFIX)x86p_cpy$(OEXT) src/$(CPU_TARGET)/x86p_cpy.as
+x86p_i8$(OEXT):src/$(CPU_TARGET)/x86p_i8.as
+	$(AS) --32 -o $(UNITTARGETDIRPREFIX)x86p_i8$(OEXT) src/$(CPU_TARGET)/x86p_i8.as
+x86p_s32$(OEXT):src/$(CPU_TARGET)/x86p_s32.as
+	$(AS) --32 -o $(UNITTARGETDIRPREFIX)x86p_s32$(OEXT) src/$(CPU_TARGET)/x86p_s32.as
+x86pscpy$(OEXT):src/$(CPU_TARGET)/x86pscpy.as
+	$(AS) --32 -o $(UNITTARGETDIRPREFIX)x86pscpy$(OEXT) src/$(CPU_TARGET)/x86pscpy.as

+ 57 - 17
packages/hermes/Makefile.fpc

@@ -8,14 +8,41 @@ version=2.4.3
 
 [target]
 units=hermes
-loaders=$(CPU_LOADERS)
+loaders_i386_linux=mmx_clr mmx_main mmxp2_32 mmxp_32 \
+             x8616lut x86_clr x86_main x86p_16 x86p_32 x86p_cpy \
+             x86p_i8 x86p_s32 x86pscpy
+loaders_i386_win32=mmx_clr mmx_main mmxp2_32 mmxp_32 \
+             x8616lut x86_clr x86_main x86p_16 x86p_32 x86p_cpy \
+             x86p_i8 x86p_s32 x86pscpy
+loaders_i386_go32v2=mmx_clr mmx_main mmxp2_32 mmxp_32 \
+             x8616lut x86_clr x86_main x86p_16 x86p_32 x86p_cpy \
+             x86p_i8 x86p_s32 x86pscpy
+loaders_i386_freebsd=mmx_clr mmx_main mmxp2_32 mmxp_32 \
+             x8616lut x86_clr x86_main x86p_16 x86p_32 x86p_cpy \
+             x86p_i8 x86p_s32 x86pscpy
+loaders_i386_haiku=mmx_clr mmx_main mmxp2_32 mmxp_32 \
+             x8616lut x86_clr x86_main x86p_16 x86p_32 x86p_cpy \
+             x86p_i8 x86p_s32 x86pscpy
+loaders_i386_beos=mmx_clr mmx_main mmxp2_32 mmxp_32 \
+             x8616lut x86_clr x86_main x86p_16 x86p_32 x86p_cpy \
+             x86p_i8 x86p_s32 x86pscpy
 
 [compiler]
+options_i386_linux=-dI386_ASSEMBLER
+options_i386_win32=-dI386_ASSEMBLER
+options_i386_go32v2=-dI386_ASSEMBLER
+options_i386_freebsd=-dI386_ASSEMBLER
+options_i386_haiku=-dI386_ASSEMBLER
+options_i386_beos=-dI386_ASSEMBLER
+
 unitdir=
 targetdir=.
 includedir=src
 sourcedir=src tests
 
+[install]
+fpcpackage=y
+
 [default]
 fpcdir=../..
 
@@ -24,25 +51,38 @@ fpcdir=../..
 mmx_clr$(OEXT):src/$(CPU_TARGET)/mmx_clr.as
         $(AS) --32 -o $(UNITTARGETDIRPREFIX)mmx_clr$(OEXT) src/$(CPU_TARGET)/mmx_clr.as
 
-mmxp_32$(OEXT):src/$(CPU_TARGET)/mmxp_32.as
-        $(AS) --32 -o $(UNITTARGETDIRPREFIX)mmxp_32$(OEXT) src/$(CPU_TARGET)/mmxp_32.as
-
 mmx_main$(OEXT):src/$(CPU_TARGET)/mmx_main.as
         $(AS) --32 -o $(UNITTARGETDIRPREFIX)mmx_main$(OEXT) src/$(CPU_TARGET)/mmx_main.as
 
 mmxp2_32$(OEXT):src/$(CPU_TARGET)/mmxp2_32.as
         $(AS) --32 -o $(UNITTARGETDIRPREFIX)mmxp2_32$(OEXT) src/$(CPU_TARGET)/mmxp2_32.as
 
-hm_i386$(OEXT): $(I386_LOADERSSRC)
-        $(AS) --32 -o $(UNITTARGETDIRPREFIX)hm_i386$(OEXT) $(I386_LOADERSSRC)
-
-[prerules]
-I386_LOADERSSRC=src/i386/x86_main.as src/i386/x86p_cpy.as \
-        src/i386/x86pscpy.as src/i386/x86p_16.as \
-        src/i386/x86p_i8.as src/i386/x86_clr.as \
-        src/i386/x86p_32.as src/i386/x86p_s32.as
-ifeq ($(CPU_TARGET),i386)
-CPU_LOADERS=mmx_clr mmxp_32 mmx_main mmxp2_32 hm_i386
-else
-CPU_LOADERS=
-endif
+mmxp_32$(OEXT):src/$(CPU_TARGET)/mmxp_32.as
+        $(AS) --32 -o $(UNITTARGETDIRPREFIX)mmxp_32$(OEXT) src/$(CPU_TARGET)/mmxp_32.as
+
+x8616lut$(OEXT):src/$(CPU_TARGET)/x8616lut.as
+        $(AS) --32 -o $(UNITTARGETDIRPREFIX)x8616lut$(OEXT) src/$(CPU_TARGET)/x8616lut.as
+
+x86_clr$(OEXT):src/$(CPU_TARGET)/x86_clr.as
+        $(AS) --32 -o $(UNITTARGETDIRPREFIX)x86_clr$(OEXT) src/$(CPU_TARGET)/x86_clr.as
+
+x86_main$(OEXT):src/$(CPU_TARGET)/x86_main.as
+        $(AS) --32 -o $(UNITTARGETDIRPREFIX)x86_main$(OEXT) src/$(CPU_TARGET)/x86_main.as
+
+x86p_16$(OEXT):src/$(CPU_TARGET)/x86p_16.as
+        $(AS) --32 -o $(UNITTARGETDIRPREFIX)x86p_16$(OEXT) src/$(CPU_TARGET)/x86p_16.as
+
+x86p_32$(OEXT):src/$(CPU_TARGET)/x86p_32.as
+        $(AS) --32 -o $(UNITTARGETDIRPREFIX)x86p_32$(OEXT) src/$(CPU_TARGET)/x86p_32.as
+
+x86p_cpy$(OEXT):src/$(CPU_TARGET)/x86p_cpy.as
+        $(AS) --32 -o $(UNITTARGETDIRPREFIX)x86p_cpy$(OEXT) src/$(CPU_TARGET)/x86p_cpy.as
+
+x86p_i8$(OEXT):src/$(CPU_TARGET)/x86p_i8.as
+        $(AS) --32 -o $(UNITTARGETDIRPREFIX)x86p_i8$(OEXT) src/$(CPU_TARGET)/x86p_i8.as
+
+x86p_s32$(OEXT):src/$(CPU_TARGET)/x86p_s32.as
+        $(AS) --32 -o $(UNITTARGETDIRPREFIX)x86p_s32$(OEXT) src/$(CPU_TARGET)/x86p_s32.as
+
+x86pscpy$(OEXT):src/$(CPU_TARGET)/x86pscpy.as
+        $(AS) --32 -o $(UNITTARGETDIRPREFIX)x86pscpy$(OEXT) src/$(CPU_TARGET)/x86pscpy.as

+ 0 - 223
packages/hermes/src/clear.inc

@@ -1,223 +0,0 @@
-{
-    Free Pascal port of the Hermes C library.
-    Copyright (C) 2001-2003  Nikolay Nikolov ([email protected])
-    Original C version by Christian Nentwich ([email protected])
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library 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
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-}
-
-{Function Hermes_ClearerInstance : THermesHandle;
-Procedure Hermes_ClearerReturn(handle : THermesHandle);
-Function Hermes_ClearerRequest(handle : THermesHandle; format : PHermesFormat) : Boolean;
-Function Hermes_ClearerClear(handle : THermesHandle; pixels : Pointer;
-                             x1, y1, width, height, pitch : Integer;
-                             r, g, b : int32; index : char8) : Boolean;}
-
-Type
-  PClearerInstance = ^TClearerInstance;
-  TClearerInstance = Record
-    format : PHermesFormat;
-    func : THermesClearPtr;
-  End;
-
-Const
-{ClearerList is a list of TClearerInstance}
-  ClearerList : PHermesList = Nil;
-  CLEARrefcount : Integer = 0;
-  ClearCurrenthandle : THermesHandle = 0;
-
-Function Hermes_ClearerInstance : THermesHandle;
-
-Var
-  element : PHermesListElement;
-  newinstance : PClearerInstance;
-
-Begin
-  If CLEARrefcount = 0 Then
-  Begin
-    ClearerList := Hermes_ListNew;
-    If ClearerList = Nil Then
-    Begin
-      Hermes_ClearerInstance := 0;
-      Exit;
-    End;
-  End;
-  element := Hermes_ListElementNew(ClearCurrenthandle + 1);
-  If element = Nil Then
-  Begin
-    Hermes_ClearerInstance := 0;
-    Exit;
-  End;
-  newinstance := malloc(SizeOf(TClearerInstance));
-  If newinstance = Nil Then
-  Begin
-    Hermes_ClearerInstance := 0;
-    Exit;
-  End;
-  newinstance^.func := Nil;
-  newinstance^.format := Hermes_FormatNewEmpty;
-  If newinstance^.format = Nil Then
-  Begin
-    Hermes_ClearerInstance := 0;
-    Exit;
-  End;
-  element^.data := newinstance;
-  Hermes_ListAdd(ClearerList, element);
-  Inc(CLEARrefcount);
-  Inc(ClearCurrenthandle);
-  Hermes_ClearerInstance := ClearCurrenthandle;
-End;
-
-Procedure Hermes_ClearerFreeHandleCallback(q : Pointer);
-
-Begin
-  free(PClearerInstance(q)^.format);
-End;
-
-Procedure Hermes_ClearerReturn(handle : THermesHandle);
-
-Var
-  element : PHermesListElement;
-  instance : PClearerInstance;
-
-Begin
-  Dec(CLEARrefcount);
-  If Hermes_ListDeleteElement(ClearerList, handle, @Hermes_ClearerFreeHandleCallback) = False Then
-    Exit;
-  If CLEARrefcount = 0 Then
-  Begin
-    { Dirty fix: Free the format pointers in all the clearer instances }
-    { The list functions need updating to allow member deletion! }
-    element := ClearerList^.first;
-    While element <> Nil Do
-    Begin
-      instance := element^.data;
-      free(instance^.format);
-      element := element^.next;
-    End;
-    Hermes_ListDestroy(ClearerList);
-  End;
-End;
-
-Function Hermes_ClearerRequest(handle : THermesHandle; format : PHermesFormat) : Boolean;
-
-Var
-  element : PHermesListElement;
-  clr : PClearerInstance;
-  i : Integer;
-
-Begin
-  { Look up this clearer in the list }
-  element := Hermes_ListLookup(ClearerList, handle);
-  If element = Nil Then
-  Begin
-    Hermes_ClearerRequest := False;
-    Exit;
-  End;
-  clr := element^.data;
-
-  { If the clearer is the same, return 1 }
-  If Hermes_FormatEquals(clr^.format, format) Then
-  Begin
-    Hermes_ClearerRequest := True;
-    Exit;
-  End;
-
-  { Otherwise look for a new clearer }
-  clr^.func := Nil;
-  For i := 0 To numClearers - 1 Do
-  Begin
-    If Clearers[i]^.bits = format^.bits Then
-    Begin
-      clr^.func := Clearers[i]^.func;
-      Hermes_FormatCopy(format, clr^.format);
-      Hermes_ClearerRequest := True;
-      Exit;
-    End;
-  End;
-  Hermes_ClearerRequest := False;
-End;
-
-Function Hermes_ClearerClear(handle : THermesHandle; pixels : Pointer;
-                             x1, y1, width, height, pitch : Integer;
-                             r, g, b : int32; index : char8) : Boolean;
-
-Var
-  element : PHermesListElement;
-  info : THermesGenericInfo;
-  clr : PClearerInstance;
-  pixelval, d_r, d_g, d_b, d_a : int32;
-  iface : THermesClearInterface;
-
-Begin
-  If (height <= 0) Or (width <= 0) Then
-  Begin
-    Hermes_ClearerClear := True;
-    Exit;
-  End;
-
-  { Look up this clearer in the list }
-  element := Hermes_ListLookup(ClearerList, handle);
-  If (element = Nil) Or (element^.data = Nil) Then
-  Begin
-    Hermes_ClearerClear := False;
-    Exit;
-  End;
-
-  { Get clearer instance from list element data }
-  clr := element^.data;
-
-  { No conversion function assigned }
-  If clr^.func = Nil Then
-  Begin
-    Hermes_ClearerClear := False;
-    Exit;
-  End;
-
-  If clr^.format^.indexed Then
-    pixelval := index
-  Else
-  Begin
-    Hermes_Calculate_Generic_Info(24, 16, 8, 32,
-                                  Hermes_Topbit(clr^.format^.r),
-                                  Hermes_Topbit(clr^.format^.g),
-                                  Hermes_Topbit(clr^.format^.b),
-                                  Hermes_Topbit(clr^.format^.a), @info);
-    pixelval := (index Shl 24) Or (r Shl 16) Or (g Shl 8) Or b;
-    d_r := ((pixelval Shr info.r_right) Shl info.r_left) And clr^.format^.r;
-    d_g := ((pixelval Shr info.g_right) Shl info.g_left) And clr^.format^.g;
-    d_b := ((pixelval Shr info.b_right) Shl info.b_left) And clr^.format^.b;
-    d_a := ((pixelval Shr info.a_right) Shl info.a_left) And clr^.format^.a;
-    pixelval := d_r Or d_g Or d_b Or d_a;
-  End;
-  iface.dest := pixels;
-  Inc(iface.dest, y1*pitch + x1*(clr^.format^.bits Shr 3));
-
-  iface.width := width;
-  iface.height := height;
-  iface.add := pitch - width * (clr^.format^.bits Shr 3);
-
-  iface.value := pixelval;
-
-  { Optimization }
-  If iface.add = 0 Then
-  Begin
-    iface.width := iface.width * iface.height;
-    iface.height := 1;
-  End;
-
-  clr^.func(@iface);
-  Hermes_ClearerClear := True;
-End;

+ 89 - 81
packages/hermes/src/d_32.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,97 +34,93 @@
    32 bit to * dithered converters for the HERMES library
    Copyright (c) 1998 Christian Nentwich ([email protected])
    This source code is licensed under the GNU LGPL
-  
+
    Please refer to the file COPYING.LIB contained in the distribution for
    licensing conditions
 }
 
-Procedure ConvertP_32rgb888_16rgb565_dither(iface : PHermesConverterInterface); CDecl;
-
-Var
-  source, dest : Pchar8;
-  d_pixel : int32;
-  y, count : LongInt;
-
-Begin
+procedure ConvertP_32rgb888_16rgb565_dither(iface: PHermesConverterInterface); cdecl;
+var
+  source, dest: PUint8;
+  d_pixel: Uint32;
+  y, count: LongInt;
+begin
   y := 0;
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  While y < iface^.d_height Do
-  Begin
+  while y < iface^.d_height do
+  begin
     { Get counter for this scanline }
     count := iface^.d_width;
 
     { Check first pixel alignment, correct if necessary }
-    If (PtrUInt(iface^.d_pixels) And 3) <> 0 Then
-    Begin
-      Pshort16(dest)^ := 
-        DitherTab_r565_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
-	DitherTab_g565_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
-	DitherTab_b565_44[count And 3, y And 3, Pint32(source)^ And $ff];
+    if (PtrUInt(iface^.d_pixels) and 3) <> 0 then
+    begin
+      PUint16(dest)^ :=
+        DitherTab_r565_44[count and 3, y and 3, (PUint32(source)^ shr 16) and $ff] or
+        DitherTab_g565_44[count and 3, y and 3, (PUint32(source)^ shr 8) and $ff] or
+        DitherTab_b565_44[count and 3, y and 3, PUint32(source)^ and $ff];
 
       Inc(source, 4);
       Inc(dest, 2);
       Dec(count);
-    End;
+    end;
 
     { Two pixels at a time loop }
-    While count > 1 Do
-    Begin
-      d_pixel :=
-        DitherTab_r565_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
-	DitherTab_g565_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
-	DitherTab_b565_44[count And 3, y And 3, Pint32(source)^ And $ff];
+    while count > 1 do
+    begin
+      d_pixel := (
+        DitherTab_r565_44[count and 3, y and 3, (PUint32(source)^ shr 16) and $ff] or
+        DitherTab_g565_44[count and 3, y and 3, (PUint32(source)^ shr 8) and $ff] or
+        DitherTab_b565_44[count and 3, y and 3, PUint32(source)^ and $ff]) shl DWORD_SMALLINT0_SHL;
 
       Inc(source, 4);
       Dec(count);
 
-      d_pixel := d_pixel Or ((
-        DitherTab_r565_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
-	DitherTab_g565_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
-	DitherTab_b565_44[count And 3, y And 3, Pint32(source)^ And $ff]) Shl 16);
+      d_pixel := d_pixel or ((
+        DitherTab_r565_44[count and 3, y and 3, (PUint32(source)^ shr 16) and $ff] or
+        DitherTab_g565_44[count and 3, y and 3, (PUint32(source)^ shr 8) and $ff] or
+        DitherTab_b565_44[count and 3, y and 3, PUint32(source)^ and $ff]) shl DWORD_SMALLINT1_SHL);
 
       Dec(count);
       Inc(source, 4);
 
-      Pint32(dest)^ := d_pixel;
+      PUint32(dest)^ := d_pixel;
 
       Inc(dest, 4);
-    End;
+    end;
 
     { Convert the odd trailing pixel }
-    If (iface^.d_width And 1) <> 0 Then
-    Begin
-      Pshort16(dest)^ :=
-        DitherTab_r565_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
-	DitherTab_g565_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
-	DitherTab_b565_44[count And 3, y And 3, Pint32(source)^ And $ff];
+    if (iface^.d_width and 1) <> 0 then
+    begin
+      PUint16(dest)^ :=
+        DitherTab_r565_44[count and 3, y and 3, (PUint32(source)^ shr 16) and $ff] or
+        DitherTab_g565_44[count and 3, y and 3, (PUint32(source)^ shr 8) and $ff] or
+        DitherTab_b565_44[count and 3, y and 3, PUint32(source)^ and $ff];
 
       Inc(source, 4);
       Inc(dest, 2);
-    End;
+    end;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
 
     Inc(y);
-  End;
-End;
-
-Procedure ConvertP_32rgb888_8rgb332_dither(iface : PHermesConverterInterface); CDecl;
-
-Var
-  source, dest : Pchar8;
-  d_pixel : int32;
-  y, count : LongInt;
-
-Begin
+  end;
+end;
+
+procedure ConvertP_32rgb888_8rgb332_dither(iface: PHermesConverterInterface); cdecl;
+var
+  source, dest: PUint8;
+  d_pixel: Uint32;
+  y, count: LongInt;
+begin
   y := 0;
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
- 
-  While y < iface^.d_height Do
-  Begin
+
+  while y < iface^.d_height do
+  begin
     { Get counter for this scanline }
     count := iface^.d_width;
 
@@ -121,56 +129,56 @@ Begin
 
 
     { Convert 4 pixels at a time }
-    While count > 3 Do
-    Begin
-      d_pixel :=
-        DitherTab_r332_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
-	DitherTab_g332_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
-	DitherTab_b332_44[count And 3, y And 3, Pint32(source)^ And $ff];
+    while count > 3 do
+    begin
+      d_pixel := (
+        DitherTab_r332_44[count and 3, y and 3, (PUint32(source)^ shr 16) and $ff] or
+        DitherTab_g332_44[count and 3, y and 3, (PUint32(source)^ shr 8) and $ff] or
+        DitherTab_b332_44[count and 3, y and 3, PUint32(source)^ and $ff]) shl DWORD_BYTE0_SHL;
       Dec(count);
       Inc(source, 4);
 
-      d_pixel := d_pixel Or ((
-        DitherTab_r332_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
-	DitherTab_g332_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
-	DitherTab_b332_44[count And 3, y And 3, Pint32(source)^ And $ff]) Shl 8);
+      d_pixel := d_pixel or ((
+        DitherTab_r332_44[count and 3, y and 3, (PUint32(source)^ shr 16) and $ff] or
+        DitherTab_g332_44[count and 3, y and 3, (PUint32(source)^ shr 8) and $ff] or
+        DitherTab_b332_44[count and 3, y and 3, PUint32(source)^ and $ff]) shl DWORD_BYTE1_SHL);
       Dec(count);
       Inc(source, 4);
 
-      d_pixel := d_pixel Or ((
-        DitherTab_r332_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
-	DitherTab_g332_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
-	DitherTab_b332_44[count And 3, y And 3, Pint32(source)^ And $ff]) Shl 16);
+      d_pixel := d_pixel or ((
+        DitherTab_r332_44[count and 3, y and 3, (PUint32(source)^ shr 16) and $ff] or
+        DitherTab_g332_44[count and 3, y and 3, (PUint32(source)^ shr 8) and $ff] or
+        DitherTab_b332_44[count and 3, y and 3, PUint32(source)^ and $ff]) shl DWORD_BYTE2_SHL);
       Dec(count);
       Inc(source, 4);
 
-      d_pixel := d_pixel Or ((
-        DitherTab_r332_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
-	DitherTab_g332_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
-	DitherTab_b332_44[count And 3, y And 3, Pint32(source)^ And $ff]) Shl 24);
+      d_pixel := d_pixel or ((
+        DitherTab_r332_44[count and 3, y and 3, (PUint32(source)^ shr 16) and $ff] or
+        DitherTab_g332_44[count and 3, y and 3, (PUint32(source)^ shr 8) and $ff] or
+        DitherTab_b332_44[count and 3, y and 3, PUint32(source)^ and $ff]) shl DWORD_BYTE3_SHL);
       Dec(count);
       Inc(source, 4);
 
-      Pint32(dest)^ := d_pixel;
+      PUint32(dest)^ := d_pixel;
       Inc(dest, 4);
-    End;
+    end;
 
     { Write trailing pixels }
-    While count <> 0 Do
-    Begin
+    while count <> 0 do
+    begin
       Dec(count);
-      dest^ := 
-        DitherTab_r332_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
-	DitherTab_g332_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
-	DitherTab_b332_44[count And 3, y And 3, Pint32(source)^ And $ff];
+      dest^ :=
+        DitherTab_r332_44[count and 3, y and 3, (PUint32(source)^ shr 16) and $ff] or
+        DitherTab_g332_44[count and 3, y and 3, (PUint32(source)^ shr 8) and $ff] or
+        DitherTab_b332_44[count and 3, y and 3, PUint32(source)^ and $ff];
 
       Inc(source, 4);
       Inc(dest);
-    End;
+    end;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
 
     Inc(y);
-  End;
-End;
+  end;
+end;

+ 0 - 62
packages/hermes/src/debug.inc

@@ -1,62 +0,0 @@
-{
-    Free Pascal port of the Hermes C library.
-    Copyright (C) 2001-2003  Nikolay Nikolov ([email protected])
-    Original C version by Christian Nentwich ([email protected])
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library 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
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-}
-
-Function C2Str(Q : Integer) : String;
-
-Var
-  S : String;
-
-Begin
-  Str(Q, S);
-  C2Str := S;
-End;
-
-Procedure DebugInit;
-
-{Var
-  F : Text;}
-
-Begin
-{  ASSign(F, 'debug.txt');
-  Rewrite(F);
-  Close(F);}
-End;
-
-Procedure DebugMSG(S : String);
-
-Var
-  F : Text;
-
-Begin
-  ASSign(F, 'debug.txt');
-  {$I-}
-  Append(F);
-  {$I+}
-  If IOResult <> 0 Then
-  Begin
-    {$I-}
-    Rewrite(F);
-    {$I+}
-    If IOResult <> 0 Then
-      Exit;
-  End;
-  Writeln(F, S);
-  Close(F);
-End;

+ 0 - 82
packages/hermes/src/dither.inc

@@ -1,82 +0,0 @@
-{
-    Free Pascal port of the Hermes C library.
-    Copyright (C) 2001-2003  Nikolay Nikolov ([email protected])
-    Original C version by Christian Nentwich ([email protected])
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library 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
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-}
-
-{ Everything in here (C)1998 The Rasterman }
-
-{ Rasterman's dither matrix }
-
-Const
-  DitherMatrix_44 : Array[0..3, 0..3] Of char8 = (
-    (0, 4, 1, 5),
-    (6, 2, 7, 3),
-    (1, 5, 0, 4),
-    (7, 3, 6, 2));
-
-Var
-  DitherTab_r565_44 : Array[0..3, 0..3, 0..255] Of short16;
-  DitherTab_g565_44 : Array[0..3, 0..3, 0..255] Of short16;
-  DitherTab_b565_44 : Array[0..3, 0..3, 0..255] Of short16;
-
-  DitherTab_r332_44 : Array[0..3, 0..3, 0..255] Of char8;
-  DitherTab_g332_44 : Array[0..3, 0..3, 0..255] Of char8;
-  DitherTab_b332_44 : Array[0..3, 0..3, 0..255] Of char8;
-
-Procedure Dither_SetupMatrices;
-
-Var
-  i, x, y : LongInt;
-
-Begin  
-  For y := 0 To 3 Do
-    For x := 0 To 3 Do
-      For i := 0 To 255 Do
-      Begin
-        If (DitherMatrix_44[x, y] < (i And $7)) And (i < (256 - 8)) Then
-	Begin
-	  DitherTab_r565_44[x, y, i] := ((i + 8) And $f8) Shl 8;
-	  DitherTab_r332_44[x, y, i] := ((i + 8) And $e0);
-	End
-	Else
-	Begin
-	  DitherTab_r565_44[x, y, i] := (i And $f8) Shl 8;
-	  DitherTab_r332_44[x, y, i] := i And $e0;
-	End;
-        If (DitherMatrix_44[x, y] < ((i And $3) Shl 1)) And (i < (256 - 4)) Then
-	Begin
-	  DitherTab_g565_44[x, y, i] := (((i + 4) And $fc) Shl 8) Shr 5;
-	  DitherTab_g332_44[x, y, i] := ((i + 4) And $e0) Shr 3;
-	End
-	Else
-	Begin
-	  DitherTab_g565_44[x, y, i] := ((i And $fc) Shl 8) Shr 5;
-	  DitherTab_g332_44[x, y, i] := (i And $e0) Shr 3;
-	End;
-        If (DitherMatrix_44[x, y] < (i And $7)) And (i < (256 - 8)) Then
-	Begin
-	  DitherTab_b565_44[x, y, i] := (((i + 8) And $f8) Shl 16) Shr 19;
-	  DitherTab_b332_44[x, y, i] := ((i + 8) Shr 6) And $3;
-	End
-	Else
-	Begin
-	  DitherTab_b565_44[x, y, i] := ((i And $f8) Shl 16) Shr 19;
-	  DitherTab_b332_44[x, y, i] := (i Shr 6) And $3;
-	End;
-      End;
-End;

+ 134 - 123
packages/hermes/src/factconv.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -24,15 +36,14 @@
    which use the generic loop.
    There needs to be a function assigned to the scanline loop however,
    otherwise the converter will fail a test in Convert.c. This is the easiest
-   way. Do NOT use NotApplicable as NotYetImplemented ! }
-Procedure NotApplicable(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Begin
-  If source <> Nil Then;
-  If dest <> Nil Then;
-  If count <> 0 Then;
-  If inc_source <> 0 Then;
-End;
+   way. do NOT use NotApplicable as NotYetImplemented ! }
+procedure NotApplicable(source, dest: PUint8; count, inc_source: DWord); cdecl;
+begin
+  if source <> nil Then;
+  if dest <> nil Then;
+  if count <> 0 Then;
+  if inc_source <> 0 Then;
+end;
 
 {  Factory converter array, holds ALL converters available from HERMES. Note
    that converters have to be assigned IN ORDER of priority for processors
@@ -43,154 +54,154 @@ End;
       - X86 converters
       - Pascal converters
 
-   If someone wrote a P2 or P3 converter, if would be added even further up. }
+   if someone wrote a P2 or P3 converter, if would be added even further up. }
 
-Const
+const
   Factory_NumConverters = 45
   {$IFDEF I386_ASSEMBLER}+27{$ENDIF I386_ASSEMBLER};
 
-  Factory_Converters : Array[0..Factory_NumConverters - 1] Of THermesFactoryStruct =
+  Factory_Converters: array [0..Factory_NumConverters - 1] of THermesFactoryStruct =
 (
 {$IFDEF I386_ASSEMBLER}
   { ------ From 32 RGB 888 - MMX PENTIUM II ---- }
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:24;d_idx:False;d_r:$ff0000;d_g:$ff00;d_b:$ff;d_a:0;
-   loopnormal:@ConvertMMX;loopstretch:Nil;normal:@ConvertMMXpII32_24RGB888;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_MMX_PENTIUM),
+   loopnormal:@ConvertMMX;loopstretch:nil;normal:@ConvertMMXpII32_24RGB888;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_MMX_PENTIUM),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$f800;d_g:$7e0;d_b:$1f;d_a:0;
-   loopnormal:@ConvertMMX;loopstretch:Nil;normal:@ConvertMMXpII32_16RGB565;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_MMX_PENTIUM),
+   loopnormal:@ConvertMMX;loopstretch:nil;normal:@ConvertMMXpII32_16RGB565;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_MMX_PENTIUM),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$1f;d_g:$7e0;d_b:$f800;d_a:0;
-   loopnormal:@ConvertMMX;loopstretch:Nil;normal:@ConvertMMXpII32_16BGR565;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_MMX_PENTIUM),
+   loopnormal:@ConvertMMX;loopstretch:nil;normal:@ConvertMMXpII32_16BGR565;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_MMX_PENTIUM),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$7c00;d_g:$3e0;d_b:$1f;d_a:0;
-   loopnormal:@ConvertMMX;loopstretch:Nil;normal:@ConvertMMXpII32_16RGB555;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_MMX_PENTIUM),
+   loopnormal:@ConvertMMX;loopstretch:nil;normal:@ConvertMMXpII32_16RGB555;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_MMX_PENTIUM),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$1f;d_g:$3e0;d_b:$7c00;d_a:0;
-   loopnormal:@ConvertMMX;loopstretch:Nil;normal:@ConvertMMXpII32_16BGR555;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_MMX_PENTIUM),
+   loopnormal:@ConvertMMX;loopstretch:nil;normal:@ConvertMMXpII32_16BGR555;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_MMX_PENTIUM),
 
   { ------ From 32 RGB 888 - MMX PENTIUM ------- }
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$7c00;d_g:$3e0;d_b:$1f;d_a:0;
-   loopnormal:@ConvertMMX;loopstretch:Nil;normal:@ConvertMMXpII32_16RGB555;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_MMX_PENTIUM),
+   loopnormal:@ConvertMMX;loopstretch:nil;normal:@ConvertMMXpII32_16RGB555;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_MMX_PENTIUM),
 
   { ------ From 32 RGB 888 - X86 PENTIUM ------- }
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff;d_g:$ff00;d_b:$ff0000;d_a:0;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p32_32BGR888;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p32_32BGR888;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff000000;d_g:$ff0000;d_b:$ff00;d_a:$ff;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p32_32RGBA888;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p32_32RGBA888;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff00;d_g:$ff0000;d_b:$ff000000;d_a:$ff;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p32_32BGRA888;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p32_32BGRA888;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:24;d_idx:False;d_r:$ff0000;d_g:$ff00;d_b:$ff;d_a:0;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p32_24RGB888;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p32_24RGB888;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:24;d_idx:False;d_r:$ff;d_g:$ff00;d_b:$ff0000;d_a:0;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p32_24BGR888;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p32_24BGR888;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$f800;d_g:$7e0;d_b:$1f;d_a:0;
    loopnormal:@ConvertX86;loopstretch:@ConvertX86Stretch;
    normal:@ConvertX86p32_16RGB565;stretch:@ConvertX86p32_16RGB565_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$1f;d_g:$7e0;d_b:$f800;d_a:0;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p32_16BGR565;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p32_16BGR565;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$7c00;d_g:$3e0;d_b:$1f;d_a:0;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p32_16RGB555;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p32_16RGB555;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$1f;d_g:$3e0;d_b:$7c00;d_a:0;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p32_16BGR555;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p32_16BGR555;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:8;d_idx:False;d_r:$e0;d_g:$1c;d_b:$3;d_a:0;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p32_8RGB332;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p32_8RGB332;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   { ------ From 16 RGB 565 - X86 PENTIUM ------- }
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff0000;d_g:$ff00;d_b:$ff;d_a:0;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p16_32RGB888;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p16_32RGB888;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff;d_g:$ff00;d_b:$ff0000;d_a:0;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p16_32BGR888;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p16_32BGR888;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff000000;d_g:$ff0000;d_b:$ff00;d_a:$ff;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p16_32RGBA888;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p16_32RGBA888;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff00;d_g:$ff0000;d_b:$ff000000;d_a:$ff;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p16_32BGRA888;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p16_32BGRA888;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:24;d_idx:False;d_r:$ff0000;d_g:$ff00;d_b:$ff;d_a:0;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p16_24RGB888;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p16_24RGB888;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:24;d_idx:False;d_r:$ff;d_g:$ff00;d_b:$ff0000;d_a:0;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p16_24BGR888;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p16_24BGR888;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:16;d_idx:False;d_r:$1f;d_g:$7e0;d_b:$f800;d_a:0;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p16_16BGR565;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p16_16BGR565;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:16;d_idx:False;d_r:$7c00;d_g:$3e0;d_b:$1f;d_a:0;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p16_16RGB555;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p16_16RGB555;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:16;d_idx:False;d_r:$1f;d_g:$3e0;d_b:$7c00;d_a:0;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p16_16BGR555;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p16_16BGR555;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:8;d_idx:False;d_r:$e0;d_g:$1c;d_b:$3;d_a:0;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86p16_8RGB332;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86p16_8RGB332;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 
   (s_bits:8;s_idx:True;s_r:0;s_g:0;s_b:0;s_a:0;
    d_bits:16;d_idx:False;d_r:0;d_g:0;d_b:0;d_a:0;
-   loopnormal:@ConvertX86;loopstretch:Nil;normal:@ConvertX86pI8_16;
-   stretch:Nil;dither:Nil;ditherstretch:Nil;processor:PROC_X86_PENTIUM),
+   loopnormal:@ConvertX86;loopstretch:nil;normal:@ConvertX86pI8_16;
+   stretch:nil;dither:nil;ditherstretch:nil;processor:PROC_X86_PENTIUM),
 {$ENDIF I386_ASSEMBLER}
 
   { ------ From 32 RGBA 8888 ---- }
@@ -199,7 +210,7 @@ Const
    d_bits:32;d_idx:False;d_r:$ff000000;d_g:$ff0000;d_b:$ff00;d_a:$ff;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_32rgb888_32bgr888;stretch:@ConvertP_32rgb888_32bgr888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
   }
 
   { ------ From 32 RGB 888 ------- }
@@ -208,275 +219,275 @@ Const
    d_bits:32;d_idx:False;d_r:$ff;d_g:$ff00;d_b:$ff0000;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_32rgb888_32bgr888;stretch:@ConvertP_32rgb888_32bgr888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff000000;d_g:$ff0000;d_b:$ff00;d_a:$ff;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_32rgb888_32rgba888;stretch:@ConvertP_32rgb888_32rgba888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff00;d_g:$ff0000;d_b:$ff000000;d_a:$ff;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_32rgb888_32bgra888;stretch:@ConvertP_32rgb888_32bgra888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:24;d_idx:False;d_r:$ff0000;d_g:$ff00;d_b:$ff;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_32rgb888_24rgb888;stretch:@ConvertP_32rgb888_24rgb888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:24;d_idx:False;d_r:$ff;d_g:$ff00;d_b:$ff0000;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_32rgb888_24bgr888;stretch:@ConvertP_32rgb888_24bgr888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$f800;d_g:$7e0;d_b:$1f;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_32rgb888_16rgb565;stretch:@ConvertP_32rgb888_16rgb565_S;
-   dither:@ConvertP_32rgb888_16rgb565_dither;ditherstretch:Nil;
+   dither:@ConvertP_32rgb888_16rgb565_dither;ditherstretch:nil;
    processor:PROC_GENERIC),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$1f;d_g:$7e0;d_b:$f800;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_32rgb888_16bgr565;stretch:@ConvertP_32rgb888_16bgr565_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$7c00;d_g:$3e0;d_b:$1f;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_32rgb888_16rgb555;stretch:@ConvertP_32rgb888_16rgb555_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$1f;d_g:$3e0;d_b:$7c00;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_32rgb888_16bgr555;stretch:@ConvertP_32rgb888_16bgr555_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:32;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:8;d_idx:False;d_r:$e0;d_g:$1c;d_b:$3;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_32rgb888_8rgb332;stretch:@ConvertP_32rgb888_8rgb332_S;
    dither:@ConvertP_32rgb888_8rgb332_dither;
-   ditherstretch:Nil;processor:PROC_GENERIC),
+   ditherstretch:nil;processor:PROC_GENERIC),
 
  { ------ From 32 RGB MUHMU ------- }
-  (s_bits:32;s_idx:False;s_r:$ff Shl 20;s_g:$ff Shl 10;s_b:$ff;s_a:0;
+  (s_bits:32;s_idx:False;s_r:$ff shl 20;s_g:$ff shl 10;s_b:$ff;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff0000;d_g:$ff00;d_b:$ff;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_muhmu32_32rgb888;stretch:@ConvertP_muhmu32_32rgb888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
-  (s_bits:32;s_idx:False;s_r:$ff Shl 20;s_g:$ff Shl 10;s_b:$ff;s_a:0;
+  (s_bits:32;s_idx:False;s_r:$ff shl 20;s_g:$ff shl 10;s_b:$ff;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff;d_g:$ff00;d_b:$ff0000;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_muhmu32_32bgr888;stretch:@ConvertP_muhmu32_32bgr888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
-  (s_bits:32;s_idx:False;s_r:$ff Shl 20;s_g:$ff Shl 10;s_b:$ff;s_a:0;
+  (s_bits:32;s_idx:False;s_r:$ff shl 20;s_g:$ff shl 10;s_b:$ff;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff000000;d_g:$ff0000;d_b:$ff00;d_a:$ff;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_muhmu32_32rgba888;stretch:@ConvertP_muhmu32_32rgba888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
-  (s_bits:32;s_idx:False;s_r:$ff Shl 20;s_g:$ff Shl 10;s_b:$ff;s_a:0;
+  (s_bits:32;s_idx:False;s_r:$ff shl 20;s_g:$ff shl 10;s_b:$ff;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff00;d_g:$ff0000;d_b:$ff000000;d_a:$ff;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_muhmu32_32bgra888;stretch:@ConvertP_muhmu32_32bgra888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
-  (s_bits:32;s_idx:False;s_r:$ff Shl 20;s_g:$ff Shl 10;s_b:$ff;s_a:0;
+  (s_bits:32;s_idx:False;s_r:$ff shl 20;s_g:$ff shl 10;s_b:$ff;s_a:0;
    d_bits:24;d_idx:False;d_r:$ff0000;d_g:$ff00;d_b:$ff;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_muhmu32_24rgb888;stretch:@ConvertP_muhmu32_24rgb888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
-  (s_bits:32;s_idx:False;s_r:$ff Shl 20;s_g:$ff Shl 10;s_b:$ff;s_a:0;
+  (s_bits:32;s_idx:False;s_r:$ff shl 20;s_g:$ff shl 10;s_b:$ff;s_a:0;
    d_bits:24;d_idx:False;d_r:$ff;d_g:$ff00;d_b:$ff0000;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_muhmu32_24bgr888;stretch:@ConvertP_muhmu32_24bgr888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
-  (s_bits:32;s_idx:False;s_r:$ff Shl 20;s_g:$ff Shl 10;s_b:$ff;s_a:0;
+  (s_bits:32;s_idx:False;s_r:$ff shl 20;s_g:$ff shl 10;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$f800;d_g:$7e0;d_b:$1f;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_muhmu32_16rgb565;stretch:@ConvertP_muhmu32_16rgb565_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
-  (s_bits:32;s_idx:False;s_r:$ff Shl 20;s_g:$ff Shl 10;s_b:$ff;s_a:0;
+  (s_bits:32;s_idx:False;s_r:$ff shl 20;s_g:$ff shl 10;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$1f;d_g:$7e0;d_b:$f800;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_muhmu32_16bgr565;stretch:@ConvertP_muhmu32_16bgr565_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
-  (s_bits:32;s_idx:False;s_r:$ff Shl 20;s_g:$ff Shl 10;s_b:$ff;s_a:0;
+  (s_bits:32;s_idx:False;s_r:$ff shl 20;s_g:$ff shl 10;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$7c00;d_g:$3e0;d_b:$1f;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_muhmu32_16rgb555;stretch:@ConvertP_muhmu32_16rgb555_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
-  (s_bits:32;s_idx:False;s_r:$ff Shl 20;s_g:$ff Shl 10;s_b:$ff;s_a:0;
+  (s_bits:32;s_idx:False;s_r:$ff shl 20;s_g:$ff shl 10;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$1f;d_g:$3e0;d_b:$7c00;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_muhmu32_16bgr555;stretch:@ConvertP_muhmu32_16bgr555_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
-  (s_bits:32;s_idx:False;s_r:$ff Shl 20;s_g:$ff Shl 10;s_b:$ff;s_a:0;
+  (s_bits:32;s_idx:False;s_r:$ff shl 20;s_g:$ff shl 10;s_b:$ff;s_a:0;
    d_bits:8;d_idx:False;d_r:$e0;d_g:$1c;d_b:$3;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_muhmu32_8rgb332;stretch:@ConvertP_muhmu32_8rgb332_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   { ------ From 24 RGB 888 ------- }
   (s_bits:24;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff0000;d_g:$ff00;d_b:$ff;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_24rgb888_32rgb888;stretch:@ConvertP_24rgb888_32rgb888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:24;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff;d_g:$ff00;d_b:$ff0000;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_24rgb888_32bgr888;stretch:@ConvertP_24rgb888_32bgr888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:24;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff000000;d_g:$ff0000;d_b:$ff00;d_a:$ff;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_24rgb888_32rgba888;stretch:@ConvertP_24rgb888_32rgba888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:24;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff00;d_g:$ff0000;d_b:$ff000000;d_a:$ff;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_24rgb888_32bgra888;stretch:@ConvertP_24rgb888_32bgra888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:24;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:24;d_idx:False;d_r:$ff;d_g:$ff00;d_b:$ff0000;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_24rgb888_24bgr888;stretch:@ConvertP_24rgb888_24bgr888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:24;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$f800;d_g:$7e0;d_b:$1f;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_24rgb888_16rgb565;stretch:@ConvertP_24rgb888_16rgb565_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:24;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$1f;d_g:$7e0;d_b:$f800;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_24rgb888_16bgr565;stretch:@ConvertP_24rgb888_16bgr565_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:24;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$7c00;d_g:$3e0;d_b:$1f;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_24rgb888_16rgb555;stretch:@ConvertP_24rgb888_16rgb555_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:24;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:16;d_idx:False;d_r:$1f;d_g:$3e0;d_b:$7c00;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_24rgb888_16bgr555;stretch:@ConvertP_24rgb888_16bgr555_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:24;s_idx:False;s_r:$ff0000;s_g:$ff00;s_b:$ff;s_a:0;
    d_bits:8;d_idx:False;d_r:$e0;d_g:$1c;d_b:$3;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_24rgb888_8rgb332;stretch:@ConvertP_24rgb888_8rgb332_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   { ------ From 16 RGB 565 ------- }
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff0000;d_g:$ff00;d_b:$ff;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_16rgb565_32rgb888;stretch:@ConvertP_16rgb565_32rgb888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff;d_g:$ff00;d_b:$ff0000;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_16rgb565_32bgr888;stretch:@ConvertP_16rgb565_32bgr888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff000000;d_g:$ff0000;d_b:$ff00;d_a:$ff;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_16rgb565_32rgba888;stretch:@ConvertP_16rgb565_32rgba888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:32;d_idx:False;d_r:$ff00;d_g:$ff0000;d_b:$ff000000;d_a:$ff;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_16rgb565_32bgra888;stretch:@ConvertP_16rgb565_32bgra888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:24;d_idx:False;d_r:$ff0000;d_g:$ff00;d_b:$ff;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_16rgb565_24rgb888;stretch:@ConvertP_16rgb565_24rgb888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:24;d_idx:False;d_r:$ff;d_g:$ff00;d_b:$ff0000;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_16rgb565_24bgr888;stretch:@ConvertP_16rgb565_24bgr888_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:16;d_idx:False;d_r:$1f;d_g:$7e0;d_b:$f800;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_16rgb565_16bgr565;stretch:@ConvertP_16rgb565_16bgr565_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:16;d_idx:False;d_r:$7c00;d_g:$3e0;d_b:$1f;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_16rgb565_16rgb555;stretch:@ConvertP_16rgb565_16rgb555_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:16;d_idx:False;d_r:$1f;d_g:$3e0;d_b:$7c00;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_16rgb565_16bgr555;stretch:@ConvertP_16rgb565_16bgr555_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:16;s_idx:False;s_r:$f800;s_g:$7e0;s_b:$1f;s_a:0;
    d_bits:8;d_idx:False;d_r:$e0;d_g:$1c;d_b:$3;d_a:0;
    loopnormal:@ConvertP;loopstretch:@ConvertPStretch;
    normal:@ConvertP_16rgb565_8rgb332;stretch:@ConvertP_16rgb565_8rgb332_S;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   { ------ From 8 bit INDEXED ------- }
   (s_bits:8;s_idx:True;s_r:0;s_g:0;s_b:0;s_a:0;
    d_bits:32;d_idx:False;d_r:0;d_g:0;d_b:0;d_a:0;
    loopnormal:@ConvertP_index8_32;loopstretch:@ConvertP_index8_32_S;
    normal:@NotApplicable;stretch:@NotApplicable;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:8;s_idx:True;s_r:0;s_g:0;s_b:0;s_a:0;
    d_bits:24;d_idx:False;d_r:0;d_g:0;d_b:0;d_a:0;
    loopnormal:@ConvertP_index8_24;loopstretch:@ConvertP_index8_24_S;
    normal:@NotApplicable;stretch:@NotApplicable;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:8;s_idx:True;s_r:0;s_g:0;s_b:0;s_a:0;
    d_bits:16;d_idx:False;d_r:0;d_g:0;d_b:0;d_a:0;
    loopnormal:@ConvertP_index8_16;loopstretch:@ConvertP_index8_16_S;
    normal:@NotApplicable;stretch:@NotApplicable;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC),
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC),
 
   (s_bits:8;s_idx:True;s_r:0;s_g:0;s_b:0;s_a:0;
    d_bits:8;d_idx:False;d_r:0;d_g:0;d_b:0;d_a:0;
    loopnormal:@ConvertP_index8_8;loopstretch:@ConvertP_index8_8_S;
    normal:@NotApplicable;stretch:@NotApplicable;
-   dither:Nil;ditherstretch:Nil;processor:PROC_GENERIC)
+   dither:nil;ditherstretch:nil;processor:PROC_GENERIC)
 );

+ 0 - 398
packages/hermes/src/factory.inc

@@ -1,398 +0,0 @@
-{
-    Free Pascal port of the Hermes C library.
-    Copyright (C) 2001-2003  Nikolay Nikolov ([email protected])
-    Original C version by Christian Nentwich ([email protected])
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library 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
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-}
-
-Var
-  Processor : Integer;
-
-Procedure Hermes_Factory_Init;
-
-Var
-  res : Integer;
-
-Begin
-  res := 0;
-  Processor := PROC_GENERIC;
-
-  {$IFDEF I386_ASSEMBLER}
-    Processor := Processor Or PROC_X86_PENTIUM;{There are no others at the moment}
-    res := Hermes_X86_CPU;
-    If (res And $800000) <> 0 Then
-    Begin
-//      Writeln('mmx disabled for debugging');
-      Processor := Processor Or PROC_MMX_PENTIUM;
-{      Writeln('mmx!');}
-    End;
-  {$ENDIF I386_ASSEMBLER}
-End;
-
-Function Hermes_Factory_getClearer(bits : int32) : PHermesClearer;
-
-Var
-  tmp : PHermesClearer;
-
-Begin
-  { Try different processors in order of priority..
-    Note that for this to work, an MMX processor has to have both MMX and
-    X86 flags }
-  tmp := malloc(SizeOf(THermesClearer));
-  If tmp = Nil Then
-  Begin
-    Hermes_Factory_getClearer := Nil;
-    Exit;
-  End;
-
-  tmp^.bits := bits;
-  Hermes_Factory_getClearer := tmp;
-
-  {$IFDEF I386_ASSEMBLER}
-    If (Processor And PROC_MMX_PENTIUM) <> 0 Then
-      Case bits Of
-        32 : Begin
-          tmp^.func := @ClearMMX_32;
-          Exit;
-        End;
-        24 : ;
-        16 : Begin
-          tmp^.func := @ClearMMX_16;
-          Exit;
-        End;
-        8 : Begin
-          tmp^.func := @ClearMMX_8;
-          Exit;
-        End;
-      End;
-
-    If (Processor And PROC_X86_PENTIUM) <> 0 Then
-      Case bits Of
-        32 : Begin
-          tmp^.func := @ClearX86_32;
-          Exit;
-        End;
-        24 : ;
-        16 : Begin
-          tmp^.func := @ClearX86_16;
-          Exit;
-        End;
-        8 : Begin
-          tmp^.func := @ClearX86_8;
-          Exit;
-        End;
-      End;
-  {$ENDIF I386_ASSEMBLER}
-
-  Case bits Of
-    32 : Begin
-      tmp^.func := @ClearP_32;
-      Exit;
-    End;
-    24 : Begin
-      tmp^.func := @ClearP_24;
-      Exit;
-    End;
-    16 : Begin
-      tmp^.func := @ClearP_16;
-      Exit;
-    End;
-    8 : Begin
-      tmp^.func := @ClearP_8;
-      Exit;
-    End;
-    Else
-    Begin
-      free(tmp);
-      Hermes_Factory_getClearer := Nil;
-    End;
-  End;
-End;
-
-Function Hermes_Factory_getConverter(source, dest : PHermesFormat) : PHermesConverter;
-
-Var
-  tmp : PHermesConverter;
-  i : Integer;
-  found : Boolean;
-
-Begin
-  found := False;
-
-  tmp := malloc(SizeOf(THermesConverter));
-  If tmp = Nil Then
-  Begin
-    Hermes_Factory_getConverter := Nil;
-    Exit;
-  End;
-
-  { Set all conversion routines to nil }
-  tmp^.loopnormal := Nil;
-  tmp^.loopstretch := Nil;
-  tmp^.normal := Nil;
-  tmp^.stretch := Nil;
-  tmp^.dither := Nil;
-  tmp^.ditherstretch := Nil;
-  tmp^.flags := 0;
-
-  If source^.indexed Then
-    { For 8 bit indexed, just look at the destination bit depth and check
-      if the converter's processor is a subset of our processor }
-    For i := 0 To Factory_NumConverters - 1 Do
-      If (Factory_Converters[i].d_bits = dest^.bits) And
-        (Factory_Converters[i].s_idx And
-        ((processor And Factory_Converters[i].processor) <> 0)) Then
-      Begin
-        { If any routines are unassigned, assign them now }
-
-        If tmp^.loopnormal = Nil Then
-        Begin
-          tmp^.loopnormal := Factory_Converters[i].loopnormal;
-          found := True;
-        End;
-
-        If tmp^.normal = Nil Then
-        Begin
-          tmp^.normal := Factory_Converters[i].normal;
-          found := True;
-        End;
-
-        If tmp^.loopstretch = Nil Then
-        Begin
-          tmp^.loopstretch := Factory_Converters[i].loopstretch;
-          found := True;
-        End;
-
-        If tmp^.stretch = Nil Then
-        Begin
-          tmp^.stretch := Factory_Converters[i].stretch;
-          found := True;
-        End;
-      End Else
-  Else
-    { Otherwise we need to compare everything, including bitmasks }
-    For i := 0 To Factory_NumConverters - 1 Do
-      If (Factory_Converters[i].d_bits = dest^.bits) And
-         (Factory_Converters[i].d_r = dest^.r) And
-         (Factory_Converters[i].d_g = dest^.g) And
-         (Factory_Converters[i].d_b = dest^.b) And
-         (Factory_Converters[i].d_a = dest^.a) And
-         (Factory_Converters[i].d_idx = dest^.indexed) And
-         (Factory_Converters[i].s_bits = source^.bits) And
-         (Factory_Converters[i].s_r = source^.r) And
-         (Factory_Converters[i].s_g = source^.g) And
-         (Factory_Converters[i].s_b = source^.b) And
-         (Factory_Converters[i].s_a = source^.a) And
-         (Factory_Converters[i].s_idx = source^.indexed) And
-         ((processor And Factory_Converters[i].processor) <> 0) Then
-      Begin
-        { If any routines are unassigned, assign them now }
-
-        If (tmp^.loopnormal = Nil) And
-           (Factory_Converters[i].loopnormal <> Nil) Then
-        Begin
-          tmp^.loopnormal := Factory_Converters[i].loopnormal;
-          found := True;
-        End;
-
-        If (tmp^.normal = Nil) And
-           (Factory_Converters[i].normal <> Nil) Then
-        Begin
-          tmp^.normal := Factory_Converters[i].normal;
-          found := True;
-        End;
-
-        If (tmp^.loopstretch = Nil) And
-           (Factory_Converters[i].loopstretch <> Nil) Then
-        Begin
-          tmp^.loopstretch := Factory_Converters[i].loopstretch;
-          found := True;
-        End;
-
-        If (tmp^.stretch = Nil) And
-           (Factory_Converters[i].stretch <> Nil) Then
-        Begin
-          tmp^.stretch := Factory_Converters[i].stretch;
-          found := True;
-        End;
-
-        If (tmp^.dither = Nil) And
-           (Factory_Converters[i].dither <> Nil) Then
-        Begin
-          tmp^.dither := Factory_Converters[i].dither;
-          found := True;
-        End;
-
-        If (tmp^.ditherstretch = Nil) And
-           (Factory_Converters[i].ditherstretch <> Nil) Then
-        Begin
-          tmp^.ditherstretch := Factory_Converters[i].ditherstretch;
-          found := True;
-        End;
-
-        { In the rare event of having everything assigned, pull the emergency
-          break. Otherwise we need to continue looking (might be stretching
-          routines somewhere :)
-          Do I sound like a stewardess? }
-        If (tmp^.loopnormal <> Nil) And (tmp^.normal <> Nil) And
-           (tmp^.loopstretch <> Nil) And (tmp^.stretch <> Nil) And
-           (tmp^.dither <> Nil) And (tmp^.ditherstretch <> Nil) Then
-          Break;
-      End;
-
-  If found Then
-  Begin
-    Hermes_FormatCopy(source, @tmp^.source);
-    Hermes_FormatCopy(dest, @tmp^.dest);
-
-    Hermes_Factory_getConverter := tmp;
-  End
-  Else
-  Begin
-    free(tmp);
-    Hermes_Factory_getConverter := Nil;
-  End;
-End;
-
-Function Hermes_Factory_getEqualConverter(bits : Integer) : PHermesConverter;
-
-Var
-  found : Boolean;
-  tmp : PHermesConverter;
-  asm_found : Integer;
-  c_found : Integer;
-
-Begin
-  found := False;
-  tmp := malloc(SizeOf(THermesConverter));
-  If tmp = Nil Then
-  Begin
-    Hermes_Factory_getEqualConverter := Nil;
-    Exit;
-  End;
-
-  { Set all conversion routines to null }
-  tmp^.loopnormal := Nil;
-  tmp^.loopstretch := Nil;
-  tmp^.normal := Nil;
-  tmp^.stretch := Nil;
-  tmp^.dither := Nil;
-  tmp^.ditherstretch := Nil;
-
-{$IFDEF I386_ASSEMBLER}
-
-  { Try MMX routines }
-  If (tmp^.loopnormal = Nil) Or (tmp^.normal = Nil) Or
-     (tmp^.loopstretch = Nil) Or (tmp^.stretch = Nil) Then
-    If (processor And PROC_MMX_PENTIUM) <> 0 Then
-{      Case bits Of
-      End};
-
-  { Try X86 routines }
-  If (tmp^.loopnormal = Nil) Or (tmp^.normal = Nil) Or
-     (tmp^.loopstretch = Nil) Or (tmp^.stretch = Nil) Then
-    If (processor And PROC_X86_PENTIUM) <> 0 Then
-    Begin
-      asm_found := 0;
-      Case bits Of
-        32 : Begin
-          tmp^.normal := @CopyX86p_4byte; asm_found := 1;
-        End;
-        24 : ;
-        16 : Begin
-          tmp^.normal := @CopyX86p_2byte; asm_found := 1;
-        End;
-         8 : Begin
-          tmp^.normal := @CopyX86p_1byte; asm_found := 1;
-        End;
-      End;
-
-      If (asm_found And 1) <> 0 Then
-      Begin
-        tmp^.loopnormal := @ConvertX86;
-        found := True;
-      End;
-    End;
-
-{$ENDIF I386_ASSEMBLER}
-
-
-  If (tmp^.loopnormal = Nil) Or (tmp^.normal = Nil) Or
-     (tmp^.loopstretch = Nil) Or (tmp^.stretch = Nil) Then
-  Begin
-    c_found := 0;
-
-    Case bits Of
-      32 : Begin
-        If tmp^.normal = Nil Then
-        Begin
-          tmp^.normal := @CopyP_4byte; c_found := c_found Or 1;
-        End;
-        If tmp^.stretch = Nil Then
-        Begin
-          tmp^.stretch := @CopyP_4byte_S; c_found := c_found Or 2;
-        End;
-      End;
-      24 : Begin
-        If tmp^.normal = Nil Then
-        Begin
-          tmp^.normal := @CopyP_3byte; c_found := c_found Or 1;
-        End;
-        If tmp^.stretch = Nil Then
-        Begin
-          tmp^.stretch := @CopyP_3byte_S; c_found := c_found Or 2;
-        End;
-      End;
-      16 : Begin
-        If tmp^.normal = Nil Then
-        Begin
-          tmp^.normal := @CopyP_2byte; c_found := c_found Or 1;
-        End;
-        If tmp^.stretch = Nil Then
-        Begin
-          tmp^.stretch := @CopyP_2byte_S; c_found := c_found Or 2;
-        End;
-      End;
-       8 : Begin
-        If tmp^.normal = Nil Then
-        Begin
-          tmp^.normal := @CopyP_1byte; c_found := c_found Or 1;
-        End;
-        If tmp^.stretch = Nil Then
-        Begin
-          tmp^.stretch := @CopyP_1byte_S; c_found := c_found Or 2;
-        End;
-      End;
-    End;
-
-    If (c_found And 1) <> 0 Then
-    Begin
-      tmp^.loopnormal := @ConvertP; found := True;
-    End;
-    If (c_found And 2) <> 0 Then
-    Begin
-      tmp^.loopstretch := @ConvertPStretch; found := True;
-    End;
-  End;
-
-  If found Then
-    Hermes_Factory_getEqualConverter := tmp
-  Else
-  Begin
-    free(tmp);
-    Hermes_Factory_getEqualConverter := Nil;
-  End;
-End;

+ 0 - 138
packages/hermes/src/format.inc

@@ -1,138 +0,0 @@
-{
-    Free Pascal port of the Hermes C library.
-    Copyright (C) 2001-2003  Nikolay Nikolov ([email protected])
-    Original C version by Christian Nentwich ([email protected])
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library 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
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-}
-
-{Function Hermes_FormatNewEmpty : PHermesFormat;
-Function Hermes_FormatNew(bits : Integer; r, g, b, a : int32;
-                          indexed : Boolean) : PHermesFormat;
-Procedure Hermes_FormatFree(fmt : PHermesFormat);
-Function Hermes_FormatNewEx(bits : Integer; r, g, b, a : int32;
-                            indexed, has_colorkey : Boolean;
-                            colorkey : int32) : PHermesFormat;
-Function Hermes_FormatEquals(op1, op2 : PHermesFormat) : Boolean;
-Procedure Hermes_FormatCopy(source, dest : PHermesFormat);}
-
-Function Hermes_FormatNewEmpty : PHermesFormat;
-
-Var
-  tmp : PHermesFormat;
-
-Begin
-  tmp := malloc(SizeOf(THermesFormat));
-  If tmp = Nil Then
-  Begin
-    Hermes_FormatNewEmpty := Nil;
-    Exit;
-  End;
-  tmp^.bits := 0;
-  tmp^.indexed := False;
-  tmp^.r := 0;
-  tmp^.g := 0;
-  tmp^.b := 0;
-  tmp^.a := 0;
-  tmp^.has_colorkey := False;
-  tmp^.colorkey := 0;
-  Hermes_FormatNewEmpty := tmp;
-End;
-
-Function Hermes_FormatNew(bits : Integer; r, g, b, a : int32;
-                          indexed : Boolean) : PHermesFormat;
-
-Var
-  tmp : PHermesFormat;
-
-Begin
-  If indexed And (bits <> 8) Then
-  Begin
-    Hermes_FormatNew := Nil;
-    Exit;
-  End;
-  tmp := malloc(SizeOf(THermesFormat));
-  If tmp = Nil Then
-  Begin
-    Hermes_FormatNew := Nil;
-    Exit;
-  End;
-  tmp^.bits := bits;
-  tmp^.r := r;
-  tmp^.g := g;
-  tmp^.b := b;
-  tmp^.a := a;
-  tmp^.indexed := indexed;
-  tmp^.has_colorkey := False;
-  tmp^.colorkey := 0;
-  Hermes_FormatNew := tmp;
-End;
-
-Procedure Hermes_FormatFree(fmt : PHermesFormat);
-
-Begin
-  If fmt <> Nil Then
-    free(fmt);
-End;
-
-Function Hermes_FormatNewEx(bits : Integer; r, g, b, a : int32;
-                            indexed, has_colorkey : Boolean;
-                            colorkey : int32) : PHermesFormat;
-
-Var
-  tmp : PHermesFormat;
-
-Begin
-  If indexed And (bits <> 8) Then
-  Begin
-    Hermes_FormatNewEx := Nil;
-    Exit;
-  End;
-  tmp := malloc(SizeOf(THermesFormat));
-  If tmp = Nil Then
-  Begin
-    Hermes_FormatNewEx := Nil;
-    Exit;
-  End;
-  tmp^.bits := bits;
-  tmp^.r := r;
-  tmp^.g := g;
-  tmp^.b := b;
-  tmp^.a := a;
-  tmp^.indexed := indexed;
-  tmp^.has_colorkey := has_colorkey;
-  tmp^.colorkey := colorkey;
-  Hermes_FormatNewEx := tmp;
-End;
-
-Function Hermes_FormatEquals(op1, op2 : PHermesFormat) : Boolean;
-
-Begin
-  Hermes_FormatEquals := ((op1^.indexed = op2^.indexed) And
-                          (op1^.bits = op2^.bits) And
-                          (op1^.r = op2^.r) And
-                          (op1^.g = op2^.g) And
-                          (op1^.b = op2^.b) And
-                          (op1^.a = op2^.a) And
-                          (op1^.has_colorkey = op2^.has_colorkey) And
-                          ((op1^.has_colorkey = False) Or
-                           (op1^.colorkey = op2^.colorkey)));
-End;
-
-Procedure Hermes_FormatCopy(source, dest : PHermesFormat);
-
-Begin
-  Move(source^, dest^, SizeOf(THermesFormat));
-End;

+ 18 - 6
packages/hermes/src/headp.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,23 +32,23 @@
 
 { This little definition makes everything much nicer below here }
 {$MACRO ON}
-{$define CONVERT_PARAMETERS:=source, dest : Pchar8; count, inc_source : DWord}
+{$define CONVERT_PARAMETERS:=source, dest: PUint8; count, inc_source: DWord}
 
 {$I p_16.inc}
 {$I p_24.inc}
 {$I p_32.inc}
-{ $I p32aoblt.pp}
+{ $I p32aoblt.inc}
 {$I p_clr.inc}
 {$I p_cnv.inc}
 {$I p_cpy.inc}
 {$I p_g.inc}
 {$I p_ga.inc}
 {$I p_gac.inc}
-{ $I p_gaoblt.pp}
+{ $I p_gaoblt.inc}
 {$I p_gca.inc}
 {$I p_gcc.inc}
-{ $I p_gccblt.pp}
-{ $I p_gcoblt.pp}
+{ $I p_gccblt.inc}
+{ $I p_gcoblt.inc}
 {$I p_i8.inc}
 {$I p_muhmu.inc}
 {$I d_32.inc}

+ 41 - 16
packages/hermes/src/hermconf.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,22 +31,35 @@
 }
 
 
-Const
-  HERMES_INITIAL = 8; { Initial size and growth of dynamic }
-  HERMES_GROWTH = 4; { array structures }
-
-  A_32 = 3;		      { oh yes, hardcode it... tsk tsk tsk }
-  R_32 = 2;                   { Position of R,G,B in a 32 bit dword }
+const
+  {$IFDEF FPC_LITTLE_ENDIAN}
+  A_32 = 3;                   { oh yes, hardcode it... tsk tsk tsk }
+  R_32 = 2;                   { Position of R,G,B in a 32 bit dword (in ARGB8888 format) }
   G_32 = 1;
   B_32 = 0;
-  R_24 = 2;                   { Position of R,G,B in a 24 bit pixel }
+  R_24 = 2;                   { Position of R,G,B in a 24 bit pixel (in RGB888 format) }
   G_24 = 1;
   B_24 = 0;
-{  #define DWORD_BYTE0(s) s         /* Shift values to get to bytes in dwords */
-  #define DWORD_BYTE1(s) ((s)<<8)  /* Check out the bracket paranoia to */   
-  #define DWORD_BYTE2(s) ((s)<<16) /* prevent bugs :)) */     
-  #define DWORD_BYTE3(s) ((s)<<24)       
-  #define DWORD_SHORT0(s) s
-  #define DWORD_SHORT1(s) ((s)<<16)
-  #define DWORD_SHORT0(s) s
-  #define DWORD_SHORT1(s) ((s)<<16)}
+
+  DWORD_BYTE0_SHL = 0;
+  DWORD_BYTE1_SHL = 8;
+  DWORD_BYTE2_SHL = 16;
+  DWORD_BYTE3_SHL = 24;
+  DWORD_SMALLINT0_SHL = 0;
+  DWORD_SMALLINT1_SHL = 16;
+  {$ELSE FPC_LITTLE_ENDIAN}
+  A_32 = 0;
+  R_32 = 1;
+  G_32 = 2;
+  B_32 = 3;
+  R_24 = 0;
+  G_24 = 1;
+  B_24 = 2;
+
+  DWORD_BYTE0_SHL = 24;
+  DWORD_BYTE1_SHL = 16;
+  DWORD_BYTE2_SHL = 8;
+  DWORD_BYTE3_SHL = 0;
+  DWORD_SMALLINT0_SHL = 16;
+  DWORD_SMALLINT1_SHL = 0;
+  {$ENDIF FPC_LITTLE_ENDIAN}

+ 24 - 27
packages/hermes/src/hermdef.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,28 +31,20 @@
 }
 
 
-{$IFDEF CPU86}
-  {$DEFINE I386_ASSEMBLER}
+{$IFDEF I386_ASSEMBLER}
   {$IFNDEF win32}
-    Const
-      ExternalAsmPrefix='_';
+    {$IFNDEF go32v2}
+    const
+      ExternalAsmPrefix='_'; // targets other than go32v2 and win32
+    {$ELSE go32v2}
+    const
+      ExternalAsmPrefix=''; // go32v2
+    {$ENDIF go32v2}
   {$ELSE win32}
-    Const
-      ExternalAsmPrefix='';
+    const
+      ExternalAsmPrefix=''; // win32
   {$ENDIF win32}
-{$ENDIF CPU86}
-
-{$IFDEF VER1_0}
-  {$IFDEF ENDIAN_LITTLE}
-    {$DEFINE FPC_LITTLE_ENDIAN}
-  {$ENDIF ENDIAN_LITTLE}
-  {$IFDEF ENDIAN_BIG}
-    {$DEFINE FPC_BIG_ENDIAN}
-  {$ENDIF ENDIAN_BIG}
-  Type
-    PtrInt = LongInt;
-    PtrUInt = Cardinal;
-{$ENDIF VER1_0}
+{$ENDIF I386_ASSEMBLER}
 
 {$IFDEF FPC_LITTLE_ENDIAN}
   {$IFDEF FPC_BIG_ENDIAN}
@@ -51,10 +55,3 @@
     {$FATAL Neither FPC_LITTLE_ENDIAN, nor FPC_BIG_ENDIAN defined?!}
   {$ENDIF FPC_BIG_ENDIAN}
 {$ENDIF FPC_LITTLE_ENDIAN}
-
-{$IFDEF FPC_LITTLE_ENDIAN}
-  {$INFO FPC_LITTLE_ENDIAN}
-{$ENDIF FPC_LITTLE_ENDIAN}
-{$IFDEF FPC_BIG_ENDIAN}
-  {$INFO FPC_BIG_ENDIAN}
-{$ENDIF FPC_BIG_ENDIAN}

+ 232 - 213
packages/hermes/src/hermes.pp

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,65 +30,77 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 }
 
-Unit Hermes;
+unit Hermes;
 
 {$MODE objfpc}
 
-Interface
+interface
 
-Const
+const
   HERMES_CONVERT_NORMAL = 0;
   HERMES_CONVERT_DITHER = 1;
 
-Type
-  THermesHandle = Integer;
-  Pint32 = ^int32;
-  int32 = DWord;
-  Pshort16 = ^short16;
-  short16 = Word;
-  Pchar8 = ^char8;
-  char8 = Byte;
+type
+  THermesConverterHandle = Pointer;
+  THermesPaletteHandle = Pointer;
+  THermesClearerHandle = Pointer;
+  PUint8  = ^Uint8;
+  PUint16 = ^Uint16;
+  PUint32 = ^Uint32;
+  PUint64 = ^Uint64;
+  PSint8  = ^Sint8;
+  PSint16 = ^Sint16;
+  PSint32 = ^Sint32;
+  PSint64 = ^Sint64;
+  Uint8  = Byte;
+  Uint16 = Word;
+  Uint32 = DWord;
+  Uint64 = QWord;
+  Sint8  = ShortInt;
+  Sint16 = SmallInt;
+  Sint32 = LongInt;
+  Sint64 = Int64;
   PHermesFormat = ^THermesFormat;
-  THermesFormat = Record
-    r,g,b,a : int32;
-    bits : Integer;
-    indexed : Boolean;
-    has_colorkey : Boolean;
-    colorkey : int32;
-  End;
+  THermesFormat = record
+    r,g,b,a: Uint32;
+    bits: Integer;
+    indexed: Boolean;
+    has_colorkey: Boolean;
+    colorkey: Uint32;
+  end;
 
-Function Hermes_FormatNewEmpty : PHermesFormat;
+function Hermes_FormatNewEmpty: PHermesFormat;
 
-{ Create a new format structure, returns 0 if failed. }
-Function Hermes_FormatNew(bits : Integer; r, g, b, a : int32;
-                          indexed : Boolean) : PHermesFormat;
+{ Create a new format structure, returns nil if failed. }
+function Hermes_FormatNew(bits: Integer; r, g, b, a: Uint32;
+                          indexed: Boolean): PHermesFormat;
 
 { Free a format structure }
-Procedure Hermes_FormatFree(fmt : PHermesFormat);
+procedure Hermes_FormatFree(fmt: PHermesFormat);
 
-{ Create a new format structure with colorkey info, returns 0 if failed. }
-Function Hermes_FormatNewEx(bits : Integer; r, g, b, a : int32;
-                            indexed, has_colorkey : Boolean;
-                            colorkey : int32) : PHermesFormat;
+{ Create a new format structure with colorkey info, returns nil if failed. }
+function Hermes_FormatNewEx(bits: Integer; r, g, b, a: Uint32;
+                            indexed, has_colorkey: Boolean;
+                            colorkey: Uint32): PHermesFormat;
 
 { Compare two formats. Return true if they are equal, false otherwise }
-Function Hermes_FormatEquals(op1, op2 : PHermesFormat) : Boolean;
+function Hermes_FormatEquals(op1, op2: PHermesFormat): Boolean;
 
 { Copy the contents of format 'source' to format 'destination' }
-Procedure Hermes_FormatCopy(source, dest : PHermesFormat);
+procedure Hermes_FormatCopy(source, dest: PHermesFormat);
 
 
 {
    Get a converter to work with, specifying a combination of the flags
-   above. Returns 0 if unsuccessful.
+   above. Returns nil if unsuccessful.
 }
-Function Hermes_ConverterInstance(flags : DWord) : THermesHandle;
+function Hermes_ConverterInstance(flags: DWord): THermesConverterHandle;
 
 {
    Return a converter if it is not needed anymore, thus releasing some
    memory.
 }
-Procedure Hermes_ConverterReturn(handle : THermesHandle);
+procedure Hermes_ConverterReturn(handle: THermesConverterHandle);
 
 {
    Request a format conversion between two formats. This function returns false
@@ -84,27 +108,27 @@ Procedure Hermes_ConverterReturn(handle : THermesHandle);
    Repeated calls to this function will be cached an terminate almost
    immediately, so don't be ashamed of calling it often.
 }
-Function Hermes_ConverterRequest(handle : THermesHandle;
-                                 source, dest : PHermesFormat) : Boolean;
+function Hermes_ConverterRequest(handle: THermesConverterHandle;
+                                 source, dest: PHermesFormat): Boolean;
 
 {
    Set the palette of the source surface / destination surface for a
    subsequent conversion. At the moment, only sourcepal is used.
    Returns false if unsuccessful (invalid handle!).
 }
-Function Hermes_ConverterPalette(handle, sourcepal, destpal : THermesHandle) : Boolean;
+function Hermes_ConverterPalette(handle: THermesConverterHandle; sourcepal, destpal: THermesPaletteHandle): Boolean;
 
 {
-   Do a format conversion after calling the setup routines above. This will
+   do a format conversion after calling the setup routines above. This will
    convert (or copy) the pixel data from s_pixels to the data in d_pixels.
    Both source and destination areas/origins can be specified as well as
    the scanline width in bytes of the source/destination.
    Returns false if unsuccessful (invalid handle or request not called before).
 }
-Function Hermes_ConverterCopy(handle : THermesHandle; s_pixels : Pointer;
-                              s_x, s_y, s_width, s_height, s_pitch : Integer;
-                              d_pixels : Pointer; d_x, d_y, d_width,
-                              d_height, d_pitch : Integer) : Boolean;
+function Hermes_ConverterCopy(handle: THermesConverterHandle; s_pixels: Pointer;
+                              s_x, s_y, s_width, s_height, s_pitch: Integer;
+                              d_pixels: Pointer; d_x, d_y, d_width,
+                              d_height, d_pitch: Integer): Boolean;
 
 (*
 {-----------------H_BLIT---------------}
@@ -113,13 +137,13 @@ Function Hermes_ConverterCopy(handle : THermesHandle; s_pixels : Pointer;
    Get a blitter to work with, specifying a combination of the flags
    in H_Conv. Returns 0 if unsuccessful.
 }
-Function Hermes_BlitterInstance(flags : DWord) : THermesHandle;
+function Hermes_BlitterInstance(flags: DWord): THermesHandle;
 
 {
    Return a blitter if it is not needed anymore, thus releasing some
    memory.
 }
-Procedure Hermes_BlitterReturn(handle : THermesHandle);
+procedure Hermes_BlitterReturn(handle: THermesHandle);
 
 {
    Request a format blitting between two formats. This function returns false
@@ -127,101 +151,101 @@ Procedure Hermes_BlitterReturn(handle : THermesHandle);
    Repeated calls to this function will be cached an terminate almost
    immediately, so don't be ashamed of calling it often.
 }
-Function Hermes_BlitterRequest(handle : THermesHandle;
-                               source, dest : PHermesFormat) : Boolean;
+function Hermes_BlitterRequest(handle: THermesHandle;
+                               source, dest: PHermesFormat): Boolean;
 
 {
    Set the palette of the source surface / destination surface for a
    subsequent blitting. At the moment, only sourcepal is used.
    Returns false if unsuccessful (invalid handle!).
 }
-Function Hermes_BlitterPalette(handle, sourcepal, destpal : THermesHandle) : Boolean;
+function Hermes_BlitterPalette(handle, sourcepal, destpal: THermesHandle): Boolean;
 
 {
-   Do a format blitting after calling the setup routines above. This will
+   do a format blitting after calling the setup routines above. This will
    blit the pixel data from s_pixels to the data in d_pixels.  Both source
    and destination areas/origins can be specified as well as the scanline
    width in bytes of the source/destination.  Returns false if unsuccessful
    (invalid handle or request not called before).
 }
-Function Hermes_BlitterBlit(handle : THermesHandle; s_pixels : Pointer;
-                            s_x, s_y, s_width, s_height, s_pitch : Integer;
-                            d_pixels : Pointer; d_x, d_y, d_width, d_height,
-                            d_pitch : Integer) : Boolean;
+function Hermes_BlitterBlit(handle: THermesHandle; s_pixels: Pointer;
+                            s_x, s_y, s_width, s_height, s_pitch: Integer;
+                            d_pixels: Pointer; d_x, d_y, d_width, d_height,
+                            d_pitch: Integer): Boolean;
 *)
 {-----------------H_PAL---------------}
 
 { Get a handle for a palette to work with. This allocates memory for an
-   internal palette. Returns 0 if failed.
+   internal palette. Returns nil if failed.
 }
-Function Hermes_PaletteInstance : THermesHandle;
+function Hermes_PaletteInstance: THermesPaletteHandle;
 
 {
    Return a handle for a palette if the palette isn't used anymore. The
    internal palette will be deallocated.
 }
-Procedure Hermes_PaletteReturn(handle : THermesHandle);
+procedure Hermes_PaletteReturn(handle: THermesPaletteHandle);
 
 {
    Copy the contents of the palette parameter provided into the internal
    palette. The user palette has to be 256*4 bytes long.
 }
-Procedure Hermes_PaletteSet(handle : THermesHandle; palette : Pointer);
+procedure Hermes_PaletteSet(handle: THermesPaletteHandle; palette: Pointer);
 
 {
    Return the pointer to the internal palette. The palette is 256*4 bytes
    long.
 }
-Function Hermes_PaletteGet(handle : THermesHandle) : Pointer;
+function Hermes_PaletteGet(handle: THermesPaletteHandle): Pointer;
 
 {
    Force invalidation of the palette cache. This will force lookup tables to
    be regenerated and has to be done manually after PaletteGet has been used
    and the data has been modified without the knowledge of Hermes.
 }
-Procedure Hermes_PaletteInvalidateCache(handle : THermesHandle);
+procedure Hermes_PaletteInvalidateCache(handle: THermesPaletteHandle);
 
 
 {-----------------H_CLEAR---------------}
 
 {
-   Get a handle for a new clearer instance to work with. Returns 0 if failed.
+   Get a handle for a new clearer instance to work with. Returns nil if failed.
 }
-Function Hermes_ClearerInstance : THermesHandle;
+function Hermes_ClearerInstance: THermesClearerHandle;
 
 {
    Return the clearer instance if it is no longer needed.
 }
-Procedure Hermes_ClearerReturn(handle : THermesHandle);
+procedure Hermes_ClearerReturn(handle: THermesClearerHandle);
 
 {
    Request the clearing routines to be set up for clearing to a specific
    format later. Repeated calls to the routine will be cached and terminate
    after a short check.
 }
-Function Hermes_ClearerRequest(handle : THermesHandle; format : PHermesFormat) : Boolean;
+function Hermes_ClearerRequest(handle: THermesClearerHandle; format: PHermesFormat): Boolean;
 
 {
    Clear a surface. pixels points to the pixel data, x1, y1, width, height
    specify the area to clear, pitch is the width of a scanline in bytes,
    the rest are the colour components.
 }
-Function Hermes_ClearerClear(handle : THermesHandle; pixels : Pointer;
-                             x1, y1, width, height, pitch : Integer;
-                             r, g, b : int32; index : char8) : Boolean;
+function Hermes_ClearerClear(handle: THermesClearerHandle; pixels: Pointer;
+                             x1, y1, width, height, pitch: Integer;
+                             r, g, b: Uint32; index: Uint8): Boolean;
 
 
 { Initialise Hermes, returns false if failed }
-Function Hermes_Init : Boolean;
+function Hermes_Init: Boolean;
 
 { Deinitialise Hermes, returns false if failed }
-Function Hermes_Done : Boolean;
+function Hermes_Done: Boolean;
 
-Implementation
+implementation
 
 {$I hermdef.inc}
 
-Const
+const
   PROC_GENERIC = 1;
   PROC_X86_PENTIUM = 2;
   PROC_MMX_PENTIUM = 4;
@@ -229,102 +253,103 @@ Const
 
 {$I hermconf.inc}
 
-Type
+type
+  THermesHandle = Integer;
   PHermesClearInterface = ^THermesClearInterface;
-  THermesClearInterface = Record
-    dest : ^char8;
-    value : int32;
-    width, height : Integer;
-    add : Integer;
-  End;
-  THermesClearPtr = Procedure(hci : PHermesClearInterface); CDecl;
+  THermesClearInterface = record
+    dest: ^Uint8;
+    value: Uint32;
+    width, height: Integer;
+    add: Integer;
+  end;
+  THermesClearPtr = procedure(hci: PHermesClearInterface); cdecl;
   PHermesClearer = ^THermesClearer;
-  THermesClearer = Record
-    bits : Integer;
-    func : THermesClearPtr;
-  End;
+  THermesClearer = record
+    bits: Integer;
+    func: THermesClearPtr;
+  end;
 
 
 { Structure to hold shift amounts for the generic routines }
   PHermesGenericInfo = ^THermesGenericInfo;
-  THermesGenericInfo = Record
-    r_right, g_right, b_right, a_right : Integer; {Shift amount to the right}
-    r_left, g_left, b_left, a_left : Integer; {Shift amount to the right}
-  End;
+  THermesGenericInfo = record
+    r_right, g_right, b_right, a_right: Integer; {Shift amount to the right}
+    r_left, g_left, b_left, a_left: Integer; {Shift amount to the right}
+  end;
 
 
 { Pointer to specialised (one-scanline-only) conversion procedure }
-  THermesConverterPtr = Procedure(source, dest : Pchar8;
-                                  count, inc_source : DWord); CDecl;
+  THermesConverterPtr = procedure(source, dest: PUint8;
+                                  count, inc_source: DWord); cdecl;
 
 { Structure for conversion loop routines, don't be scared, size does NOT
    matter in this case :) }
   PHermesConverterInterface = ^THermesConverterInterface;
-  THermesConverterInterface = Record
-    s_pixels : Pchar8;
-    s_width,s_height : Integer;
-    s_add : Integer;          { Offset to next line from end of line }
+  THermesConverterInterface = record
+    s_pixels: PUint8;
+    s_width,s_height: Integer;
+    s_add: Integer;          { Offset to next line from end of line }
 
-    d_pixels : Pchar8;
-    d_width,d_height : Integer;
-    d_add : Integer;
+    d_pixels: PUint8;
+    d_width,d_height: Integer;
+    d_add: Integer;
 
-    func : THermesConverterPtr;
+    func: THermesConverterPtr;
 
-    lookup : Pint32;          { Palette lookup table ptr, for 8 bit }
+    lookup: PUint32;          { Palette lookup table ptr, for 8 bit }
 
-    s_pitch : Integer;        { Source and destination pitch, }
-    d_pitch : Integer;        { only used by C routines }
+    s_pitch: Integer;        { Source and destination pitch, }
+    d_pitch: Integer;        { only used by C routines }
 
-    info : THermesGenericInfo; { Only used by generic converters }
-    mask_r, mask_g, mask_b, mask_a : int32; { Only used by generic converters }
-    s_mask_a : int32;
+    info: THermesGenericInfo; { Only used by generic converters }
+    mask_r, mask_g, mask_b, mask_a: Uint32; { Only used by generic converters }
+    s_mask_a: Uint32;
 
-    s_has_colorkey : Boolean;
-    s_colorkey : int32;
+    s_has_colorkey: Boolean;
+    s_colorkey: Uint32;
 
-    d_has_colorkey : Boolean;
-    d_colorkey : int32;
-  End;
+    d_has_colorkey: Boolean;
+    d_colorkey: Uint32;
+  end;
 
 { Pointer to loop function (C, assembler main loop, generic routines) }
-  THermesConverterLoopPtr = Procedure(hci : PHermesConverterInterface); CDecl;
+  THermesConverterLoopPtr = procedure(hci: PHermesConverterInterface); cdecl;
 
   PHermesConverter = ^THermesConverter;
-  THermesConverter = Record
-    source,dest : THermesFormat;           { Source and destination format }
-    lookup : Pint32;                       { Pointer to lookup table (8bit) }
+  THermesConverter = record
+    source,dest: THermesFormat;           { Source and destination format }
+    lookup: PUint32;                       { Pointer to lookup table (8bit) }
 
-    flags : DWord;                         { Defined in H_Conv.h, DITHER,etc}
+    flags: DWord;                         { Defined in H_Conv.h, DITHER,etc}
 
-    loopnormal : THermesConverterLoopPtr;  { Loop routine for normal conv. }
-    loopstretch : THermesConverterLoopPtr;
-    normal : THermesConverterPtr;          { One-scanline routine }
-    stretch : THermesConverterPtr;
+    loopnormal: THermesConverterLoopPtr;  { Loop routine for normal conv. }
+    loopstretch: THermesConverterLoopPtr;
+    normal: THermesConverterPtr;          { One-scanline routine }
+    stretch: THermesConverterPtr;
 
-    dither : THermesConverterLoopPtr;        { Dithering routines always }
-    ditherstretch : THermesConverterLoopPtr; { convert the whole buffer }
-  End;
+    dither: THermesConverterLoopPtr;        { Dithering routines always }
+    ditherstretch: THermesConverterLoopPtr; { convert the whole buffer }
+  end;
 
   PHermesFactoryStruct = ^THermesFactoryStruct;
-  THermesFactoryStruct = Record
-    s_bits : Integer;
-    s_idx : Boolean;
-    s_r, s_g, s_b, s_a : int32;
-    d_bits : Integer;
-    d_idx : Boolean;
-    d_r, d_g, d_b, d_a : int32;
+  THermesFactoryStruct = record
+    s_bits: Integer;
+    s_idx: Boolean;
+    s_r, s_g, s_b, s_a: Uint32;
+    d_bits: Integer;
+    d_idx: Boolean;
+    d_r, d_g, d_b, d_a: Uint32;
 
-    loopnormal, loopstretch : THermesConverterLoopPtr;
-    normal, stretch : THermesConverterPtr;
-    dither, ditherstretch : THermesConverterLoopPtr;
+    loopnormal, loopstretch: THermesConverterLoopPtr;
+    normal, stretch: THermesConverterPtr;
+    dither, ditherstretch: THermesConverterLoopPtr;
 
-    processor : Integer;
-  End;
+    processor: Integer;
+  end;
 
 {dither types ?}
 
-Const
+const
 { p_converters holds a list of formats, for conversion from 32 bit, 24 bit,
   16 bit, muhmu and 8 bit.
   The destination formats are listed in the order of frequency they might
@@ -336,7 +361,7 @@ Const
 }
 { I wish I could touch this, but it's used in too many other placed in the code,
   ( at least indirectly), and many of the indicies are hardcoded }
-  p_converters : Array[0..4, 0..11, 0..11] Of DWord =
+  p_converters: array [0..4, 0..11, 0..11] of DWord =
   (
   ( {From 32 bit RGB 888}
   (32,0,$ff0000,$ff00,$ff,0,16,0,$f800,$7e0,$1f,0),          {16RGB565 }
@@ -404,47 +429,43 @@ Const
   (0,0,0,0,0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0,0,0,0,0)
   )
   );
-  numConverters : Array[0..4] Of Integer = (10,10,10,11,4);
-  refcount : Integer = 0;
-
-Var
-  Clearers : Array[0..3] Of PHermesClearer;
-  numClearers : Integer;
-  standardConverters : Array[0..4] Of ^PHermesConverter;
-  equalConverters : Array[0..3] Of PHermesConverter;
+  numConverters: array [0..4] of Integer = (10,10,10,11,4);
+  refcount: Integer = 0;
 
-{$I malloc.inc}
+var
+  Clearers: array [0..3] of PHermesClearer;
+  numClearers: Integer;
+  standardConverters: array [0..4] of ^PHermesConverter;
+  equalConverters: array [0..3] of PHermesConverter;
 
-{$I debug.inc}
+{$I hermes_debug.inc}
 
-{$I dither.inc}
+{$I hermes_dither.inc}
 {$I headp.inc}
 {$IFDEF I386_ASSEMBLER}
   {$I i386/headi386.inc}
   {$I i386/headmmx.inc}
 {$ENDIF I386_ASSEMBLER}
 {$I factconv.inc}
-{$I list.inc}
-{$I utility.inc}
-{$I format.inc}
-{$I palette.inc}
-{$I convert.inc}
-{$I clear.inc}
-{$I factory.inc}
-
-Function Hermes_Init : Boolean;
-
-Var
-  i, j : Integer;
-  source, dest : THermesFormat;
-
-Begin
-  If refcount > 0 Then
-  Begin
+{$I hermes_list.inc}
+{$I hermes_utility.inc}
+{$I hermes_format.inc}
+{$I hermes_palette.inc}
+{$I hermes_converter.inc}
+{$I hermes_clearer.inc}
+{$I hermes_factory.inc}
+
+function Hermes_Init: Boolean;
+var
+  i, j: Integer;
+  source, dest: THermesFormat;
+begin
+  if refcount > 0 then
+  begin
     Inc(refcount);
-    Hermes_Init := True;
-    Exit;
-  End;
+    Result := True;
+    exit;
+  end;
   { Initialise hermes factory }
   Hermes_Factory_Init;
 
@@ -456,11 +477,11 @@ Begin
   numClearers := 4;
 
   { Use factory to obtain specialised converters }
-  For j := 0 To 4 Do
-  Begin
-    standardConverters[j] := malloc(SizeOf(PHermesConverter)*numConverters[j]);
-    For i := 0 To numConverters[j] - 1 Do
-    Begin
+  for j := 0 to 4 do
+  begin
+    standardConverters[j] := GetMem(SizeOf(PHermesConverter)*numConverters[j]);
+    for i := 0 to numConverters[j] - 1 do
+    begin
       // xxx jm color keys not taken into consideration here
       FillChar(source, SizeOf(source), 0);
       FillChar(dest, SizeOf(dest), 0);
@@ -472,8 +493,8 @@ Begin
       source.a := p_converters[j, i, 5];       dest.a := p_converters[j, i, 11];
 
       standardConverters[j][i] := Hermes_Factory_getConverter(@source, @dest);
-    End;
-  End;
+    end;
+  end;
 
 
   { Set up converters for equal colour formats }
@@ -486,51 +507,49 @@ Begin
   Dither_SetupMatrices;
 
   Inc(refcount);
-  Hermes_Init := True;
-End;
-
-Function Hermes_Done : Boolean;
-
-Var
-  i, j : Integer;
+  Result := True;
+end;
 
-Begin
+function Hermes_Done: Boolean;
+var
+  i, j: Integer;
+begin
   Dec(refcount);
-  If refcount < 0 Then
-  Begin
+  if refcount < 0 then
+  begin
     refcount := 0;
-    Hermes_Done := False;
-    Exit;
-  End;
-  If refcount = 0 Then
-  Begin
-    For i := 0 To 3 Do
-    Begin
-      If Clearers[i] <> Nil Then
-      Begin
-        free(Clearers[i]);
-        Clearers[i] := Nil;
-      End;
-      If equalConverters[i] <> Nil Then
-      Begin
-        free(equalConverters[i]);
-        equalConverters[i] := Nil;
-      End;
-    End;
-    For i := 0 To 4 Do
-    Begin
-      If standardConverters[i] <> Nil Then
-      Begin
-        For j := 0 To numConverters[i] - 1 Do
-          free(standardConverters[i][j]);
-        free(standardConverters[i]);
-      End;
-      standardConverters[i] := Nil;
-    End;
-  End;
-  Hermes_Done := True;
-End;
-
-Begin
+    Result := False;
+    exit;
+  end;
+  if refcount = 0 then
+  begin
+    for i := 0 to 3 do
+    begin
+      if Clearers[i] <> nil then
+      begin
+        Dispose(Clearers[i]);
+        Clearers[i] := nil;
+      end;
+      if equalConverters[i] <> nil then
+      begin
+        Dispose(equalConverters[i]);
+        equalConverters[i] := nil;
+      end;
+    end;
+    for i := 0 to 4 do
+    begin
+      if standardConverters[i] <> nil then
+      begin
+        for j := 0 to numConverters[i] - 1 do
+          Dispose(standardConverters[i][j]);
+        FreeMem(standardConverters[i]);
+        standardConverters[i] := nil;
+      end;
+    end;
+  end;
+  Result := True;
+end;
+
+begin
   DebugInit;
-End.
+end.

+ 156 - 0
packages/hermes/src/hermes_clearer.inc

@@ -0,0 +1,156 @@
+{
+    Free Pascal port of the Hermes C library.
+    Copyright (C) 2001-2003  Nikolay Nikolov ([email protected])
+    Original C version by Christian Nentwich ([email protected])
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+}
+
+type
+  PClearerInstance = ^TClearerInstance;
+  TClearerInstance = record
+    format: PHermesFormat;
+    func: THermesClearPtr;
+  end;
+
+function Hermes_ClearerInstance: THermesClearerHandle;
+var
+  newinstance: PClearerInstance;
+begin
+  New(newinstance);
+  newinstance^.func := nil;
+  newinstance^.format := Hermes_FormatNewEmpty;
+  Result := THermesClearerHandle(newinstance);
+end;
+
+procedure Hermes_ClearerReturn(handle: THermesClearerHandle);
+begin
+  if handle <> nil then
+  begin
+    Hermes_FormatFree(PClearerInstance(handle)^.format);
+    Dispose(PClearerInstance(handle));
+  end;
+end;
+
+function Hermes_ClearerRequest(handle: THermesClearerHandle; format: PHermesFormat): Boolean;
+var
+  clr: PClearerInstance;
+  i: Integer;
+begin
+  if handle = nil then
+  begin
+    Result := False;
+    exit;
+  end;
+  clr := PClearerInstance(handle);
+
+  { if the clearer is the same, return 1 }
+  if Hermes_FormatEquals(clr^.format, format) then
+  begin
+    Result := True;
+    exit;
+  end;
+
+  { Otherwise look for a new clearer }
+  clr^.func := nil;
+  for i := 0 to numClearers - 1 do
+  begin
+    if Clearers[i]^.bits = format^.bits then
+    begin
+      clr^.func := Clearers[i]^.func;
+      Hermes_FormatCopy(format, clr^.format);
+      Result := True;
+      exit;
+    end;
+  end;
+  Result := False;
+end;
+
+function Hermes_ClearerClear(handle: THermesClearerHandle; pixels: Pointer;
+                             x1, y1, width, height, pitch: Integer;
+                             r, g, b: Uint32; index: Uint8): Boolean;
+var
+  info: THermesGenericInfo;
+  clr: PClearerInstance;
+  pixelval, d_r, d_g, d_b, d_a: Uint32;
+  iface: THermesClearInterface;
+begin
+  if (height <= 0) or (width <= 0) then
+  begin
+    Result := True;
+    exit;
+  end;
+
+  if handle = nil then
+  begin
+    Result := False;
+    exit;
+  end;
+  clr := PClearerInstance(handle);
+
+  { No conversion function assigned }
+  if clr^.func = nil then
+  begin
+    Result := False;
+    exit;
+  end;
+
+  if clr^.format^.indexed then
+    pixelval := index
+  else
+  begin
+    Hermes_Calculate_Generic_Info(24, 16, 8, 32,
+                                  Hermes_Topbit(clr^.format^.r),
+                                  Hermes_Topbit(clr^.format^.g),
+                                  Hermes_Topbit(clr^.format^.b),
+                                  Hermes_Topbit(clr^.format^.a), @info);
+    pixelval := (index shl 24) or (r shl 16) or (g shl 8) or b;
+    d_r := ((pixelval shr info.r_right) shl info.r_left) and clr^.format^.r;
+    d_g := ((pixelval shr info.g_right) shl info.g_left) and clr^.format^.g;
+    d_b := ((pixelval shr info.b_right) shl info.b_left) and clr^.format^.b;
+    d_a := ((pixelval shr info.a_right) shl info.a_left) and clr^.format^.a;
+    pixelval := d_r or d_g or d_b or d_a;
+  end;
+  iface.dest := pixels;
+  Inc(iface.dest, y1*pitch + x1*(clr^.format^.bits shr 3));
+
+  iface.width := width;
+  iface.height := height;
+  iface.add := pitch - width * (clr^.format^.bits shr 3);
+
+  iface.value := pixelval;
+
+  { Optimization }
+  if iface.add = 0 then
+  begin
+    iface.width := iface.width * iface.height;
+    iface.height := 1;
+  end;
+
+  clr^.func(@iface);
+  Result := True;
+end;

+ 350 - 427
packages/hermes/src/convert.inc → packages/hermes/src/hermes_converter.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,202 +30,115 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 }
 
-
-{Function Hermes_ConverterInstance(flags : DWord) : THermesHandle;
-Procedure Hermes_ConverterReturn(handle : THermesHandle);}
-
-Var
-{ ConverterList is a list of HermesConverter* }
-  ConverterList : ^PHermesConverter;
-  ConvertCurrenthandle : THermesHandle;
-
-Const
-  lastConverter : Integer = 0;                { Array size, one beyond end }
-  CONVERTrefcount : Integer = 0;
-
-Function Hermes_ConverterInstance(flags : DWord) : THermesHandle;
-
-Var
-  i : Integer;
-  newinstance : PHermesConverter;
-  newlist : ^PHermesConverter;
-
-Begin
-  { Initialising, allocate initial size array of converters }
-  If CONVERTrefcount = 0 Then
-  Begin
-    ConverterList := malloc(SizeOf(PHermesConverter) * HERMES_INITIAL);
-    If ConverterList = Nil Then
-    Begin
-      Hermes_ConverterInstance := 0;
-      Exit;
-    End;
-    lastConverter := HERMES_INITIAL;
-    ConvertCurrenthandle := 1;
-    For i := 0 To lastConverter - 1 Do
-      ConverterList[i] := Nil;
-{    DEBUG_PRINT("Creating dynamic array(convert.c:57), size %d\n",HERMES_INITIAL)}
-  End;
-
-  { Uh oh, arrary too small, time for growth }
-  If ConvertCurrenthandle = lastConverter Then
-  Begin
-    { I'm told realloc isn't completely portable !? Let's do it by hand }
-    newlist := malloc(SizeOf(PHermesConverter)*(lastConverter+HERMES_GROWTH));
-    If newlist = Nil Then
-    Begin
-      Hermes_ConverterInstance := 0;
-      Exit;
-    End;
-    { Copy converter pointers }
-    For i := 0 To lastConverter - 1 Do
-      newlist[i] := ConverterList[i];
-    free(ConverterList);
-    { Assign new list to old one }
-    ConverterList := newlist;
-    Inc(lastConverter, HERMES_GROWTH);
-{    DEBUG_PRINT("Growing dynamic array, new size %d\n",lastConverter)}
-  End;
-
+function Hermes_ConverterInstance(flags: DWord): THermesConverterHandle;
+var
+  newinstance: PHermesConverter;
+begin
   { Create a HermesConverter }
-  newinstance := malloc(sizeof(THermesConverter));
-  If newinstance = Nil Then
-  Begin
-    Hermes_ConverterInstance := 0;
-    Exit;
-  End;
+  New(newinstance);
 
   { Zero it out }
-  newinstance^.loopnormal := Nil;
-  newinstance^.loopstretch := Nil;
-  newinstance^.normal := Nil;
-  newinstance^.stretch := Nil;
-  newinstance^.dither := Nil;
-  newinstance^.ditherstretch := Nil;
+  newinstance^.loopnormal := nil;
+  newinstance^.loopstretch := nil;
+  newinstance^.normal := nil;
+  newinstance^.stretch := nil;
+  newinstance^.dither := nil;
+  newinstance^.ditherstretch := nil;
   newinstance^.flags := flags;
   FillChar(newinstance^.source, 0, SizeOf(THermesFormat));
   FillChar(newinstance^.dest, 0, SizeOf(THermesFormat));
 
-  ConverterList[ConvertCurrenthandle] := newinstance;
-
-  Inc(CONVERTrefcount);
-  Inc(ConvertCurrenthandle);
-
-  Hermes_ConverterInstance := ConvertCurrenthandle - 1;
-End;
-
-Procedure Hermes_ConverterReturn(handle : THermesHandle);
-
-Begin
-  If (handle < 0) Or (handle >= lastConverter) Then
-    Exit;
-
-  { Adjust reference count }
-  Dec(CONVERTrefcount);
-
-  If ConverterList[handle] <> Nil Then
-  Begin
-    free(ConverterList[handle]);
-    ConverterList[handle] := Nil;
-  End;
-
-  { No more references, deinitialise }
-  If CONVERTrefcount = 0 Then
-  Begin
-    If ConverterList <> Nil Then
-    Begin
-      free(ConverterList);
-      ConverterList := Nil;
-    End;
-    ConvertCurrenthandle := 0;
-    lastConverter := 0;
-  End;
-End;
-
-Function Hermes_ConverterRequest(handle : THermesHandle;
-                                 source, dest : PHermesFormat) : Boolean;
-
-Var
-  searchlist : Integer;
-  i : Integer;
-  found : Boolean;
-  cnv : PHermesConverter;
-
-Begin
+  Result := THermesConverterHandle(newinstance);
+end;
+
+procedure Hermes_ConverterReturn(handle: THermesConverterHandle);
+begin
+  if handle = nil then
+    exit;
+
+  Dispose(PHermesConverter(handle));
+end;
+
+function Hermes_ConverterRequest(handle: THermesConverterHandle;
+                                 source, dest: PHermesFormat): Boolean;
+var
+  searchlist: Integer;
+  i: Integer;
+  found: Boolean;
+  cnv: PHermesConverter;
+begin
 {  DebugMSG('Hermes_ConverterRequest(' + C2Str(source^.bits)
    + ',' + C2Str(source^.r) + ',' + C2Str(source^.g) + ',' +
    C2Str(source^.b) + ';' + C2Str(dest^.bits)
    + ',' + C2Str(dest^.r) + ',' + C2Str(dest^.g) + ',' +
    C2Str(dest^.b) + ')');}
 
-  Hermes_ConverterRequest := False;
+  Result := False;
   searchlist := 0;
   i := 0;
   found := False;
   { Check array ranges }
-  If (handle < 0) Or (handle >= lastConverter) Then
-    Exit;
-  If ConverterList[handle] = Nil Then
-    Exit;
-  cnv := ConverterList[handle];
+  if handle = nil then
+    exit;
+  cnv := PHermesConverter(handle);
 
   { Cache repeated requests of the same conversion }
-  If Hermes_FormatEquals(source, @ConverterList[handle]^.source) And
-     Hermes_FormatEquals(dest, @ConverterList[handle]^.dest) Then
-  Begin
-    Hermes_ConverterRequest := True;
-    Exit;
-  End;
+  if Hermes_FormatEquals(source, @cnv^.source) and
+     Hermes_FormatEquals(dest, @cnv^.dest) then
+  begin
+    Result := True;
+    exit;
+  end;
 
   { Clear the generic converter flag }
-  cnv^.flags := cnv^.flags And (Not HERMES_CONVERT_GENERIC);
+  cnv^.flags := cnv^.flags and (not HERMES_CONVERT_GENERIC);
 
-  { If the source and destination are equal, use copy routines }
-  If Hermes_FormatEquals(source, dest) Then
-  Begin
+  { if the source and destination are equal, use copy routines }
+  if Hermes_FormatEquals(source, dest) then
+  begin
 {    DebugMSG('format equals!');}
-    If ((source^.bits And 7) <> 0) Or (source^.bits > 32) Or
-       (source^.bits = 0) Then
-      Exit;
-    i := (source^.bits Shr 3) - 1;
-    If equalConverters[i] = Nil Then
-      Exit;
+    if ((source^.bits and 7) <> 0) or (source^.bits > 32) or
+       (source^.bits = 0) then
+      exit;
+    i := (source^.bits shr 3) - 1;
+    if equalConverters[i] = nil then
+      exit;
     Hermes_FormatCopy(source, @cnv^.source);
     Hermes_FormatCopy(dest, @cnv^.dest);
     cnv^.loopnormal := equalConverters[i]^.loopnormal;
     cnv^.loopstretch := equalConverters[i]^.loopstretch;
     cnv^.normal := equalConverters[i]^.normal;
     cnv^.stretch := equalConverters[i]^.stretch;
-    Hermes_ConverterRequest := True;
-    Exit;
-  End;
+    Result := True;
+    exit;
+  end;
 
   { Start looking for specialised converters }
   searchlist := $ff;
-  Case source^.bits Of
-    32 : If (source^.r = $ff0000) And (source^.g = $ff00) And (source^.b = $ff) Then
+  case source^.bits of
+    32: if (source^.r = $ff0000) and (source^.g = $ff00) and (source^.b = $ff) then
            searchlist := 0
-         Else
-           If (source^.r = ($ff Shl 20)) And
-              (source^.g = ($ff Shl 10)) And
-              (source^.b = $ff) Then
+         else
+           if (source^.r = ($ff shl 20)) and
+              (source^.g = ($ff shl 10)) and
+              (source^.b = $ff) then
              searchlist := 3;
-    24 : If (source^.r = $ff0000) And (source^.g = $ff00) And (source^.b = $ff) Then
+    24: if (source^.r = $ff0000) and (source^.g = $ff00) and (source^.b = $ff) then
            searchlist := 1;
-    16 : If (source^.r = $f800) And (source^.g = $7e0) And (source^.b = $1f) Then
+    16: if (source^.r = $f800) and (source^.g = $7e0) and (source^.b = $1f) then
            searchlist := 2;
-     8 : If source^.indexed Then
+     8: if source^.indexed then
            searchlist := 4;
-  End;
+  end;
 
   { We can use a quicker loop for 8 bit }
-  If searchlist <> $ff Then
-    If source^.bits = 8 Then
-    Begin
-      For i := 0 To numConverters[searchlist] - 1 Do
-        If standardConverters[searchlist][i] <> Nil Then
-          If dest^.bits = standardConverters[searchlist][i]^.dest.bits Then
-          Begin
+  if searchlist <> $ff then
+    if source^.bits = 8 then
+    begin
+      for i := 0 to numConverters[searchlist] - 1 do
+        if standardConverters[searchlist][i] <> nil then
+          if dest^.bits = standardConverters[searchlist][i]^.dest.bits then
+          begin
             Hermes_FormatCopy(source, @cnv^.source);
             Hermes_FormatCopy(dest, @cnv^.dest);
 
@@ -226,17 +151,16 @@ Begin
             cnv^.dither := standardConverters[searchlist][i]^.dither;
             cnv^.ditherstretch := standardConverters[searchlist][i]^.ditherstretch;
 
-            Hermes_ConverterRequest := True;
-            Exit;
-          End
-;
-    End
-    Else
-      For i := 0 To numConverters[searchlist] - 1 Do
-        If standardConverters[searchlist][i] <> Nil Then
-          If Hermes_FormatEquals(@standardConverters[searchlist][i]^.source, source) And
-             Hermes_FormatEquals(@standardConverters[searchlist][i]^.dest, dest) Then
-          Begin
+            Result := True;
+            exit;
+          end;
+    end
+    else
+      for i := 0 to numConverters[searchlist] - 1 do
+        if standardConverters[searchlist][i] <> nil then
+          if Hermes_FormatEquals(@standardConverters[searchlist][i]^.source, source) and
+             Hermes_FormatEquals(@standardConverters[searchlist][i]^.dest, dest) then
+          begin
             Hermes_FormatCopy(source, @cnv^.source);
             Hermes_FormatCopy(dest, @cnv^.dest);
 
@@ -249,20 +173,20 @@ Begin
             cnv^.dither := standardConverters[searchlist][i]^.dither;
             cnv^.ditherstretch := standardConverters[searchlist][i]^.ditherstretch;
 
-            Hermes_ConverterRequest := True;
-            Exit;
-          End;
+            Result := True;
+            exit;
+          end;
 
 
   { Otherwise find a generic converter }
 {  DebugMSG('looking for a generic converter!');}
 
 
-  cnv^.loopnormal := Nil;
-  cnv^.loopstretch := Nil;
-  cnv^.dither := Nil;
-  cnv^.ditherstretch := Nil;
-  cnv^.flags := cnv^.flags Or HERMES_CONVERT_GENERIC;
+  cnv^.loopnormal := nil;
+  cnv^.loopstretch := nil;
+  cnv^.dither := nil;
+  cnv^.ditherstretch := nil;
+  cnv^.flags := cnv^.flags or HERMES_CONVERT_GENERIC;
 
 
   { Generic routines implement whole converters not scanline converters,
@@ -285,394 +209,393 @@ Begin
         O -> O , A, C are the same
 }
 
-  If source^.has_colorkey And dest^.has_colorkey Then { Ck -> Ck }
-    Case source^.bits Of
-      32 : Case dest^.bits Of
-        32 : Begin
+  if source^.has_colorkey and dest^.has_colorkey then { Ck -> Ck }
+    case source^.bits of
+      32: case dest^.bits of
+        32: begin
           cnv^.loopnormal := @ConvertP_Generic32_C_Generic32_C;
           cnv^.loopstretch := @ConvertP_Generic32_C_Generic32_C_S;
           found := True;
-        End;
-        24 : Begin
+        end;
+        24: begin
           cnv^.loopnormal := @ConvertP_Generic32_C_Generic24_C;
           found := True;
-        End;
-        16 : Begin
+        end;
+        16: begin
           cnv^.loopnormal := @ConvertP_Generic32_C_Generic16_C;
           cnv^.loopstretch := @ConvertP_Generic32_C_Generic16_C_S;
           found := True;
-        End;
-        8 : Begin
+        end;
+        8: begin
           cnv^.loopnormal := @ConvertP_Generic32_C_Generic8_C;
           found := True;
-        End;
-      End;
-      24 : Case dest^.bits Of
-        32 : Begin
+        end;
+      end;
+      24: case dest^.bits of
+        32: begin
           cnv^.loopnormal := @ConvertP_Generic24_C_Generic32_C;
           found := True;
-        End;
-        24 : Begin
+        end;
+        24: begin
           cnv^.loopnormal := @ConvertP_Generic24_C_Generic24_C;
           found := True;
-        End;
-        16 : Begin
+        end;
+        16: begin
           cnv^.loopnormal := @ConvertP_Generic24_C_Generic16_C;
           found := True;
-        End;
-        8 : Begin
+        end;
+        8: begin
           cnv^.loopnormal := @ConvertP_Generic24_C_Generic8_C;
           found := True;
-        End;
-      End;
-      16 : Case dest^.bits Of
-        32 : Begin
+        end;
+      end;
+      16: case dest^.bits of
+        32: begin
           cnv^.loopnormal := @ConvertP_Generic16_C_Generic32_C;
           found := True;
-        End;
-        24 : Begin
+        end;
+        24: begin
           cnv^.loopnormal := @ConvertP_Generic16_C_Generic24_C;
           found := True;
-        End;
-        16 : Begin
+        end;
+        16: begin
           cnv^.loopnormal := @ConvertP_Generic16_C_Generic16_C;
           found := True;
-        End;
-        8 : Begin
+        end;
+        8: begin
           cnv^.loopnormal := @ConvertP_Generic16_C_Generic8_C;
           found := True;
-        End;
-      End;
-    End
-  Else
-    If source^.has_colorkey And (dest^.a <> 0) Then { Ck -> A }
-      Case source^.bits Of
-        32 : Case dest^.bits Of
-          32 : Begin
+        end;
+      end;
+    end
+  else
+    if source^.has_colorkey and (dest^.a <> 0) then { Ck -> A }
+      case source^.bits of
+        32: case dest^.bits of
+          32: begin
             cnv^.loopnormal := @ConvertP_Generic32_C_Generic32_A;
             cnv^.loopstretch := @ConvertP_Generic32_C_Generic32_A_S;
             found := True;
-          End;
-          24 : Begin
+          end;
+          24: begin
             cnv^.loopnormal := @ConvertP_Generic32_C_Generic24_A;
             found := True;
-          End;
-          16 : Begin
+          end;
+          16: begin
             cnv^.loopnormal := @ConvertP_Generic32_C_Generic16_A;
             cnv^.loopstretch := @ConvertP_Generic32_C_Generic16_A_S;
             found := True;
-          End;
-          8 : Begin
+          end;
+          8: begin
             cnv^.loopnormal := @ConvertP_Generic32_C_Generic8_A;
             found := True;
-          End;
-        End;
-        24 : Case dest^.bits Of
-          32 : Begin
+          end;
+        end;
+        24: case dest^.bits of
+          32: begin
             cnv^.loopnormal := @ConvertP_Generic24_C_Generic32_A;
             found := True;
-          End;
-          24 : Begin
+          end;
+          24: begin
             cnv^.loopnormal := @ConvertP_Generic24_C_Generic24_A;
             found := True;
-          End;
-          16 : Begin
+          end;
+          16: begin
             cnv^.loopnormal := @ConvertP_Generic24_C_Generic16_A;
             found := True;
-          End;
-          8 : Begin
+          end;
+          8: begin
             cnv^.loopnormal := @ConvertP_Generic24_C_Generic8_A;
             found := True;
-          End;
-        End;
-        16 : Case dest^.bits Of
-          32 : Begin
+          end;
+        end;
+        16: case dest^.bits of
+          32: begin
             cnv^.loopnormal := @ConvertP_Generic16_C_Generic32_A;
             found := True;
-          End;
-          24 : Begin
+          end;
+          24: begin
             cnv^.loopnormal := @ConvertP_Generic16_C_Generic24_A;
             found := True;
-          End;
-          16 : Begin
+          end;
+          16: begin
             cnv^.loopnormal := @ConvertP_Generic16_C_Generic16_A;
             found := True;
-          End;
-          8 : Begin
+          end;
+          8: begin
             cnv^.loopnormal := @ConvertP_Generic16_C_Generic8_A;
             found := True;
-          End;
-        End;
-      End
-    Else
-      If (source^.a <> 0) And dest^.has_colorkey Then { A -> Ck }
-        Case source^.bits Of
-          32 : Case dest^.bits Of
-            32 : Begin
+          end;
+        end;
+      end
+    else
+      if (source^.a <> 0) and dest^.has_colorkey then { A -> Ck }
+        case source^.bits of
+          32: case dest^.bits of
+            32: begin
               cnv^.loopnormal := @ConvertP_Generic32_A_Generic32_C;
               cnv^.loopstretch := @ConvertP_Generic32_A_Generic32_C_S;
               found := True;
-            End;
-            24 : Begin
+            end;
+            24: begin
               cnv^.loopnormal := @ConvertP_Generic32_A_Generic24_C;
               found := True;
-            End;
-            16 : Begin
+            end;
+            16: begin
               cnv^.loopnormal := @ConvertP_Generic32_A_Generic16_C;
               cnv^.loopnormal := @ConvertP_Generic32_A_Generic16_C_S;
               found := True;
-            End;
-            8 : Begin
+            end;
+            8: begin
               cnv^.loopnormal := @ConvertP_Generic32_A_Generic8_C;
               found := True;
-            End;
-          End;
-          24 : Case dest^.bits Of
-            32 : Begin
+            end;
+          end;
+          24: case dest^.bits of
+            32: begin
               cnv^.loopnormal := @ConvertP_Generic24_A_Generic32_C;
               found := True;
-            End;
-            24 : Begin
+            end;
+            24: begin
               cnv^.loopnormal := @ConvertP_Generic24_A_Generic24_C;
               found := True;
-            End;
-            16 : Begin
+            end;
+            16: begin
               cnv^.loopnormal := @ConvertP_Generic24_A_Generic16_C;
               found := True;
-            End;
-            8 : Begin
+            end;
+            8: begin
               cnv^.loopnormal := @ConvertP_Generic24_A_Generic8_C;
               found := True;
-            End;
-          End;
-          16 : Case dest^.bits Of
-            32 : Begin
+            end;
+          end;
+          16: case dest^.bits of
+            32: begin
               cnv^.loopnormal := @ConvertP_Generic16_A_Generic32_C;
               found := True;
-            End;
-            24 : Begin
+            end;
+            24: begin
               cnv^.loopnormal := @ConvertP_Generic16_A_Generic24_C;
               found := True;
-            End;
-            16 : Begin
+            end;
+            16: begin
               cnv^.loopnormal := @ConvertP_Generic16_A_Generic16_C;
               found := True;
-            End;
-            8 : Begin
+            end;
+            8: begin
               cnv^.loopnormal := @ConvertP_Generic16_A_Generic8_C;
               found := True;
-            End;
-          End;
-        End
-      Else
-        If (source^.a <> 0) And (dest^.a <> 0) Then { A -> A }
-          Case source^.bits Of
-            32 : Case dest^.bits Of
-              32 : Begin
+            end;
+          end;
+        end
+      else
+        if (source^.a <> 0) and (dest^.a <> 0) then { A -> A }
+          case source^.bits of
+            32: case dest^.bits of
+              32: begin
                 cnv^.loopnormal := @ConvertP_Generic32_A_Generic32_A;
                 cnv^.loopstretch := @ConvertP_Generic32_A_Generic32_A_S;
                 found := True;
-              End;
-              24 : Begin
+              end;
+              24: begin
                 cnv^.loopnormal := @ConvertP_Generic32_A_Generic24_A;
                 found := True;
-              End;
-              16 : Begin
+              end;
+              16: begin
                 cnv^.loopnormal := @ConvertP_Generic32_A_Generic16_A;
                 cnv^.loopstretch := @ConvertP_Generic32_A_Generic16_A_S;
                 found := True;
-              End;
-              8 : Begin
+              end;
+              8: begin
                 cnv^.loopnormal := @ConvertP_Generic32_A_Generic8_A;
                 found := True;
-              End;
-            End;
-            24 : Case dest^.bits Of
-              32 : Begin
+              end;
+            end;
+            24: case dest^.bits of
+              32: begin
                 cnv^.loopnormal := @ConvertP_Generic24_A_Generic32_A;
                 found := True;
-              End;
-              24 : Begin
+              end;
+              24: begin
                 cnv^.loopnormal := @ConvertP_Generic24_A_Generic24_A;
                 found := True;
-              End;
-              16 : Begin
+              end;
+              16: begin
                 cnv^.loopnormal := @ConvertP_Generic24_A_Generic16_A;
                 found := True;
-              End;
-              8 : Begin
+              end;
+              8: begin
                 cnv^.loopnormal := @ConvertP_Generic24_A_Generic8_A;
                 found := True;
-              End;
-            End;
-            16 : Case dest^.bits Of
-              32 : Begin
+              end;
+            end;
+            16: case dest^.bits of
+              32: begin
                 cnv^.loopnormal := @ConvertP_Generic16_A_Generic32_A;
                 found := True;
-              End;
-              24 : Begin
+              end;
+              24: begin
                 cnv^.loopnormal := @ConvertP_Generic16_A_Generic24_A;
                 found := True;
-              End;
-              16 : Begin
+              end;
+              16: begin
                 cnv^.loopnormal := @ConvertP_Generic16_A_Generic16_A;
                 found := True;
-              End;
-              8 : Begin
+              end;
+              8: begin
                 cnv^.loopnormal := @ConvertP_Generic16_A_Generic8_A;
                 found := True;
-              End;
-            End;
-          End
-        Else { O->O, O->A, A->O, Ck->O, O->Ck }
-          Case source^.bits Of
-            32 : Case dest^.bits Of
-              32 : Begin
+              end;
+            end;
+          end
+        else { O->O, O->A, A->O, Ck->O, O->Ck }
+          case source^.bits of
+            32: case dest^.bits of
+              32: begin
                 cnv^.loopnormal := @ConvertP_Generic32_Generic32;
                 cnv^.loopstretch := @ConvertP_Generic32_Generic32_S;
                 found := True;
-              End;
-              24 : Begin
+              end;
+              24: begin
                 cnv^.loopnormal := @ConvertP_Generic32_Generic24;
                 cnv^.loopstretch := @ConvertP_Generic32_Generic24_S;
                 found := True;
-              End;
-              16 : Begin
+              end;
+              16: begin
                 cnv^.loopnormal := @ConvertP_Generic32_Generic16;
                 cnv^.loopstretch := @ConvertP_Generic32_Generic16_S;
                 found := True;
-              End;
-              8 : Begin
+              end;
+              8: begin
                 cnv^.loopnormal := @ConvertP_Generic32_Generic8;
                 cnv^.loopstretch := @ConvertP_Generic32_Generic8_S;
                 found := True;
-              End;
-            End;
-            24 : Case dest^.bits Of
-              32 : Begin
+              end;
+            end;
+            24: case dest^.bits of
+              32: begin
                 cnv^.loopnormal := @ConvertP_Generic24_Generic32;
                 cnv^.loopstretch := @ConvertP_Generic24_Generic32_S;
                 found := True;
-              End;
-              24 : Begin
+              end;
+              24: begin
                 cnv^.loopnormal := @ConvertP_Generic24_Generic24;
                 cnv^.loopstretch := @ConvertP_Generic24_Generic24_S;
                 found := True;
-              End;
-              16 : Begin
+              end;
+              16: begin
                 cnv^.loopnormal := @ConvertP_Generic24_Generic16;
                 cnv^.loopstretch := @ConvertP_Generic24_Generic16_S;
                 found := True;
-              End;
-              8 : Begin
+              end;
+              8: begin
                 cnv^.loopnormal := @ConvertP_Generic24_Generic8;
                 cnv^.loopstretch := @ConvertP_Generic24_Generic8_S;
                 found := True;
-              End;
-            End;
-            16 : Case dest^.bits Of
-              32 : Begin
+              end;
+            end;
+            16: case dest^.bits of
+              32: begin
                 cnv^.loopnormal := @ConvertP_Generic16_Generic32;
                 cnv^.loopstretch := @ConvertP_Generic16_Generic32_S;
                 found := True;
-              End;
-              24 : Begin
+              end;
+              24: begin
                 cnv^.loopnormal := @ConvertP_Generic16_Generic24;
                 cnv^.loopstretch := @ConvertP_Generic16_Generic24_S;
                 found := True;
-              End;
-              16 : Begin
+              end;
+              16: begin
                 cnv^.loopnormal := @ConvertP_Generic16_Generic16;
                 cnv^.loopstretch := @ConvertP_Generic16_Generic16_S;
                 found := True;
-              End;
-              8 : Begin
+              end;
+              8: begin
                 cnv^.loopnormal := @ConvertP_Generic16_Generic8;
                 cnv^.loopstretch := @ConvertP_Generic16_Generic8_S;
                 found := True;
-              End;
-            End;
-          End;
+              end;
+            end;
+          end;
 
-  If found Then
-  Begin
+  if found then
+  begin
     Hermes_FormatCopy(source, @cnv^.source);
     Hermes_FormatCopy(dest, @cnv^.dest);
 
-    Hermes_ConverterRequest := True;
-    Exit;
-  End;
+    Result := True;
+    exit;
+  end;
 
   DebugMSG('no converter found!!!');
   { No converter found, fail }
-  Hermes_ConverterRequest := False;
-End;
-
-Function Hermes_ConverterPalette(handle, sourcepal, destpal : THermesHandle) : Boolean;
+  Result := False;
+end;
 
-Begin
+function Hermes_ConverterPalette(handle: THermesConverterHandle; sourcepal, destpal: THermesPaletteHandle): Boolean;
+var
+  cnv: PHermesConverter;
+begin
 {  DebugMSG('Hermes_ConverterPalette('+C2Str(sourcepal)+','+C2Str(destpal)+')');}
-  Hermes_ConverterPalette := False;
-  If (handle < 0) Or (handle >= lastConverter) Then
-    Exit;
-  If ConverterList[handle] = Nil Then
-    Exit;
+  Result := False;
+  if handle = nil then
+    exit;
+
+  cnv := PHermesConverter(handle);
 
   { Fail silently if not indexed colour format }
-  If Not ConverterList[handle]^.source.indexed Then
-  Begin
-    ConverterList[handle]^.lookup := Nil;
-    Hermes_ConverterPalette := True;
-    Exit;
-  End;
-
-  ConverterList[handle]^.lookup :=
-    Hermes_PaletteGetTable(sourcepal, @ConverterList[handle]^.dest);
-
-  If ConverterList[handle]^.lookup = Nil Then
-    Exit;
-
-  Hermes_ConverterPalette := True;
-End;
-
-Function Hermes_ConverterCopy(handle : THermesHandle; s_pixels : Pointer;
-                              s_x, s_y, s_width, s_height, s_pitch : Integer;
-                              d_pixels : Pointer; d_x, d_y, d_width,
-                              d_height, d_pitch : Integer) : Boolean;
-
-Var
-  cnv : PHermesConverter;
-  iface : THermesConverterInterface;
-
-Begin
-  Hermes_ConverterCopy := False;
-  If (handle < 0) Or (handle >= lastConverter) Then
-    Exit;
-  cnv := ConverterList[handle];
-  If cnv = Nil Then
-    Exit;
+  if not cnv^.source.indexed then
+  begin
+    cnv^.lookup := nil;
+    Result := True;
+    exit;
+  end;
+
+  cnv^.lookup := Hermes_PaletteGetTable(sourcepal, @cnv^.dest);
+
+  if cnv^.lookup = nil then
+    exit;
+
+  Result := True;
+end;
+
+function Hermes_ConverterCopy(handle: THermesConverterHandle; s_pixels: Pointer;
+                              s_x, s_y, s_width, s_height, s_pitch: Integer;
+                              d_pixels: Pointer; d_x, d_y, d_width,
+                              d_height, d_pitch: Integer): Boolean;
+var
+  cnv: PHermesConverter;
+  iface: THermesConverterInterface;
+begin
+  Result := False;
+  if handle = nil then
+    exit;
+//  cnv := ConverterList[handle];
+  cnv := PHermesConverter(handle);
+//  if cnv = nil then
+//    exit;
 
   { Returns success if height or width is zero. This is debatable.. ! }
-  If (s_width <= 0) Or (s_height <= 0) Or (d_width <= 0) Or (d_height <= 0) Then
-  Begin
-    Hermes_ConverterCopy := True;
-    Exit;
-  End;
+  if (s_width <= 0) or (s_height <= 0) or (d_width <= 0) or (d_height <= 0) then
+  begin
+    Result := True;
+    exit;
+  end;
 
   iface.s_pixels := s_pixels;
   iface.s_width := s_width;
   iface.s_height := s_height;
-  iface.s_add := s_pitch - s_width * (cnv^.source.bits Shr 3);
+  iface.s_add := s_pitch - s_width * (cnv^.source.bits shr 3);
   iface.s_pitch := s_pitch;
 
   iface.d_pixels := d_pixels;
   iface.d_width := d_width;
   iface.d_height := d_height;
-  iface.d_add := d_pitch - d_width*(cnv^.dest.bits Shr 3);
+  iface.d_add := d_pitch - d_width*(cnv^.dest.bits shr 3);
   iface.d_pitch := d_pitch;
 
-  Inc(iface.s_pixels, s_y * s_pitch + s_x * (cnv^.source.bits Shr 3));
-  Inc(iface.d_pixels, d_y * d_pitch + d_x * (cnv^.dest.bits Shr 3));
+  Inc(iface.s_pixels, s_y * s_pitch + s_x * (cnv^.source.bits shr 3));
+  Inc(iface.d_pixels, d_y * d_pitch + d_x * (cnv^.dest.bits shr 3));
 
   iface.s_has_colorkey := cnv^.source.has_colorkey;
   iface.d_has_colorkey := cnv^.dest.has_colorkey;
@@ -682,10 +605,10 @@ Begin
   iface.lookup := cnv^.lookup;
 
 
-  { For generic converters, do some extra setup (find shifts, etc.)
+  { for generic converters, do some extra setup (find shifts, etc.)
     TODO: Move that out of here and in the request routine ! }
-  If (cnv^.flags And HERMES_CONVERT_GENERIC) <> 0 Then
-  Begin
+  if (cnv^.flags and HERMES_CONVERT_GENERIC) <> 0 then
+  begin
     Hermes_Calculate_Generic_Info(Hermes_Topbit(cnv^.source.r),
                                   Hermes_Topbit(cnv^.source.g),
                                   Hermes_Topbit(cnv^.source.b),
@@ -699,41 +622,41 @@ Begin
     iface.mask_g := cnv^.dest.g;
     iface.mask_b := cnv^.dest.b;
     iface.mask_a := cnv^.dest.a;
-  End;
+  end;
 
   { Check for dithering. This should not be in here but in request as well }
-  If (cnv^.flags And HERMES_CONVERT_DITHER) <> 0 Then
-  Begin
-    { If there is a ditherer, use it else fall back to normal }
-    If cnv^.dither <> Nil Then
+  if (cnv^.flags and HERMES_CONVERT_DITHER) <> 0 then
+  begin
+    { if there is a ditherer, use it else fall back to normal }
+    if cnv^.dither <> nil then
       cnv^.loopnormal := cnv^.dither;
-  End;
+  end;
 
   { Normal conversion }
-  If (s_width = d_width) And (s_height = d_height) Then
-  Begin
-    If (cnv^.normal = Nil) Or (cnv^.loopnormal = Nil) Then
-      Exit;
+  if (s_width = d_width) and (s_height = d_height) then
+  begin
+    if (cnv^.normal = nil) or (cnv^.loopnormal = nil) then
+      exit;
     { Optimization
-    If (iface.s_add = 0) And (iface.d_add = 0) Then
-    Begin
+    if (iface.s_add = 0) and (iface.d_add = 0) then
+    begin
       iface.s_width := iface.s_width * s_height;
       iface.d_width := iface.d_width * d_height;
       iface.s_height := 1;
       iface.d_height := 1;
-    End;}
+    end;}
     iface.func := cnv^.normal;
     cnv^.loopnormal(@iface);
-    Hermes_ConverterCopy := True;
-    Exit;
-  End
+    Result := True;
+    exit;
+  end
   { Stretch conversion }
-  Else
-  Begin
-    If (cnv^.stretch = Nil) Or (cnv^.loopstretch = Nil) Then
-      Exit;
+  else
+  begin
+    if (cnv^.stretch = nil) or (cnv^.loopstretch = nil) then
+      exit;
     iface.func := cnv^.stretch;
     cnv^.loopstretch(@iface);
-  End;
-  Hermes_ConverterCopy := True;
-End;
+  end;
+  Result := True;
+end;

+ 68 - 0
packages/hermes/src/hermes_debug.inc

@@ -0,0 +1,68 @@
+{
+    Free Pascal port of the Hermes C library.
+    Copyright (C) 2001-2003  Nikolay Nikolov ([email protected])
+    Original C version by Christian Nentwich ([email protected])
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+}
+
+function C2Str(Q: Integer): string;
+var
+  S: string;
+begin
+  Str(Q, S);
+  Result := S;
+end;
+
+procedure DebugInit;
+{var
+  F: TextFile;}
+begin
+{  AssignFile(F, 'debug.txt');
+  Rewrite(F);
+  CloseFile(F);}
+end;
+
+procedure DebugMSG(S: string);
+var
+  F: TextFile;
+begin
+  AssignFile(F, 'debug.txt');
+  {$I-}
+  Append(F);
+  {$I+}
+  if IOResult <> 0 then
+  begin
+    {$I-}
+    Rewrite(F);
+    {$I+}
+    if IOResult <> 0 then
+      exit;
+  end;
+  Writeln(F, S);
+  CloseFile(F);
+end;

+ 92 - 0
packages/hermes/src/hermes_dither.inc

@@ -0,0 +1,92 @@
+{
+    Free Pascal port of the Hermes C library.
+    Copyright (C) 2001-2003  Nikolay Nikolov ([email protected])
+    Original C version by Christian Nentwich ([email protected])
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+}
+
+{ Everything in here (C)1998 The Rasterman }
+
+{ Rasterman's dither matrix }
+
+const
+  DitherMatrix_44: array [0..3, 0..3] of Uint8 = (
+    (0, 4, 1, 5),
+    (6, 2, 7, 3),
+    (1, 5, 0, 4),
+    (7, 3, 6, 2));
+
+var
+  DitherTab_r565_44: array [0..3, 0..3, 0..255] of Uint16;
+  DitherTab_g565_44: array [0..3, 0..3, 0..255] of Uint16;
+  DitherTab_b565_44: array [0..3, 0..3, 0..255] of Uint16;
+
+  DitherTab_r332_44: array [0..3, 0..3, 0..255] of Uint8;
+  DitherTab_g332_44: array [0..3, 0..3, 0..255] of Uint8;
+  DitherTab_b332_44: array [0..3, 0..3, 0..255] of Uint8;
+
+procedure Dither_SetupMatrices;
+var
+  i, x, y: LongInt;
+begin
+  for y := 0 to 3 do
+    for x := 0 to 3 do
+      for i := 0 to 255 do
+      begin
+        if (DitherMatrix_44[x, y] < (i and $7)) and (i < (256 - 8)) then
+        begin
+          DitherTab_r565_44[x, y, i] := ((i + 8) and $f8) shl 8;
+          DitherTab_r332_44[x, y, i] := ((i + 8) and $e0);
+        end
+        else
+        begin
+          DitherTab_r565_44[x, y, i] := (i and $f8) shl 8;
+          DitherTab_r332_44[x, y, i] := i and $e0;
+        end;
+        if (DitherMatrix_44[x, y] < ((i and $3) shl 1)) and (i < (256 - 4)) then
+        begin
+          DitherTab_g565_44[x, y, i] := (((i + 4) and $fc) shl 8) shr 5;
+          DitherTab_g332_44[x, y, i] := ((i + 4) and $e0) shr 3;
+        end
+        else
+        begin
+          DitherTab_g565_44[x, y, i] := ((i and $fc) shl 8) shr 5;
+          DitherTab_g332_44[x, y, i] := (i and $e0) shr 3;
+        end;
+        if (DitherMatrix_44[x, y] < (i and $7)) and (i < (256 - 8)) then
+        begin
+          DitherTab_b565_44[x, y, i] := (((i + 8) and $f8) shl 16) shr 19;
+          DitherTab_b332_44[x, y, i] := ((i + 8) shr 6) and $3;
+        end
+        else
+        begin
+          DitherTab_b565_44[x, y, i] := ((i and $f8) shl 16) shr 19;
+          DitherTab_b332_44[x, y, i] := (i shr 6) and $3;
+        end;
+      end;
+end;

+ 377 - 0
packages/hermes/src/hermes_factory.inc

@@ -0,0 +1,377 @@
+{
+    Free Pascal port of the Hermes C library.
+    Copyright (C) 2001-2003  Nikolay Nikolov ([email protected])
+    Original C version by Christian Nentwich ([email protected])
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+}
+
+var
+  Processor: Integer;
+
+procedure Hermes_Factory_Init;
+var
+  res: Integer;
+begin
+  res := 0;
+  Processor := PROC_GENERIC;
+
+  {$IFDEF I386_ASSEMBLER}
+    Processor := Processor or PROC_X86_PENTIUM;{There are no others at the moment}
+    res := Hermes_X86_CPU;
+    if (res and $800000) <> 0 then
+    begin
+//      Writeln('mmx disabled for debugging');
+      Processor := Processor or PROC_MMX_PENTIUM;
+{      Writeln('mmx!');}
+    end;
+  {$ENDIF I386_ASSEMBLER}
+end;
+
+function Hermes_Factory_getClearer(bits: Uint32): PHermesClearer;
+begin
+  { Try different processors in order of priority..
+    Note that for this to work, an MMX processor has to have both MMX and
+    X86 flags }
+  New(Result);
+  Result^.bits := bits;
+
+  {$IFDEF I386_ASSEMBLER}
+    if (Processor and PROC_MMX_PENTIUM) <> 0 then
+      case bits of
+        32: begin
+          Result^.func := @ClearMMX_32;
+          exit;
+        end;
+        24: ;
+        16: begin
+          Result^.func := @ClearMMX_16;
+          exit;
+        end;
+        8: begin
+          Result^.func := @ClearMMX_8;
+          exit;
+        end;
+      end;
+
+    if (Processor and PROC_X86_PENTIUM) <> 0 then
+      case bits of
+        32: begin
+          Result^.func := @ClearX86_32;
+          exit;
+        end;
+        24: ;
+        16: begin
+          Result^.func := @ClearX86_16;
+          exit;
+        end;
+        8: begin
+          Result^.func := @ClearX86_8;
+          exit;
+        end;
+      end;
+  {$ENDIF I386_ASSEMBLER}
+
+  case bits of
+    32: begin
+      Result^.func := @ClearP_32;
+      exit;
+    end;
+    24: begin
+      Result^.func := @ClearP_24;
+      exit;
+    end;
+    16: begin
+      Result^.func := @ClearP_16;
+      exit;
+    end;
+    8: begin
+      Result^.func := @ClearP_8;
+      exit;
+    end;
+    else
+    begin
+      Dispose(Result);
+      Result := nil;
+    end;
+  end;
+end;
+
+function Hermes_Factory_getConverter(source, dest: PHermesFormat): PHermesConverter;
+var
+  i: Integer;
+  found: Boolean;
+begin
+  found := False;
+
+  New(Result);
+
+  { Set all conversion routines to nil }
+  Result^.loopnormal := nil;
+  Result^.loopstretch := nil;
+  Result^.normal := nil;
+  Result^.stretch := nil;
+  Result^.dither := nil;
+  Result^.ditherstretch := nil;
+  Result^.flags := 0;
+
+  if source^.indexed then
+    { for 8 bit indexed, just look at the destination bit depth and check
+      if the converter's processor is a subset of our processor }
+    for i := 0 to Factory_NumConverters - 1 do
+      if (Factory_Converters[i].d_bits = dest^.bits) and
+        (Factory_Converters[i].s_idx and
+        ((processor and Factory_Converters[i].processor) <> 0)) then
+      begin
+        { if any routines are unassigned, assign them now }
+
+        if Result^.loopnormal = nil then
+        begin
+          Result^.loopnormal := Factory_Converters[i].loopnormal;
+          found := True;
+        end;
+
+        if Result^.normal = nil then
+        begin
+          Result^.normal := Factory_Converters[i].normal;
+          found := True;
+        end;
+
+        if Result^.loopstretch = nil then
+        begin
+          Result^.loopstretch := Factory_Converters[i].loopstretch;
+          found := True;
+        end;
+
+        if Result^.stretch = nil then
+        begin
+          Result^.stretch := Factory_Converters[i].stretch;
+          found := True;
+        end;
+      end else
+  else
+    { Otherwise we need to compare everything, including bitmasks }
+    for i := 0 to Factory_NumConverters - 1 do
+      if (Factory_Converters[i].d_bits = dest^.bits) and
+         (Factory_Converters[i].d_r = dest^.r) and
+         (Factory_Converters[i].d_g = dest^.g) and
+         (Factory_Converters[i].d_b = dest^.b) and
+         (Factory_Converters[i].d_a = dest^.a) and
+         (Factory_Converters[i].d_idx = dest^.indexed) and
+         (Factory_Converters[i].s_bits = source^.bits) and
+         (Factory_Converters[i].s_r = source^.r) and
+         (Factory_Converters[i].s_g = source^.g) and
+         (Factory_Converters[i].s_b = source^.b) and
+         (Factory_Converters[i].s_a = source^.a) and
+         (Factory_Converters[i].s_idx = source^.indexed) and
+         ((processor and Factory_Converters[i].processor) <> 0) then
+      begin
+        { if any routines are unassigned, assign them now }
+
+        if (Result^.loopnormal = nil) and
+           (Factory_Converters[i].loopnormal <> nil) then
+        begin
+          Result^.loopnormal := Factory_Converters[i].loopnormal;
+          found := True;
+        end;
+
+        if (Result^.normal = nil) and
+           (Factory_Converters[i].normal <> nil) then
+        begin
+          Result^.normal := Factory_Converters[i].normal;
+          found := True;
+        end;
+
+        if (Result^.loopstretch = nil) and
+           (Factory_Converters[i].loopstretch <> nil) then
+        begin
+          Result^.loopstretch := Factory_Converters[i].loopstretch;
+          found := True;
+        end;
+
+        if (Result^.stretch = nil) and
+           (Factory_Converters[i].stretch <> nil) then
+        begin
+          Result^.stretch := Factory_Converters[i].stretch;
+          found := True;
+        end;
+
+        if (Result^.dither = nil) and
+           (Factory_Converters[i].dither <> nil) then
+        begin
+          Result^.dither := Factory_Converters[i].dither;
+          found := True;
+        end;
+
+        if (Result^.ditherstretch = nil) and
+           (Factory_Converters[i].ditherstretch <> nil) then
+        begin
+          Result^.ditherstretch := Factory_Converters[i].ditherstretch;
+          found := True;
+        end;
+
+        { In the rare event of having everything assigned, pull the emergency
+          break. Otherwise we need to continue looking (might be stretching
+          routines somewhere :)
+          do I sound like a stewardess? }
+        if (Result^.loopnormal <> nil) and (Result^.normal <> nil) and
+           (Result^.loopstretch <> nil) and (Result^.stretch <> nil) and
+           (Result^.dither <> nil) and (Result^.ditherstretch <> nil) then
+          break;
+      end;
+
+  if found then
+  begin
+    Hermes_FormatCopy(source, @Result^.source);
+    Hermes_FormatCopy(dest, @Result^.dest);
+  end
+  else
+  begin
+    Dispose(Result);
+    Result := nil;
+  end;
+end;
+
+function Hermes_Factory_getEqualConverter(bits: Integer): PHermesConverter;
+var
+  found: Boolean;
+  asm_found: Integer;
+  c_found: Integer;
+begin
+  found := False;
+  New(Result);
+
+  { Set all conversion routines to null }
+  Result^.loopnormal := nil;
+  Result^.loopstretch := nil;
+  Result^.normal := nil;
+  Result^.stretch := nil;
+  Result^.dither := nil;
+  Result^.ditherstretch := nil;
+
+{$IFDEF I386_ASSEMBLER}
+
+  { Try MMX routines }
+  if (Result^.loopnormal = nil) or (Result^.normal = nil) or
+     (Result^.loopstretch = nil) or (Result^.stretch = nil) then
+    if (processor and PROC_MMX_PENTIUM) <> 0 then
+{      case bits of
+      end};
+
+  { Try X86 routines }
+  if (Result^.loopnormal = nil) or (Result^.normal = nil) or
+     (Result^.loopstretch = nil) or (Result^.stretch = nil) then
+    if (processor and PROC_X86_PENTIUM) <> 0 then
+    begin
+      asm_found := 0;
+      case bits of
+        32: begin
+          Result^.normal := @CopyX86p_4byte; asm_found := 1;
+        end;
+        24: ;
+        16: begin
+          Result^.normal := @CopyX86p_2byte; asm_found := 1;
+        end;
+         8: begin
+          Result^.normal := @CopyX86p_1byte; asm_found := 1;
+        end;
+      end;
+
+      if (asm_found and 1) <> 0 then
+      begin
+        Result^.loopnormal := @ConvertX86;
+        found := True;
+      end;
+    end;
+
+{$ENDIF I386_ASSEMBLER}
+
+
+  if (Result^.loopnormal = nil) or (Result^.normal = nil) or
+     (Result^.loopstretch = nil) or (Result^.stretch = nil) then
+  begin
+    c_found := 0;
+
+    case bits of
+      32: begin
+        if Result^.normal = nil then
+        begin
+          Result^.normal := @CopyP_4byte; c_found := c_found or 1;
+        end;
+        if Result^.stretch = nil then
+        begin
+          Result^.stretch := @CopyP_4byte_S; c_found := c_found or 2;
+        end;
+      end;
+      24: begin
+        if Result^.normal = nil then
+        begin
+          Result^.normal := @CopyP_3byte; c_found := c_found or 1;
+        end;
+        if Result^.stretch = nil then
+        begin
+          Result^.stretch := @CopyP_3byte_S; c_found := c_found or 2;
+        end;
+      end;
+      16: begin
+        if Result^.normal = nil then
+        begin
+          Result^.normal := @CopyP_2byte; c_found := c_found or 1;
+        end;
+        if Result^.stretch = nil then
+        begin
+          Result^.stretch := @CopyP_2byte_S; c_found := c_found or 2;
+        end;
+      end;
+       8: begin
+        if Result^.normal = nil then
+        begin
+          Result^.normal := @CopyP_1byte; c_found := c_found or 1;
+        end;
+        if Result^.stretch = nil then
+        begin
+          Result^.stretch := @CopyP_1byte_S; c_found := c_found or 2;
+        end;
+      end;
+    end;
+
+    if (c_found and 1) <> 0 then
+    begin
+      Result^.loopnormal := @ConvertP; found := True;
+    end;
+    if (c_found and 2) <> 0 then
+    begin
+      Result^.loopstretch := @ConvertPStretch; found := True;
+    end;
+  end;
+
+  if not found then
+  begin
+    Dispose(Result);
+    Result := nil;
+  end;
+end;

+ 117 - 0
packages/hermes/src/hermes_format.inc

@@ -0,0 +1,117 @@
+{
+    Free Pascal port of the Hermes C library.
+    Copyright (C) 2001-2003  Nikolay Nikolov ([email protected])
+    Original C version by Christian Nentwich ([email protected])
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+}
+
+{function Hermes_FormatNewEmpty: PHermesFormat;
+function Hermes_FormatNew(bits: Integer; r, g, b, a: Uint32;
+                          indexed: Boolean): PHermesFormat;
+procedure Hermes_FormatFree(fmt: PHermesFormat);
+function Hermes_FormatNewEx(bits: Integer; r, g, b, a: Uint32;
+                            indexed, has_colorkey: Boolean;
+                            colorkey: Uint32): PHermesFormat;
+function Hermes_FormatEquals(op1, op2: PHermesFormat): Boolean;
+procedure Hermes_FormatCopy(source, dest: PHermesFormat);}
+
+function Hermes_FormatNewEmpty: PHermesFormat;
+begin
+  New(Result);
+  Result^.bits := 0;
+  Result^.indexed := False;
+  Result^.r := 0;
+  Result^.g := 0;
+  Result^.b := 0;
+  Result^.a := 0;
+  Result^.has_colorkey := False;
+  Result^.colorkey := 0;
+end;
+
+function Hermes_FormatNew(bits: Integer; r, g, b, a: Uint32;
+                          indexed: Boolean): PHermesFormat;
+begin
+  if indexed and (bits <> 8) then
+  begin
+    Result := nil;
+    exit;
+  end;
+  New(Result);
+  Result^.bits := bits;
+  Result^.r := r;
+  Result^.g := g;
+  Result^.b := b;
+  Result^.a := a;
+  Result^.indexed := indexed;
+  Result^.has_colorkey := False;
+  Result^.colorkey := 0;
+end;
+
+procedure Hermes_FormatFree(fmt: PHermesFormat);
+begin
+  if fmt <> nil then
+    Dispose(fmt);
+end;
+
+function Hermes_FormatNewEx(bits: Integer; r, g, b, a: Uint32;
+                            indexed, has_colorkey: Boolean;
+                            colorkey: Uint32): PHermesFormat;
+begin
+  if indexed and (bits <> 8) then
+  begin
+    Result := nil;
+    exit;
+  end;
+  New(Result);
+  Result^.bits := bits;
+  Result^.r := r;
+  Result^.g := g;
+  Result^.b := b;
+  Result^.a := a;
+  Result^.indexed := indexed;
+  Result^.has_colorkey := has_colorkey;
+  Result^.colorkey := colorkey;
+end;
+
+function Hermes_FormatEquals(op1, op2: PHermesFormat): Boolean;
+begin
+  Result := ((op1^.indexed = op2^.indexed) and
+             (op1^.bits = op2^.bits) and
+             (op1^.r = op2^.r) and
+             (op1^.g = op2^.g) and
+             (op1^.b = op2^.b) and
+             (op1^.a = op2^.a) and
+             (op1^.has_colorkey = op2^.has_colorkey) and
+            ((op1^.has_colorkey = False) or
+             (op1^.colorkey = op2^.colorkey)));
+end;
+
+procedure Hermes_FormatCopy(source, dest: PHermesFormat);
+begin
+  Move(source^, dest^, SizeOf(THermesFormat));
+end;

+ 182 - 0
packages/hermes/src/hermes_list.inc

@@ -0,0 +1,182 @@
+{
+    Free Pascal port of the Hermes C library.
+    Copyright (C) 2001-2003  Nikolay Nikolov ([email protected])
+    Original C version by Christian Nentwich ([email protected])
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+}
+
+type
+  TListFreeCallback = procedure(p: Pointer);
+  PHermesListElementStruct = ^THermesListElementStruct;
+  THermesListElementStruct = record
+    handle: THermesHandle;
+    data: Pointer;
+    next: PHermesListElementStruct;
+  end;
+  PHermesListElement = ^THermesListElement;
+  THermesListElement = THermesListElementStruct;
+  PHermesList = ^THermesList;
+  THermesList = record
+    first, last: PHermesListElement;
+  end;
+
+{function Hermes_ListNew: PHermesList;
+procedure Hermes_ListDestroy(list: PHermesList);
+function Hermes_ListElementNew(handle: THermesHandle): PHermesListElement;
+procedure Hermes_ListAdd(list: PHermesList; element: PHermesListElement);
+procedure Hermes_ListAddFront(list: PHermesList; element: PHermesListElement);
+function Hermes_ListDeleteElement(list: PHermesList; handle: THermesHandle): Boolean;
+function Hermes_ListLookup(list: PHermesList;
+                           handle: THermesHandle): PHermesListElement;}
+
+function Hermes_ListNew: PHermesList;
+begin
+  New(Result);
+  Result^.first := nil;
+  Result^.last := nil;
+end;
+
+procedure Hermes_ListDestroy(list: PHermesList; user_free: TListFreeCallback);
+var
+  tmp, run: PHermesListElement;
+begin
+  if list = nil then
+    exit;
+  run := list^.first;
+  while run <> nil do
+  begin
+    tmp := run;
+    run := run^.next;
+    if (tmp^.data <> nil) and (user_free <> nil) then
+      user_free(tmp^.data);
+    Dispose(tmp);
+  end;
+  Dispose(list);
+end;
+
+function Hermes_ListElementNew(handle: THermesHandle): PHermesListElement;
+begin
+  New(Result);
+  Result^.handle := handle;
+  Result^.next := nil;
+  Result^.data := nil;
+end;
+
+procedure Hermes_ListAdd(list: PHermesList; element: PHermesListElement);
+begin
+  if (list = nil) or (element = nil) then
+    exit;
+  if list^.first = nil then
+  begin
+    list^.first := element;
+    list^.last := element;
+    element^.next := nil;
+    exit;
+  end;
+  list^.last^.next := element;
+  list^.last := element;
+  element^.next := nil;
+end;
+
+procedure Hermes_ListAddFront(list: PHermesList; element: PHermesListElement);
+begin
+  if (list = nil) or (element = nil) then
+    exit;
+  if list^.first = nil then
+  begin
+    list^.first := element;
+    list^.last := element;
+    element^.next := nil;
+    exit;
+  end;
+  element^.next := list^.first;
+  list^.first := element;
+end;
+
+function Hermes_ListDeleteElement(list: PHermesList; handle: THermesHandle; user_free: TListFreeCallback): Boolean;
+var
+  run, previous: PHermesListElement;
+begin
+  if list = nil then
+  begin
+    Result := False;
+    exit;
+  end;
+  previous := nil;
+  run := list^.first;
+  while run <> nil do
+  begin
+    if run^.handle = handle then
+    begin
+      if run = list^.first then
+        list^.first := run^.next
+      else
+        previous^.next := run^.next;
+
+      if run = list^.last then
+      begin
+        list^.last := previous;
+        if list^.last <> nil then
+          list^.last^.next := nil;
+      end;
+
+      if (run^.data <> nil) and (user_free <> nil) then
+        user_free(run^.data);
+
+      Dispose(run);
+      Result := True;
+      exit;
+    end;
+    previous := run;
+    run := run^.next;
+  end;
+  Result := False;
+end;
+
+function Hermes_ListLookup(list: PHermesList;
+                           handle: THermesHandle): PHermesListElement;
+var
+  run: PHermesListElement;
+begin
+  if list = nil then
+  begin
+    Result := nil;
+    exit;
+  end;
+  run := list^.first;
+  while run <> nil do
+  begin
+    if run^.handle = handle then
+    begin
+      Result := run;
+      exit;
+    end;
+    run := run^.next;
+  end;
+  Result := nil;
+end;

+ 232 - 0
packages/hermes/src/hermes_palette.inc

@@ -0,0 +1,232 @@
+{
+    Free Pascal port of the Hermes C library.
+    Copyright (C) 2001-2003  Nikolay Nikolov ([email protected])
+    Original C version by Christian Nentwich ([email protected])
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+}
+
+type
+  PHermesLookupTable = ^THermesLookupTable;
+  THermesLookupTable = record
+    data: ^Uint32;             { Actual lookup table }
+    valid: Boolean;           { Is this table up to date? }
+    format: THermesFormat;    { Format of lookup table }
+  end;
+  PHermesPalette = ^THermesPalette;
+  THermesPalette = record
+    data: ^Uint32;             { Palette data }
+    tables: PHermesList;      { Linked list of HermesLookupTables }
+  end;
+
+function Hermes_PaletteInstance: THermesPaletteHandle;
+var
+  newinstance: PHermesPalette;
+begin
+  { Create a new palette structure }
+  New(newinstance);
+  { Create palette data }
+  newinstance^.data := GetMem(256*SizeOf(Uint32));
+  { Create lookup table list }
+  newinstance^.tables := Hermes_ListNew;
+
+  Result := THermesPaletteHandle(newinstance);
+end;
+
+procedure HermesLookupTable_FreeCallback(q: Pointer);
+begin
+  FreeMem(PHermesLookupTable(q)^.data);
+  Dispose(PHermesLookupTable(q));
+end;
+
+procedure Hermes_PaletteReturn(handle: THermesPaletteHandle);
+begin
+  if handle <> nil then
+  begin
+    { Free palette data and lookup tables }
+    FreeMem(PHermesPalette(handle)^.data);
+    Hermes_ListDestroy(PHermesPalette(handle)^.tables, @HermesLookupTable_FreeCallback);
+    Dispose(PHermesPalette(handle));
+  end;
+end;
+
+procedure Hermes_PaletteSet(handle: THermesPaletteHandle; palette: Pointer);
+var
+  element: PHermesListElement;
+  pal: PHermesPalette;
+begin
+{  DebugMSG('Hermes_PaletteSet('+C2Str(handle)+','+C2Str(DWord(palette))+')');}
+  if handle = nil then
+    exit;
+
+  pal := PHermesPalette(handle);
+  element := pal^.tables^.first;
+
+  { Invalidate all lookup tables }
+  while element <> nil do
+  begin
+    (PHermesLookupTable(element^.data))^.valid := False;
+    element := element^.next;
+  end;
+
+{  FillChar(palette^, 256*4, $7f);}
+  Move(palette^, pal^.data^, 256*4);
+end;
+
+function Hermes_PaletteGet(handle: THermesPaletteHandle): Pointer;
+begin
+  if handle = nil then
+  begin
+    Result := nil;
+    exit;
+  end;
+
+  Result := PHermesPalette(handle)^.data;
+end;
+
+procedure Hermes_PaletteMakeLookup(lookup, palette: PUint32;
+                                   format: PHermesFormat);
+var
+  info: THermesGenericInfo;
+  I: Integer;
+  r, g, b: Uint32;
+begin
+{  DebugMSG('Yo! Hermes_PaletteMakeLookup');}
+  r := 0;
+  g := 0;
+  b := 0;
+  if format^.indexed then
+    exit;
+
+  Hermes_Calculate_Generic_Info(24,16,8,32,
+                                Hermes_Topbit(format^.r),
+                                Hermes_Topbit(format^.g),
+                                Hermes_Topbit(format^.b),
+                                Hermes_Topbit(format^.a),
+                                @info);
+
+  { Optimised loop if there are no left shifts }
+  if (info.r_left = 0) and (info.g_left = 0) and (info.b_left = 0) then
+    for I := 0 to 255 do
+    begin
+      r := (palette[i] shr info.r_right) and format^.r;
+      g := (palette[i] shr info.g_right) and format^.g;
+      b := (palette[i] shr info.b_right) and format^.b;
+      lookup[i] := r or g or b;
+    end
+  else
+    for I := 0 to 255 do
+    begin
+      r := ((palette[i] shr info.r_right) shl info.r_left) and format^.r;
+      g := ((palette[i] shr info.g_right) shl info.g_left) and format^.g;
+      b := ((palette[i] shr info.b_right) shl info.b_left) and format^.b;
+      lookup[i] := r or g or b;
+    end;
+end;
+
+function Hermes_PaletteGetTable(palette: THermesPaletteHandle; format: PHermesFormat): Pointer;
+var
+  element: PHermesListElement;
+  pal: PHermesPalette;
+  table: PHermesLookupTable;
+begin
+  if palette = nil then
+  begin
+    Result := nil;
+    exit;
+  end;
+
+  pal := PHermesPalette(palette);
+
+  { Go to the first table in the list }
+  element := pal^.tables^.first;
+
+  { Search for correct table using format }
+  while element <> nil do
+  begin
+    table := element^.data;
+
+    if Hermes_FormatEquals(@table^.format, format) then
+    begin
+      if table^.valid then
+      begin
+        Result := table^.data;
+        exit;
+      end;
+
+      { Have to recreate the lookup table }
+      Hermes_PaletteMakeLookup(table^.data, pal^.data, format);
+      table^.valid := True;
+
+      Result := table^.data;
+      exit;
+    end;
+
+    element := element^.next;
+  end;
+
+  { Format not found, have to create a new table (need no handle) }
+  New(table);
+  table^.data := GetMem(1024);
+
+  { Create lookup table }
+  Hermes_PaletteMakeLookup(table^.data, pal^.data, format);
+  Hermes_FormatCopy(format, @table^.format);
+
+  table^.valid := True;
+
+  { Create a new list element }
+  element := Hermes_ListElementNew(0);
+  element^.data := table;
+
+  { Add to the front of the list }
+  Hermes_ListAddFront(pal^.tables, element);
+
+  { Return lookup data }
+  Result := table^.data;
+end;
+
+procedure Hermes_PaletteInvalidateCache(handle: THermesPaletteHandle);
+var
+  element: PHermesListElement;
+  pal: PHermesPalette;
+begin
+  if handle = nil then
+    exit;
+
+  pal := PHermesPalette(handle);
+
+  element := pal^.tables^.first;
+
+  { Invalidate all lookup tables }
+
+  while element <> nil do
+  begin
+    (PHermesLookupTable(element^.data))^.valid := False;
+    element := element^.next;
+  end;
+end;

+ 119 - 0
packages/hermes/src/hermes_utility.inc

@@ -0,0 +1,119 @@
+{
+    Free Pascal port of the Hermes C library.
+    Copyright (C) 2001-2003  Nikolay Nikolov ([email protected])
+    Original C version by Christian Nentwich ([email protected])
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+}
+
+{procedure Hermes_Calculate_Generic_Info(s_r, s_g, s_b, s_a,
+                                        d_r, d_g, d_b, d_a: Uint32;
+                                        info: PHermesGenericInfo);
+function Hermes_Topbit(mask: Uint32): Integer;}
+
+procedure Hermes_Calculate_Generic_Info(s_r, s_g, s_b, s_a,
+                                        d_r, d_g, d_b, d_a: Integer;
+                                        info: PHermesGenericInfo);
+var
+  r_right, g_right, b_right, a_right: Integer;
+begin
+  {Calculate right shift amount for red. if it's <0, then set it to 0
+   and calculate left shift amount}
+  r_right := s_r - d_r;
+  if r_right < 0 then
+  begin
+    info^.r_left := -r_right;
+    info^.r_right := 0;
+  end
+  else
+  begin
+    info^.r_left := 0;
+    info^.r_right := r_right;
+  end;
+
+  {Same for green}
+  g_right := s_g - d_g;
+  if g_right < 0 then
+  begin
+    info^.g_left := -g_right;
+    info^.g_right := 0;
+  end
+  else
+  begin
+    info^.g_left := 0;
+    info^.g_right := g_right;
+  end;
+
+  {Same for blue}
+  b_right := s_b - d_b;
+  if b_right < 0 then
+  begin
+    info^.b_left := -b_right;
+    info^.b_right := 0;
+  end
+  else
+  begin
+    info^.b_left := 0;
+    info^.b_right := b_right;
+  end;
+
+  {Alpha}
+  a_right := s_a - d_a;
+  if a_right < 0 then
+  begin
+    info^.a_left := -a_right;
+    info^.a_right := 0;
+  end
+  else
+  begin
+    info^.a_left := 0;
+    info^.a_right := a_right;
+  end;
+end;
+
+function Hermes_Topbit(mask: Uint32): Integer;
+var
+  i: Integer;
+begin
+  if mask = 0 then
+  begin
+    Result := 0;
+    exit;
+  end;
+  i := 0;
+  while (mask and 1) = 0 do
+  begin
+    mask := mask shr 1;
+    Inc(i);
+  end;
+  while (mask and 1) = 1 do
+  begin
+    mask := mask shr 1;
+    Inc(i);
+  end;
+  Result := i;
+end;

+ 81 - 43
packages/hermes/src/i386/headi386.inc

@@ -1,44 +1,82 @@
+{
+    This file is part of the PTCPas framebuffer library
+    Copyright (C) 2001-2010 Nikolay Nikolov ([email protected])
 
-{$L hm_i386}
-
-Procedure ConvertX86(hci : PHermesConverterInterface); CDecl; External name ExternalAsmPrefix+'ConvertX86';
-Procedure ConvertX86Stretch(hci : PHermesConverterInterface); CDecl; External name ExternalAsmPrefix+'ConvertX86Stretch';
-Procedure ClearX86_32(hci : PHermesClearInterface); CDecl; External name ExternalAsmPrefix+'ClearX86_32';
-Procedure ClearX86_24(hci : PHermesClearInterface); CDecl; External name ExternalAsmPrefix+'ClearX86_24';
-Procedure ClearX86_16(hci : PHermesClearInterface); CDecl; External name ExternalAsmPrefix+'ClearX86_16';
-Procedure ClearX86_8(hci : PHermesClearInterface); CDecl; External name ExternalAsmPrefix+'ClearX86_8';
-
-Function Hermes_X86_CPU : Integer; CDecl; External name ExternalAsmPrefix+'Hermes_X86_CPU';
-
-Procedure ConvertX86p32_32BGR888(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p32_32BGR888';
-Procedure ConvertX86p32_32RGBA888(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p32_32RGBA888';
-Procedure ConvertX86p32_32BGRA888(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p32_32BGRA888';
-Procedure ConvertX86p32_24RGB888(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p32_24RGB888';
-Procedure ConvertX86p32_24BGR888(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p32_24BGR888';
-Procedure ConvertX86p32_16RGB565(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p32_16RGB565';
-Procedure ConvertX86p32_16BGR565(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p32_16BGR565';
-Procedure ConvertX86p32_16RGB555(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p32_16RGB555';
-Procedure ConvertX86p32_16BGR555(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p32_16BGR555';
-Procedure ConvertX86p32_8RGB332(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p32_8RGB332';
-
-Procedure ConvertX86p32_16RGB565_S(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p32_16RGB565_S';
-
-Procedure ConvertX86p16_32RGB888(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p16_32RGB888';
-Procedure ConvertX86p16_32BGR888(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p16_32BGR888';
-Procedure ConvertX86p16_32RGBA888(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p16_32RGBA888';
-Procedure ConvertX86p16_32BGRA888(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p16_32BGRA888';
-Procedure ConvertX86p16_24RGB888(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p16_24RGB888';
-Procedure ConvertX86p16_24BGR888(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p16_24BGR888';
-Procedure ConvertX86p16_16BGR565(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p16_16BGR565';
-Procedure ConvertX86p16_16RGB555(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p16_16RGB555';
-Procedure ConvertX86p16_16BGR555(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p16_16BGR555';
-Procedure ConvertX86p16_8RGB332(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86p16_8RGB332';
-
-Procedure CopyX86p_4byte(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'CopyX86p_4byte';
-Procedure CopyX86p_3byte(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'CopyX86p_3byte';
-Procedure CopyX86p_2byte(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'CopyX86p_2byte';
-Procedure CopyX86p_1byte(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'CopyX86p_1byte';
-
-Procedure ConvertX86pI8_32(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86pI8_32';
-Procedure ConvertX86pI8_24(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86pI8_24';
-Procedure ConvertX86pI8_16(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertX86pI8_16';
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+}
+
+{$L x8616lut}
+{$L x86_clr}
+{$L x86_main}
+{$L x86p_16}
+{$L x86p_32}
+{$L x86p_cpy}
+{$L x86p_i8}
+{$L x86p_s32}
+{$L x86pscpy}
+
+procedure ConvertX86(hci: PHermesConverterInterface); cdecl; external name ExternalAsmPrefix+'ConvertX86';
+procedure ConvertX86Stretch(hci: PHermesConverterInterface); cdecl; external name ExternalAsmPrefix+'ConvertX86Stretch';
+procedure ClearX86_32(hci: PHermesClearInterface); cdecl; external name ExternalAsmPrefix+'ClearX86_32';
+procedure ClearX86_24(hci: PHermesClearInterface); cdecl; external name ExternalAsmPrefix+'ClearX86_24';
+procedure ClearX86_16(hci: PHermesClearInterface); cdecl; external name ExternalAsmPrefix+'ClearX86_16';
+procedure ClearX86_8(hci: PHermesClearInterface); cdecl; external name ExternalAsmPrefix+'ClearX86_8';
+
+function Hermes_X86_CPU: Integer; cdecl; external name ExternalAsmPrefix+'Hermes_X86_CPU';
+
+procedure ConvertX86p32_32BGR888(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p32_32BGR888';
+procedure ConvertX86p32_32RGBA888(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p32_32RGBA888';
+procedure ConvertX86p32_32BGRA888(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p32_32BGRA888';
+procedure ConvertX86p32_24RGB888(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p32_24RGB888';
+procedure ConvertX86p32_24BGR888(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p32_24BGR888';
+procedure ConvertX86p32_16RGB565(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p32_16RGB565';
+procedure ConvertX86p32_16BGR565(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p32_16BGR565';
+procedure ConvertX86p32_16RGB555(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p32_16RGB555';
+procedure ConvertX86p32_16BGR555(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p32_16BGR555';
+procedure ConvertX86p32_8RGB332(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p32_8RGB332';
+
+procedure ConvertX86p32_16RGB565_S(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p32_16RGB565_S';
+
+procedure ConvertX86p16_32RGB888(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p16_32RGB888';
+procedure ConvertX86p16_32BGR888(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p16_32BGR888';
+procedure ConvertX86p16_32RGBA888(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p16_32RGBA888';
+procedure ConvertX86p16_32BGRA888(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p16_32BGRA888';
+procedure ConvertX86p16_24RGB888(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p16_24RGB888';
+procedure ConvertX86p16_24BGR888(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p16_24BGR888';
+procedure ConvertX86p16_16BGR565(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p16_16BGR565';
+procedure ConvertX86p16_16RGB555(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p16_16RGB555';
+procedure ConvertX86p16_16BGR555(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p16_16BGR555';
+procedure ConvertX86p16_8RGB332(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86p16_8RGB332';
+
+procedure CopyX86p_4byte(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'CopyX86p_4byte';
+procedure CopyX86p_3byte(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'CopyX86p_3byte';
+procedure CopyX86p_2byte(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'CopyX86p_2byte';
+procedure CopyX86p_1byte(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'CopyX86p_1byte';
+
+procedure ConvertX86pI8_32(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86pI8_32';
+procedure ConvertX86pI8_24(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86pI8_24';
+procedure ConvertX86pI8_16(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertX86pI8_16';

+ 41 - 11
packages/hermes/src/i386/headmmx.inc

@@ -1,20 +1,50 @@
+{
+    This file is part of the PTCPas framebuffer library
+    Copyright (C) 2001-2010 Nikolay Nikolov ([email protected])
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+}
 
 {$L mmx_clr}
 {$L mmx_main}
 {$L mmxp2_32}
 {$L mmxp_32}
 
-Procedure ConvertMMX(hci : PHermesConverterInterface); CDecl; External name ExternalAsmPrefix+'ConvertMMX';
+procedure ConvertMMX(hci: PHermesConverterInterface); cdecl; external name ExternalAsmPrefix+'ConvertMMX';
 
-Procedure ClearMMX_32(hci : PHermesClearInterface); CDecl; External name ExternalAsmPrefix+'ClearMMX_32';
-Procedure ClearMMX_24(hci : PHermesClearInterface); CDecl; External name ExternalAsmPrefix+'ClearMMX_24';
-Procedure ClearMMX_16(hci : PHermesClearInterface); CDecl; External name ExternalAsmPrefix+'ClearMMX_16';
-Procedure ClearMMX_8(hci : PHermesClearInterface); CDecl; External name ExternalAsmPrefix+'ClearMMX_8';
+procedure ClearMMX_32(hci: PHermesClearInterface); cdecl; external name ExternalAsmPrefix+'ClearMMX_32';
+procedure ClearMMX_24(hci: PHermesClearInterface); cdecl; external name ExternalAsmPrefix+'ClearMMX_24';
+procedure ClearMMX_16(hci: PHermesClearInterface); cdecl; external name ExternalAsmPrefix+'ClearMMX_16';
+procedure ClearMMX_8(hci: PHermesClearInterface); cdecl; external name ExternalAsmPrefix+'ClearMMX_8';
 
-Procedure ConvertMMXpII32_24RGB888(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertMMXpII32_24RGB888';
-Procedure ConvertMMXpII32_16RGB565(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertMMXpII32_16RGB565';
-Procedure ConvertMMXpII32_16BGR565(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertMMXpII32_16BGR565';
-Procedure ConvertMMXpII32_16RGB555(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertMMXpII32_16RGB555';
-Procedure ConvertMMXpII32_16BGR555(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertMMXpII32_16BGR555';
+procedure ConvertMMXpII32_24RGB888(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertMMXpII32_24RGB888';
+procedure ConvertMMXpII32_16RGB565(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertMMXpII32_16RGB565';
+procedure ConvertMMXpII32_16BGR565(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertMMXpII32_16BGR565';
+procedure ConvertMMXpII32_16RGB555(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertMMXpII32_16RGB555';
+procedure ConvertMMXpII32_16BGR555(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertMMXpII32_16BGR555';
 
-Procedure ConvertMMXp32_16RGB555(CONVERT_PARAMETERS); CDecl; External name ExternalAsmPrefix+'ConvertMMXp32_16RGB555';
+procedure ConvertMMXp32_16RGB555(CONVERT_PARAMETERS); cdecl; external name ExternalAsmPrefix+'ConvertMMXp32_16RGB555';

+ 23 - 25
packages/hermes/src/i386/mmx_clr.as

@@ -2,7 +2,7 @@
 # MMX surface clear routines for HERMES
 # Copyright (c) 1998 Christian Nentwich ([email protected])
 # This source code is licensed under the GNU LGPL
-# 
+#
 # Please refer to the file COPYING.LIB contained in the distribution for
 # licensing conditions
 #
@@ -25,13 +25,13 @@
 ##  16: int add
 
 
-_ClearMMX_32: 
+_ClearMMX_32:
         pushl %ebp
         movl %esp,%ebp
 
         movl 8(%ebp),%ebp
 
-        movl 4(%ebp),%eax       # pixel value   
+        movl 4(%ebp),%eax       # pixel value
         movd 4(%ebp),%mm0
 
         movl 12(%ebp),%edx      # height
@@ -41,7 +41,7 @@ _ClearMMX_32:
         movl (%ebp),%edi        # destination
 
         por %mm1,%mm0
-_ClearMMX_32.L_y: 
+_ClearMMX_32.L_y:
         movl 8(%ebp),%ecx
 
         movl %ecx,%ebx
@@ -49,7 +49,7 @@ _ClearMMX_32.L_y:
         shrl %ecx
         jz _ClearMMX_32.L_last
 
-_ClearMMX_32.L_x: 
+_ClearMMX_32.L_x:
         movq %mm0,(%edi)
         addl $8,%edi
 
@@ -57,14 +57,14 @@ _ClearMMX_32.L_x:
         jnz _ClearMMX_32.L_x
 
 
-_ClearMMX_32.L_last: 
+_ClearMMX_32.L_last:
         testl $1,%ebx
         jz _ClearMMX_32.L_endline
 
         movl %eax,(%edi)
         addl $4,%edi
 
-_ClearMMX_32.L_endline: 
+_ClearMMX_32.L_endline:
 
         addl 16(%ebp),%edi
 
@@ -78,18 +78,18 @@ _ClearMMX_32.L_endline:
 
 
 
-_ClearMMX_24: 
+_ClearMMX_24:
         ret
 
 
 
-_ClearMMX_16: 
+_ClearMMX_16:
         pushl %ebp
         movl %esp,%ebp
 
         movl 8(%ebp),%ebp
 
-        movl 4(%ebp),%eax       # pixel value   
+        movl 4(%ebp),%eax       # pixel value
         movl 4(%ebp),%ebx
 
         movl 12(%ebp),%edx      # height
@@ -106,7 +106,7 @@ _ClearMMX_16:
         psllq $32,%mm0
 
         por %mm1,%mm0
-_ClearMMX_16.L_y: 
+_ClearMMX_16.L_y:
         movl 8(%ebp),%ecx
 
         testl $3,%edi           # Check if destination is aligned mod 4
@@ -118,20 +118,20 @@ _ClearMMX_16.L_y:
         decl %ecx
         jz _ClearMMX_16.L_endline
 
-_ClearMMX_16.L_aligned: 
+_ClearMMX_16.L_aligned:
         movl %ecx,%ebx
         shrl $2,%ecx
 
         jz _ClearMMX_16.L_last
 
-_ClearMMX_16.L_x: 
+_ClearMMX_16.L_x:
         movq %mm0,(%edi)
         addl $8,%edi
 
         decl %ecx
         jnz _ClearMMX_16.L_x
 
-_ClearMMX_16.L_last: 
+_ClearMMX_16.L_last:
         andl $3,%ebx
         jz _ClearMMX_16.L_endline
 
@@ -150,7 +150,7 @@ _ClearMMX_16.L_last:
         decl %ebx
         jnz _ClearMMX_16.L_endline
 
-_ClearMMX_16.L_endline: 
+_ClearMMX_16.L_endline:
         addl 16(%ebp),%edi
 
         decl %edx
@@ -165,13 +165,13 @@ _ClearMMX_16.L_endline:
 
 ## Clear8_x86 isnt optimised fully yet as it seems to be a tiny bit slower
 ## than the C routine
-_ClearMMX_8: 
+_ClearMMX_8:
         pushl %ebp
         movl %esp,%ebp
 
         movl 8(%ebp),%ebp
 
-        movl 4(%ebp),%eax       # pixel value           
+        movl 4(%ebp),%eax       # pixel value
         movl 4(%ebp),%ebx
 
         movl 12(%ebp),%edx      # height
@@ -195,7 +195,7 @@ _ClearMMX_8:
 
         por %mm1,%mm0
 
-_ClearMMX_8.L_y: 
+_ClearMMX_8.L_y:
         movl 8(%ebp),%ecx
 
         testl $3,%edi           # Align mod 4
@@ -226,20 +226,20 @@ _ClearMMX_8.L_y:
         decl %ebx
         jz _ClearMMX_8.L_aligned
 
-_ClearMMX_8.L_aligned: 
+_ClearMMX_8.L_aligned:
         movl %ecx,%ebx          # Store ecx for later
 
         shrl $3,%ecx            # We write 8 pixels at once
         jz _ClearMMX_8.L_last
 
-_ClearMMX_8.L_x: 
+_ClearMMX_8.L_x:
         movq %mm0,(%edi)
         addl $8,%edi
 
         decl %ecx
         jnz _ClearMMX_8.L_x
 
-_ClearMMX_8.L_last: 
+_ClearMMX_8.L_last:
         movl %ebx,%ecx          # Clean up trailing pixels
 
         andl $7,%ecx            # Could be up to 7 left
@@ -253,11 +253,11 @@ _ClearMMX_8.L_last:
 
         subl $4,%ecx
 
-_ClearMMX_8.L_lessthanfour: 
+_ClearMMX_8.L_lessthanfour:
         rep
  stosb              # Clean up the very rest
 
-_ClearMMX_8.L_endline: 
+_ClearMMX_8.L_endline:
         addl 16(%ebp),%edi
 
         decl %edx
@@ -267,5 +267,3 @@ _ClearMMX_8.L_endline:
 
         popl %ebp
         ret
-
-

+ 9 - 12
packages/hermes/src/i386/mmx_main.as

@@ -2,12 +2,12 @@
 # x86 format converters for HERMES
 # Some routines Copyright (c) 1998 Christian Nentwich ([email protected])
 # This source code is licensed under the GNU LGPL
-# 
+#
 # Please refer to the file COPYING.LIB contained in the distribution for
-# licensing conditions          
+# licensing conditions
 #
 # Most routines are (c) Glenn Fiedler ([email protected]), used with permission
-# 
+#
 
 #BITS 32
 
@@ -17,7 +17,7 @@
 
 .text
 
-## _ConvertMMX:  
+## _ConvertMMX:
 ## [ESP+8] ConverterInfo*
 ## --------------------------------------------------------------------------
 ## ConverterInfo (ebp+..)
@@ -29,10 +29,10 @@
 ##  20: int d_width
 ##  24: int d_height
 ##  28: int d_add
-##  32: void (*converter_function)() 
+##  32: void (*converter_function)()
 ##  36: int32 *lookup
 
-_ConvertMMX: 
+_ConvertMMX:
         pushl %ebp
         movl %esp,%ebp
 
@@ -46,12 +46,12 @@ _ConvertMMX:
         movl (%ebp),%esi
         movl 16(%ebp),%edi
 
-y_loop: 
+y_loop:
         movl 4(%ebp),%ecx
 
         jmp *32(%ebp)
 
-_mmxreturn: 
+_mmxreturn:
         addl 12(%ebp),%esi
         addl 28(%ebp),%edi
 
@@ -61,10 +61,7 @@ _mmxreturn:
 
         popl %ebp
 
-endconvert: 
+endconvert:
         emms
 
         ret
-
-
-

+ 27 - 30
packages/hermes/src/i386/mmxp2_32.as

@@ -3,12 +3,12 @@
 # Copyright (c) 1998 Christian Nentwich ([email protected])
 #   and (c) 1999 Jonathan Matthew ([email protected])
 # This source code is licensed under the GNU LGPL
-# 
+#
 # Please refer to the file COPYING.LIB contained in the distribution for
-# licensing conditions          
+# licensing conditions
 #
 # COPYRIGHT NOTICE
-# 
+#
 # This file partly contains code that is (c) Intel Corporation, specifically
 # the mode detection routine, and the converter to 15 bit (8 pixel
 # conversion routine from the mmx programming tutorial pages).
@@ -50,7 +50,7 @@ mmx32_bgr555_mul: .long 0x00082000,0x00082000
 
 .text
 
-_ConvertMMXpII32_24RGB888: 
+_ConvertMMXpII32_24RGB888:
 
         # set up mm6 as the mask, mm7 as zero
         movq mmx32_rgb888_mask,%mm6
@@ -61,7 +61,7 @@ _ConvertMMXpII32_24RGB888:
         jnz _ConvertMMXpII32_24RGB888.L1
         jmp _ConvertMMXpII32_24RGB888.L2
 
-_ConvertMMXpII32_24RGB888.L1: 
+_ConvertMMXpII32_24RGB888.L1:
 
         movq (%esi),%mm0                # A R G B a r g b
         pand %mm6,%mm0                  # 0 R G B 0 r g b
@@ -92,11 +92,11 @@ _ConvertMMXpII32_24RGB888.L1:
         subl $4,%ecx
         jnz _ConvertMMXpII32_24RGB888.L1
 
-_ConvertMMXpII32_24RGB888.L2: 
+_ConvertMMXpII32_24RGB888.L2:
         movl %edx,%ecx
         andl $3,%ecx
         jz _ConvertMMXpII32_24RGB888.L4
-_ConvertMMXpII32_24RGB888.L3: 
+_ConvertMMXpII32_24RGB888.L3:
         movb (%esi),%al
         movb 1(%esi),%bl
         movb 2(%esi),%dl
@@ -107,12 +107,12 @@ _ConvertMMXpII32_24RGB888.L3:
         addl $3,%edi
         decl %ecx
         jnz _ConvertMMXpII32_24RGB888.L3
-_ConvertMMXpII32_24RGB888.L4: 
+_ConvertMMXpII32_24RGB888.L4:
         jmp _mmxreturn
 
 
 
-_ConvertMMXpII32_16RGB565: 
+_ConvertMMXpII32_16RGB565:
 
         # set up masks
         movq mmx32_rgb565_b,%mm5
@@ -124,7 +124,7 @@ _ConvertMMXpII32_16RGB565:
         jnz _ConvertMMXpII32_16RGB565.L1
         jmp _ConvertMMXpII32_16RGB565.L2 # not necessary at the moment, but doesnt hurt (much)
 
-_ConvertMMXpII32_16RGB565.L1: 
+_ConvertMMXpII32_16RGB565.L1:
         movq (%esi),%mm0        # argb
         movq %mm0,%mm1          # argb
         pand %mm6,%mm0          # 00g0
@@ -155,11 +155,11 @@ _ConvertMMXpII32_16RGB565.L1:
         decl %ecx
         jnz _ConvertMMXpII32_16RGB565.L1
 
-_ConvertMMXpII32_16RGB565.L2: 
+_ConvertMMXpII32_16RGB565.L2:
         movl %edx,%ecx
         andl $3,%ecx
         jz _ConvertMMXpII32_16RGB565.L4
-_ConvertMMXpII32_16RGB565.L3: 
+_ConvertMMXpII32_16RGB565.L3:
         movb (%esi),%al
         movb 1(%esi),%bh
         movb 2(%esi),%ah
@@ -175,11 +175,11 @@ _ConvertMMXpII32_16RGB565.L3:
         decl %ecx
         jnz _ConvertMMXpII32_16RGB565.L3
 
-_ConvertMMXpII32_16RGB565.L4: 
+_ConvertMMXpII32_16RGB565.L4:
         jmp _mmxreturn
 
 
-_ConvertMMXpII32_16BGR565: 
+_ConvertMMXpII32_16BGR565:
 
         movq mmx32_rgb565_r,%mm5
         movq mmx32_rgb565_g,%mm6
@@ -190,7 +190,7 @@ _ConvertMMXpII32_16BGR565:
         jnz _ConvertMMXpII32_16BGR565.L1
         jmp _ConvertMMXpII32_16BGR565.L2
 
-_ConvertMMXpII32_16BGR565.L1: 
+_ConvertMMXpII32_16BGR565.L1:
         movq (%esi),%mm0                # a r g b
         movq %mm0,%mm1                  # a r g b
         pand %mm6,%mm0                  # 0 0 g 0
@@ -225,10 +225,10 @@ _ConvertMMXpII32_16BGR565.L1:
         decl %ecx
         jnz _ConvertMMXpII32_16BGR565.L1
 
-_ConvertMMXpII32_16BGR565.L2: 
+_ConvertMMXpII32_16BGR565.L2:
         andl $3,%edx
         jz _ConvertMMXpII32_16BGR565.L4
-_ConvertMMXpII32_16BGR565.L3: 
+_ConvertMMXpII32_16BGR565.L3:
         movb 2(%esi),%al
         movb 1(%esi),%bh
         movb (%esi),%ah
@@ -244,10 +244,10 @@ _ConvertMMXpII32_16BGR565.L3:
         decl %edx
         jnz _ConvertMMXpII32_16BGR565.L3
 
-_ConvertMMXpII32_16BGR565.L4: 
+_ConvertMMXpII32_16BGR565.L4:
         jmp _mmxreturn
 
-_ConvertMMXpII32_16BGR555: 
+_ConvertMMXpII32_16BGR555:
 
         # the 16BGR555 converter is identical to the RGB555 one,
         # except it uses a different multiplier for the pmaddwd
@@ -261,19 +261,19 @@ _ConvertMMXpII32_16BGR555:
 # would almost certainly be faster, even if only a little.
 # I did rename 'mmx32_rgb555_add' to 'mmx32_rgb555_mul', which is
 # (I think) a more accurate name..
-_ConvertMMXpII32_16RGB555: 
+_ConvertMMXpII32_16RGB555:
 
         movq mmx32_rgb555_mul,%mm7
-_convert_bgr555_cheat: 
+_convert_bgr555_cheat:
         movq mmx32_rgb555_g,%mm6
 
-        movl %ecx,%edx                     # Save ecx 
+        movl %ecx,%edx                     # Save ecx
 
         andl $0x0fffffff8,%ecx             # clear lower three bits
         jnz _convert_bgr555_cheat.L_OK
         jmp _convert_bgr555_cheat.L2
 
-_convert_bgr555_cheat.L_OK: 
+_convert_bgr555_cheat.L_OK:
 
         movq 8(%esi),%mm2
 
@@ -289,7 +289,7 @@ _convert_bgr555_cheat.L_OK:
         pmaddwd %mm7,%mm1
         pand %mm6,%mm2
 
-_convert_bgr555_cheat.L1: 
+_convert_bgr555_cheat.L1:
         movq 24(%esi),%mm4
         pand %mm6,%mm0
 
@@ -346,13 +346,13 @@ _convert_bgr555_cheat.L1:
         jmp _convert_bgr555_cheat.L1
 
 
-_convert_bgr555_cheat.L2: 
+_convert_bgr555_cheat.L2:
         movl %edx,%ecx
 
         andl $7,%ecx
         jz _convert_bgr555_cheat.L4
 
-_convert_bgr555_cheat.L3: 
+_convert_bgr555_cheat.L3:
         movl (%esi),%ebx
         addl $4,%esi
 
@@ -379,8 +379,5 @@ _convert_bgr555_cheat.L3:
         decl %ecx
         jnz _convert_bgr555_cheat.L3
 
-_convert_bgr555_cheat.L4: 
+_convert_bgr555_cheat.L4:
         jmp _mmxreturn
-
-
-

+ 14 - 14
packages/hermes/src/i386/mmxp_32.as

@@ -2,16 +2,16 @@
 # MMX format converters for HERMES
 # Copyright (c) 1998 Christian Nentwich ([email protected])
 # This source code is licensed under the GNU LGPL
-# 
+#
 # Please refer to the file COPYING.LIB contained in the distribution for
-# licensing conditions          
+# licensing conditions
 #
 # COPYRIGHT NOTICE
-# 
+#
 # This file partly contains code that is (c) Intel Corporation, specifically
 # the mode detection routine, and the converter to 15 bit (8 pixel
 # conversion routine from the mmx programming tutorial pages).
-# 
+#
 
 #BITS 32
 
@@ -24,7 +24,7 @@
 
 .align 8
 
-mmx32_rgb555_rb: .long 0x00f800f8,0x00f800f8 # Constants for conversion routines 
+mmx32_rgb555_rb: .long 0x00f800f8,0x00f800f8 # Constants for conversion routines
 mmx32_rgb555_add: .long 0x20000008,0x20000008
 mmx32_rgb555_g: .long 0x0000f800,0x0000f800
 
@@ -34,26 +34,26 @@ mmx32_rgb555_g: .long 0x0000f800,0x0000f800
 
 
 
-## Gone for now, it didnt draw correctly AND was slower than the x86 routine 
-_ConvertMMXp32_16RGB565: 
+## Gone for now, it didnt draw correctly AND was slower than the x86 routine
+_ConvertMMXp32_16RGB565:
 
         jmp _mmxreturn
 
 
 
 
-_ConvertMMXp32_16RGB555: 
+_ConvertMMXp32_16RGB555:
 
         movq mmx32_rgb555_add,%mm7
         movq mmx32_rgb555_g,%mm6
 
-        movl %ecx,%edx                     # Save ecx 
+        movl %ecx,%edx                     # Save ecx
 
         andl $0x0fffffff8,%ecx             # clear lower three bits
         jnz _ConvertMMXp32_16RGB555.L_OK
         jmp _ConvertMMXp32_16RGB555.L2
 
-_ConvertMMXp32_16RGB555.L_OK: 
+_ConvertMMXp32_16RGB555.L_OK:
 
         movq 8(%esi),%mm2
 
@@ -69,7 +69,7 @@ _ConvertMMXp32_16RGB555.L_OK:
         pmaddwd %mm7,%mm1
         pand %mm6,%mm2
 
-_ConvertMMXp32_16RGB555.L1: 
+_ConvertMMXp32_16RGB555.L1:
         movq 24(%esi),%mm4
         pand %mm6,%mm0
 
@@ -126,13 +126,13 @@ _ConvertMMXp32_16RGB555.L1:
         jmp _ConvertMMXp32_16RGB555.L1
 
 
-_ConvertMMXp32_16RGB555.L2: 
+_ConvertMMXp32_16RGB555.L2:
         movl %edx,%ecx
 
         andl $7,%ecx
         jz _ConvertMMXp32_16RGB555.L4
 
-_ConvertMMXp32_16RGB555.L3: 
+_ConvertMMXp32_16RGB555.L3:
         movl (%esi),%ebx
         addl $4,%esi
 
@@ -159,5 +159,5 @@ _ConvertMMXp32_16RGB555.L3:
         decl %ecx
         jnz _ConvertMMXp32_16RGB555.L3
 
-_ConvertMMXp32_16RGB555.L4: 
+_ConvertMMXp32_16RGB555.L4:
         jmp _mmxreturn

+ 2048 - 2048
packages/hermes/src/i386/x8616lut.as

@@ -2,2058 +2,2058 @@
 .data
 
 _ConvertX86p16_32RGB888_LUT_X86:
-		.long 0x00000
-		.long 0x00000
-		.long 0x00008
-		.long 0x02000
-		.long 0x00010
-		.long 0x04000
-		.long 0x00018
-		.long 0x06100
-		.long 0x00020
-		.long 0x08100
-		.long 0x00029
-		.long 0x0a100
-		.long 0x00031
-		.long 0x0c200
-		.long 0x00039
-		.long 0x0e200
-		.long 0x00041
-		.long 0x80000
-		.long 0x0004a
-		.long 0x82000
-		.long 0x00052
-		.long 0x84000
-		.long 0x0005a
-		.long 0x86100
-		.long 0x00062
-		.long 0x88100
-		.long 0x0006a
-		.long 0x8a100
-		.long 0x00073
-		.long 0x8c200
-		.long 0x0007b
-		.long 0x8e200
-		.long 0x00083
-		.long 0x100000
-		.long 0x0008b
-		.long 0x102000
-		.long 0x00094
-		.long 0x104000
-		.long 0x0009c
-		.long 0x106100
-		.long 0x000a4
-		.long 0x108100
-		.long 0x000ac
-		.long 0x10a100
-		.long 0x000b4
-		.long 0x10c200
-		.long 0x000bd
-		.long 0x10e200
-		.long 0x000c5
-		.long 0x180000
-		.long 0x000cd
-		.long 0x182000
-		.long 0x000d5
-		.long 0x184000
-		.long 0x000de
-		.long 0x186100
-		.long 0x000e6
-		.long 0x188100
-		.long 0x000ee
-		.long 0x18a100
-		.long 0x000f6
-		.long 0x18c200
-		.long 0x000ff
-		.long 0x18e200
-		.long 0x00400
-		.long 0x200000
-		.long 0x00408
-		.long 0x202000
-		.long 0x00410
-		.long 0x204000
-		.long 0x00418
-		.long 0x206100
-		.long 0x00420
-		.long 0x208100
-		.long 0x00429
-		.long 0x20a100
-		.long 0x00431
-		.long 0x20c200
-		.long 0x00439
-		.long 0x20e200
-		.long 0x00441
-		.long 0x290000
-		.long 0x0044a
-		.long 0x292000
-		.long 0x00452
-		.long 0x294000
-		.long 0x0045a
-		.long 0x296100
-		.long 0x00462
-		.long 0x298100
-		.long 0x0046a
-		.long 0x29a100
-		.long 0x00473
-		.long 0x29c200
-		.long 0x0047b
-		.long 0x29e200
-		.long 0x00483
-		.long 0x310000
-		.long 0x0048b
-		.long 0x312000
-		.long 0x00494
-		.long 0x314000
-		.long 0x0049c
-		.long 0x316100
-		.long 0x004a4
-		.long 0x318100
-		.long 0x004ac
-		.long 0x31a100
-		.long 0x004b4
-		.long 0x31c200
-		.long 0x004bd
-		.long 0x31e200
-		.long 0x004c5
-		.long 0x390000
-		.long 0x004cd
-		.long 0x392000
-		.long 0x004d5
-		.long 0x394000
-		.long 0x004de
-		.long 0x396100
-		.long 0x004e6
-		.long 0x398100
-		.long 0x004ee
-		.long 0x39a100
-		.long 0x004f6
-		.long 0x39c200
-		.long 0x004ff
-		.long 0x39e200
-		.long 0x00800
-		.long 0x410000
-		.long 0x00808
-		.long 0x412000
-		.long 0x00810
-		.long 0x414000
-		.long 0x00818
-		.long 0x416100
-		.long 0x00820
-		.long 0x418100
-		.long 0x00829
-		.long 0x41a100
-		.long 0x00831
-		.long 0x41c200
-		.long 0x00839
-		.long 0x41e200
-		.long 0x00841
-		.long 0x4a0000
-		.long 0x0084a
-		.long 0x4a2000
-		.long 0x00852
-		.long 0x4a4000
-		.long 0x0085a
-		.long 0x4a6100
-		.long 0x00862
-		.long 0x4a8100
-		.long 0x0086a
-		.long 0x4aa100
-		.long 0x00873
-		.long 0x4ac200
-		.long 0x0087b
-		.long 0x4ae200
-		.long 0x00883
-		.long 0x520000
-		.long 0x0088b
-		.long 0x522000
-		.long 0x00894
-		.long 0x524000
-		.long 0x0089c
-		.long 0x526100
-		.long 0x008a4
-		.long 0x528100
-		.long 0x008ac
-		.long 0x52a100
-		.long 0x008b4
-		.long 0x52c200
-		.long 0x008bd
-		.long 0x52e200
-		.long 0x008c5
-		.long 0x5a0000
-		.long 0x008cd
-		.long 0x5a2000
-		.long 0x008d5
-		.long 0x5a4000
-		.long 0x008de
-		.long 0x5a6100
-		.long 0x008e6
-		.long 0x5a8100
-		.long 0x008ee
-		.long 0x5aa100
-		.long 0x008f6
-		.long 0x5ac200
-		.long 0x008ff
-		.long 0x5ae200
-		.long 0x00c00
-		.long 0x620000
-		.long 0x00c08
-		.long 0x622000
-		.long 0x00c10
-		.long 0x624000
-		.long 0x00c18
-		.long 0x626100
-		.long 0x00c20
-		.long 0x628100
-		.long 0x00c29
-		.long 0x62a100
-		.long 0x00c31
-		.long 0x62c200
-		.long 0x00c39
-		.long 0x62e200
-		.long 0x00c41
-		.long 0x6a0000
-		.long 0x00c4a
-		.long 0x6a2000
-		.long 0x00c52
-		.long 0x6a4000
-		.long 0x00c5a
-		.long 0x6a6100
-		.long 0x00c62
-		.long 0x6a8100
-		.long 0x00c6a
-		.long 0x6aa100
-		.long 0x00c73
-		.long 0x6ac200
-		.long 0x00c7b
-		.long 0x6ae200
-		.long 0x00c83
-		.long 0x730000
-		.long 0x00c8b
-		.long 0x732000
-		.long 0x00c94
-		.long 0x734000
-		.long 0x00c9c
-		.long 0x736100
-		.long 0x00ca4
-		.long 0x738100
-		.long 0x00cac
-		.long 0x73a100
-		.long 0x00cb4
-		.long 0x73c200
-		.long 0x00cbd
-		.long 0x73e200
-		.long 0x00cc5
-		.long 0x7b0000
-		.long 0x00ccd
-		.long 0x7b2000
-		.long 0x00cd5
-		.long 0x7b4000
-		.long 0x00cde
-		.long 0x7b6100
-		.long 0x00ce6
-		.long 0x7b8100
-		.long 0x00cee
-		.long 0x7ba100
-		.long 0x00cf6
-		.long 0x7bc200
-		.long 0x00cff
-		.long 0x7be200
-		.long 0x01000
-		.long 0x830000
-		.long 0x01008
-		.long 0x832000
-		.long 0x01010
-		.long 0x834000
-		.long 0x01018
-		.long 0x836100
-		.long 0x01020
-		.long 0x838100
-		.long 0x01029
-		.long 0x83a100
-		.long 0x01031
-		.long 0x83c200
-		.long 0x01039
-		.long 0x83e200
-		.long 0x01041
-		.long 0x8b0000
-		.long 0x0104a
-		.long 0x8b2000
-		.long 0x01052
-		.long 0x8b4000
-		.long 0x0105a
-		.long 0x8b6100
-		.long 0x01062
-		.long 0x8b8100
-		.long 0x0106a
-		.long 0x8ba100
-		.long 0x01073
-		.long 0x8bc200
-		.long 0x0107b
-		.long 0x8be200
-		.long 0x01083
-		.long 0x940000
-		.long 0x0108b
-		.long 0x942000
-		.long 0x01094
-		.long 0x944000
-		.long 0x0109c
-		.long 0x946100
-		.long 0x010a4
-		.long 0x948100
-		.long 0x010ac
-		.long 0x94a100
-		.long 0x010b4
-		.long 0x94c200
-		.long 0x010bd
-		.long 0x94e200
-		.long 0x010c5
-		.long 0x9c0000
-		.long 0x010cd
-		.long 0x9c2000
-		.long 0x010d5
-		.long 0x9c4000
-		.long 0x010de
-		.long 0x9c6100
-		.long 0x010e6
-		.long 0x9c8100
-		.long 0x010ee
-		.long 0x9ca100
-		.long 0x010f6
-		.long 0x9cc200
-		.long 0x010ff
-		.long 0x9ce200
-		.long 0x01400
-		.long 0xa40000
-		.long 0x01408
-		.long 0xa42000
-		.long 0x01410
-		.long 0xa44000
-		.long 0x01418
-		.long 0xa46100
-		.long 0x01420
-		.long 0xa48100
-		.long 0x01429
-		.long 0xa4a100
-		.long 0x01431
-		.long 0xa4c200
-		.long 0x01439
-		.long 0xa4e200
-		.long 0x01441
-		.long 0xac0000
-		.long 0x0144a
-		.long 0xac2000
-		.long 0x01452
-		.long 0xac4000
-		.long 0x0145a
-		.long 0xac6100
-		.long 0x01462
-		.long 0xac8100
-		.long 0x0146a
-		.long 0xaca100
-		.long 0x01473
-		.long 0xacc200
-		.long 0x0147b
-		.long 0xace200
-		.long 0x01483
-		.long 0xb40000
-		.long 0x0148b
-		.long 0xb42000
-		.long 0x01494
-		.long 0xb44000
-		.long 0x0149c
-		.long 0xb46100
-		.long 0x014a4
-		.long 0xb48100
-		.long 0x014ac
-		.long 0xb4a100
-		.long 0x014b4
-		.long 0xb4c200
-		.long 0x014bd
-		.long 0xb4e200
-		.long 0x014c5
-		.long 0xbd0000
-		.long 0x014cd
-		.long 0xbd2000
-		.long 0x014d5
-		.long 0xbd4000
-		.long 0x014de
-		.long 0xbd6100
-		.long 0x014e6
-		.long 0xbd8100
-		.long 0x014ee
-		.long 0xbda100
-		.long 0x014f6
-		.long 0xbdc200
-		.long 0x014ff
-		.long 0xbde200
-		.long 0x01800
-		.long 0xc50000
-		.long 0x01808
-		.long 0xc52000
-		.long 0x01810
-		.long 0xc54000
-		.long 0x01818
-		.long 0xc56100
-		.long 0x01820
-		.long 0xc58100
-		.long 0x01829
-		.long 0xc5a100
-		.long 0x01831
-		.long 0xc5c200
-		.long 0x01839
-		.long 0xc5e200
-		.long 0x01841
-		.long 0xcd0000
-		.long 0x0184a
-		.long 0xcd2000
-		.long 0x01852
-		.long 0xcd4000
-		.long 0x0185a
-		.long 0xcd6100
-		.long 0x01862
-		.long 0xcd8100
-		.long 0x0186a
-		.long 0xcda100
-		.long 0x01873
-		.long 0xcdc200
-		.long 0x0187b
-		.long 0xcde200
-		.long 0x01883
-		.long 0xd50000
-		.long 0x0188b
-		.long 0xd52000
-		.long 0x01894
-		.long 0xd54000
-		.long 0x0189c
-		.long 0xd56100
-		.long 0x018a4
-		.long 0xd58100
-		.long 0x018ac
-		.long 0xd5a100
-		.long 0x018b4
-		.long 0xd5c200
-		.long 0x018bd
-		.long 0xd5e200
-		.long 0x018c5
-		.long 0xde0000
-		.long 0x018cd
-		.long 0xde2000
-		.long 0x018d5
-		.long 0xde4000
-		.long 0x018de
-		.long 0xde6100
-		.long 0x018e6
-		.long 0xde8100
-		.long 0x018ee
-		.long 0xdea100
-		.long 0x018f6
-		.long 0xdec200
-		.long 0x018ff
-		.long 0xdee200
-		.long 0x01c00
-		.long 0xe60000
-		.long 0x01c08
-		.long 0xe62000
-		.long 0x01c10
-		.long 0xe64000
-		.long 0x01c18
-		.long 0xe66100
-		.long 0x01c20
-		.long 0xe68100
-		.long 0x01c29
-		.long 0xe6a100
-		.long 0x01c31
-		.long 0xe6c200
-		.long 0x01c39
-		.long 0xe6e200
-		.long 0x01c41
-		.long 0xee0000
-		.long 0x01c4a
-		.long 0xee2000
-		.long 0x01c52
-		.long 0xee4000
-		.long 0x01c5a
-		.long 0xee6100
-		.long 0x01c62
-		.long 0xee8100
-		.long 0x01c6a
-		.long 0xeea100
-		.long 0x01c73
-		.long 0xeec200
-		.long 0x01c7b
-		.long 0xeee200
-		.long 0x01c83
-		.long 0xf60000
-		.long 0x01c8b
-		.long 0xf62000
-		.long 0x01c94
-		.long 0xf64000
-		.long 0x01c9c
-		.long 0xf66100
-		.long 0x01ca4
-		.long 0xf68100
-		.long 0x01cac
-		.long 0xf6a100
-		.long 0x01cb4
-		.long 0xf6c200
-		.long 0x01cbd
-		.long 0xf6e200
-		.long 0x01cc5
-		.long 0xff0000
-		.long 0x01ccd
-		.long 0xff2000
-		.long 0x01cd5
-		.long 0xff4000
-		.long 0x01cde
-		.long 0xff6100
-		.long 0x01ce6
-		.long 0xff8100
-		.long 0x01cee
-		.long 0xffa100
-		.long 0x01cf6
-		.long 0xffc200
-		.long 0x01cff
-		.long 0xffe200
+                .long 0x00000
+                .long 0x00000
+                .long 0x00008
+                .long 0x02000
+                .long 0x00010
+                .long 0x04000
+                .long 0x00018
+                .long 0x06100
+                .long 0x00020
+                .long 0x08100
+                .long 0x00029
+                .long 0x0a100
+                .long 0x00031
+                .long 0x0c200
+                .long 0x00039
+                .long 0x0e200
+                .long 0x00041
+                .long 0x80000
+                .long 0x0004a
+                .long 0x82000
+                .long 0x00052
+                .long 0x84000
+                .long 0x0005a
+                .long 0x86100
+                .long 0x00062
+                .long 0x88100
+                .long 0x0006a
+                .long 0x8a100
+                .long 0x00073
+                .long 0x8c200
+                .long 0x0007b
+                .long 0x8e200
+                .long 0x00083
+                .long 0x100000
+                .long 0x0008b
+                .long 0x102000
+                .long 0x00094
+                .long 0x104000
+                .long 0x0009c
+                .long 0x106100
+                .long 0x000a4
+                .long 0x108100
+                .long 0x000ac
+                .long 0x10a100
+                .long 0x000b4
+                .long 0x10c200
+                .long 0x000bd
+                .long 0x10e200
+                .long 0x000c5
+                .long 0x180000
+                .long 0x000cd
+                .long 0x182000
+                .long 0x000d5
+                .long 0x184000
+                .long 0x000de
+                .long 0x186100
+                .long 0x000e6
+                .long 0x188100
+                .long 0x000ee
+                .long 0x18a100
+                .long 0x000f6
+                .long 0x18c200
+                .long 0x000ff
+                .long 0x18e200
+                .long 0x00400
+                .long 0x200000
+                .long 0x00408
+                .long 0x202000
+                .long 0x00410
+                .long 0x204000
+                .long 0x00418
+                .long 0x206100
+                .long 0x00420
+                .long 0x208100
+                .long 0x00429
+                .long 0x20a100
+                .long 0x00431
+                .long 0x20c200
+                .long 0x00439
+                .long 0x20e200
+                .long 0x00441
+                .long 0x290000
+                .long 0x0044a
+                .long 0x292000
+                .long 0x00452
+                .long 0x294000
+                .long 0x0045a
+                .long 0x296100
+                .long 0x00462
+                .long 0x298100
+                .long 0x0046a
+                .long 0x29a100
+                .long 0x00473
+                .long 0x29c200
+                .long 0x0047b
+                .long 0x29e200
+                .long 0x00483
+                .long 0x310000
+                .long 0x0048b
+                .long 0x312000
+                .long 0x00494
+                .long 0x314000
+                .long 0x0049c
+                .long 0x316100
+                .long 0x004a4
+                .long 0x318100
+                .long 0x004ac
+                .long 0x31a100
+                .long 0x004b4
+                .long 0x31c200
+                .long 0x004bd
+                .long 0x31e200
+                .long 0x004c5
+                .long 0x390000
+                .long 0x004cd
+                .long 0x392000
+                .long 0x004d5
+                .long 0x394000
+                .long 0x004de
+                .long 0x396100
+                .long 0x004e6
+                .long 0x398100
+                .long 0x004ee
+                .long 0x39a100
+                .long 0x004f6
+                .long 0x39c200
+                .long 0x004ff
+                .long 0x39e200
+                .long 0x00800
+                .long 0x410000
+                .long 0x00808
+                .long 0x412000
+                .long 0x00810
+                .long 0x414000
+                .long 0x00818
+                .long 0x416100
+                .long 0x00820
+                .long 0x418100
+                .long 0x00829
+                .long 0x41a100
+                .long 0x00831
+                .long 0x41c200
+                .long 0x00839
+                .long 0x41e200
+                .long 0x00841
+                .long 0x4a0000
+                .long 0x0084a
+                .long 0x4a2000
+                .long 0x00852
+                .long 0x4a4000
+                .long 0x0085a
+                .long 0x4a6100
+                .long 0x00862
+                .long 0x4a8100
+                .long 0x0086a
+                .long 0x4aa100
+                .long 0x00873
+                .long 0x4ac200
+                .long 0x0087b
+                .long 0x4ae200
+                .long 0x00883
+                .long 0x520000
+                .long 0x0088b
+                .long 0x522000
+                .long 0x00894
+                .long 0x524000
+                .long 0x0089c
+                .long 0x526100
+                .long 0x008a4
+                .long 0x528100
+                .long 0x008ac
+                .long 0x52a100
+                .long 0x008b4
+                .long 0x52c200
+                .long 0x008bd
+                .long 0x52e200
+                .long 0x008c5
+                .long 0x5a0000
+                .long 0x008cd
+                .long 0x5a2000
+                .long 0x008d5
+                .long 0x5a4000
+                .long 0x008de
+                .long 0x5a6100
+                .long 0x008e6
+                .long 0x5a8100
+                .long 0x008ee
+                .long 0x5aa100
+                .long 0x008f6
+                .long 0x5ac200
+                .long 0x008ff
+                .long 0x5ae200
+                .long 0x00c00
+                .long 0x620000
+                .long 0x00c08
+                .long 0x622000
+                .long 0x00c10
+                .long 0x624000
+                .long 0x00c18
+                .long 0x626100
+                .long 0x00c20
+                .long 0x628100
+                .long 0x00c29
+                .long 0x62a100
+                .long 0x00c31
+                .long 0x62c200
+                .long 0x00c39
+                .long 0x62e200
+                .long 0x00c41
+                .long 0x6a0000
+                .long 0x00c4a
+                .long 0x6a2000
+                .long 0x00c52
+                .long 0x6a4000
+                .long 0x00c5a
+                .long 0x6a6100
+                .long 0x00c62
+                .long 0x6a8100
+                .long 0x00c6a
+                .long 0x6aa100
+                .long 0x00c73
+                .long 0x6ac200
+                .long 0x00c7b
+                .long 0x6ae200
+                .long 0x00c83
+                .long 0x730000
+                .long 0x00c8b
+                .long 0x732000
+                .long 0x00c94
+                .long 0x734000
+                .long 0x00c9c
+                .long 0x736100
+                .long 0x00ca4
+                .long 0x738100
+                .long 0x00cac
+                .long 0x73a100
+                .long 0x00cb4
+                .long 0x73c200
+                .long 0x00cbd
+                .long 0x73e200
+                .long 0x00cc5
+                .long 0x7b0000
+                .long 0x00ccd
+                .long 0x7b2000
+                .long 0x00cd5
+                .long 0x7b4000
+                .long 0x00cde
+                .long 0x7b6100
+                .long 0x00ce6
+                .long 0x7b8100
+                .long 0x00cee
+                .long 0x7ba100
+                .long 0x00cf6
+                .long 0x7bc200
+                .long 0x00cff
+                .long 0x7be200
+                .long 0x01000
+                .long 0x830000
+                .long 0x01008
+                .long 0x832000
+                .long 0x01010
+                .long 0x834000
+                .long 0x01018
+                .long 0x836100
+                .long 0x01020
+                .long 0x838100
+                .long 0x01029
+                .long 0x83a100
+                .long 0x01031
+                .long 0x83c200
+                .long 0x01039
+                .long 0x83e200
+                .long 0x01041
+                .long 0x8b0000
+                .long 0x0104a
+                .long 0x8b2000
+                .long 0x01052
+                .long 0x8b4000
+                .long 0x0105a
+                .long 0x8b6100
+                .long 0x01062
+                .long 0x8b8100
+                .long 0x0106a
+                .long 0x8ba100
+                .long 0x01073
+                .long 0x8bc200
+                .long 0x0107b
+                .long 0x8be200
+                .long 0x01083
+                .long 0x940000
+                .long 0x0108b
+                .long 0x942000
+                .long 0x01094
+                .long 0x944000
+                .long 0x0109c
+                .long 0x946100
+                .long 0x010a4
+                .long 0x948100
+                .long 0x010ac
+                .long 0x94a100
+                .long 0x010b4
+                .long 0x94c200
+                .long 0x010bd
+                .long 0x94e200
+                .long 0x010c5
+                .long 0x9c0000
+                .long 0x010cd
+                .long 0x9c2000
+                .long 0x010d5
+                .long 0x9c4000
+                .long 0x010de
+                .long 0x9c6100
+                .long 0x010e6
+                .long 0x9c8100
+                .long 0x010ee
+                .long 0x9ca100
+                .long 0x010f6
+                .long 0x9cc200
+                .long 0x010ff
+                .long 0x9ce200
+                .long 0x01400
+                .long 0xa40000
+                .long 0x01408
+                .long 0xa42000
+                .long 0x01410
+                .long 0xa44000
+                .long 0x01418
+                .long 0xa46100
+                .long 0x01420
+                .long 0xa48100
+                .long 0x01429
+                .long 0xa4a100
+                .long 0x01431
+                .long 0xa4c200
+                .long 0x01439
+                .long 0xa4e200
+                .long 0x01441
+                .long 0xac0000
+                .long 0x0144a
+                .long 0xac2000
+                .long 0x01452
+                .long 0xac4000
+                .long 0x0145a
+                .long 0xac6100
+                .long 0x01462
+                .long 0xac8100
+                .long 0x0146a
+                .long 0xaca100
+                .long 0x01473
+                .long 0xacc200
+                .long 0x0147b
+                .long 0xace200
+                .long 0x01483
+                .long 0xb40000
+                .long 0x0148b
+                .long 0xb42000
+                .long 0x01494
+                .long 0xb44000
+                .long 0x0149c
+                .long 0xb46100
+                .long 0x014a4
+                .long 0xb48100
+                .long 0x014ac
+                .long 0xb4a100
+                .long 0x014b4
+                .long 0xb4c200
+                .long 0x014bd
+                .long 0xb4e200
+                .long 0x014c5
+                .long 0xbd0000
+                .long 0x014cd
+                .long 0xbd2000
+                .long 0x014d5
+                .long 0xbd4000
+                .long 0x014de
+                .long 0xbd6100
+                .long 0x014e6
+                .long 0xbd8100
+                .long 0x014ee
+                .long 0xbda100
+                .long 0x014f6
+                .long 0xbdc200
+                .long 0x014ff
+                .long 0xbde200
+                .long 0x01800
+                .long 0xc50000
+                .long 0x01808
+                .long 0xc52000
+                .long 0x01810
+                .long 0xc54000
+                .long 0x01818
+                .long 0xc56100
+                .long 0x01820
+                .long 0xc58100
+                .long 0x01829
+                .long 0xc5a100
+                .long 0x01831
+                .long 0xc5c200
+                .long 0x01839
+                .long 0xc5e200
+                .long 0x01841
+                .long 0xcd0000
+                .long 0x0184a
+                .long 0xcd2000
+                .long 0x01852
+                .long 0xcd4000
+                .long 0x0185a
+                .long 0xcd6100
+                .long 0x01862
+                .long 0xcd8100
+                .long 0x0186a
+                .long 0xcda100
+                .long 0x01873
+                .long 0xcdc200
+                .long 0x0187b
+                .long 0xcde200
+                .long 0x01883
+                .long 0xd50000
+                .long 0x0188b
+                .long 0xd52000
+                .long 0x01894
+                .long 0xd54000
+                .long 0x0189c
+                .long 0xd56100
+                .long 0x018a4
+                .long 0xd58100
+                .long 0x018ac
+                .long 0xd5a100
+                .long 0x018b4
+                .long 0xd5c200
+                .long 0x018bd
+                .long 0xd5e200
+                .long 0x018c5
+                .long 0xde0000
+                .long 0x018cd
+                .long 0xde2000
+                .long 0x018d5
+                .long 0xde4000
+                .long 0x018de
+                .long 0xde6100
+                .long 0x018e6
+                .long 0xde8100
+                .long 0x018ee
+                .long 0xdea100
+                .long 0x018f6
+                .long 0xdec200
+                .long 0x018ff
+                .long 0xdee200
+                .long 0x01c00
+                .long 0xe60000
+                .long 0x01c08
+                .long 0xe62000
+                .long 0x01c10
+                .long 0xe64000
+                .long 0x01c18
+                .long 0xe66100
+                .long 0x01c20
+                .long 0xe68100
+                .long 0x01c29
+                .long 0xe6a100
+                .long 0x01c31
+                .long 0xe6c200
+                .long 0x01c39
+                .long 0xe6e200
+                .long 0x01c41
+                .long 0xee0000
+                .long 0x01c4a
+                .long 0xee2000
+                .long 0x01c52
+                .long 0xee4000
+                .long 0x01c5a
+                .long 0xee6100
+                .long 0x01c62
+                .long 0xee8100
+                .long 0x01c6a
+                .long 0xeea100
+                .long 0x01c73
+                .long 0xeec200
+                .long 0x01c7b
+                .long 0xeee200
+                .long 0x01c83
+                .long 0xf60000
+                .long 0x01c8b
+                .long 0xf62000
+                .long 0x01c94
+                .long 0xf64000
+                .long 0x01c9c
+                .long 0xf66100
+                .long 0x01ca4
+                .long 0xf68100
+                .long 0x01cac
+                .long 0xf6a100
+                .long 0x01cb4
+                .long 0xf6c200
+                .long 0x01cbd
+                .long 0xf6e200
+                .long 0x01cc5
+                .long 0xff0000
+                .long 0x01ccd
+                .long 0xff2000
+                .long 0x01cd5
+                .long 0xff4000
+                .long 0x01cde
+                .long 0xff6100
+                .long 0x01ce6
+                .long 0xff8100
+                .long 0x01cee
+                .long 0xffa100
+                .long 0x01cf6
+                .long 0xffc200
+                .long 0x01cff
+                .long 0xffe200
 
 _ConvertX86p16_32BGR888_LUT_X86:
-		.long 0x00000
-		.long 0x00000
-		.long 0x80000
-		.long 0x02000
-		.long 0x100000
-		.long 0x04000
-		.long 0x180000
-		.long 0x06100
-		.long 0x200000
-		.long 0x08100
-		.long 0x290000
-		.long 0x0a100
-		.long 0x310000
-		.long 0x0c200
-		.long 0x390000
-		.long 0x0e200
-		.long 0x410000
-		.long 0x00008
-		.long 0x4a0000
-		.long 0x02008
-		.long 0x520000
-		.long 0x04008
-		.long 0x5a0000
-		.long 0x06108
-		.long 0x620000
-		.long 0x08108
-		.long 0x6a0000
-		.long 0x0a108
-		.long 0x730000
-		.long 0x0c208
-		.long 0x7b0000
-		.long 0x0e208
-		.long 0x830000
-		.long 0x00010
-		.long 0x8b0000
-		.long 0x02010
-		.long 0x940000
-		.long 0x04010
-		.long 0x9c0000
-		.long 0x06110
-		.long 0xa40000
-		.long 0x08110
-		.long 0xac0000
-		.long 0x0a110
-		.long 0xb40000
-		.long 0x0c210
-		.long 0xbd0000
-		.long 0x0e210
-		.long 0xc50000
-		.long 0x00018
-		.long 0xcd0000
-		.long 0x02018
-		.long 0xd50000
-		.long 0x04018
-		.long 0xde0000
-		.long 0x06118
-		.long 0xe60000
-		.long 0x08118
-		.long 0xee0000
-		.long 0x0a118
-		.long 0xf60000
-		.long 0x0c218
-		.long 0xff0000
-		.long 0x0e218
-		.long 0x00400
-		.long 0x00020
-		.long 0x80400
-		.long 0x02020
-		.long 0x100400
-		.long 0x04020
-		.long 0x180400
-		.long 0x06120
-		.long 0x200400
-		.long 0x08120
-		.long 0x290400
-		.long 0x0a120
-		.long 0x310400
-		.long 0x0c220
-		.long 0x390400
-		.long 0x0e220
-		.long 0x410400
-		.long 0x00029
-		.long 0x4a0400
-		.long 0x02029
-		.long 0x520400
-		.long 0x04029
-		.long 0x5a0400
-		.long 0x06129
-		.long 0x620400
-		.long 0x08129
-		.long 0x6a0400
-		.long 0x0a129
-		.long 0x730400
-		.long 0x0c229
-		.long 0x7b0400
-		.long 0x0e229
-		.long 0x830400
-		.long 0x00031
-		.long 0x8b0400
-		.long 0x02031
-		.long 0x940400
-		.long 0x04031
-		.long 0x9c0400
-		.long 0x06131
-		.long 0xa40400
-		.long 0x08131
-		.long 0xac0400
-		.long 0x0a131
-		.long 0xb40400
-		.long 0x0c231
-		.long 0xbd0400
-		.long 0x0e231
-		.long 0xc50400
-		.long 0x00039
-		.long 0xcd0400
-		.long 0x02039
-		.long 0xd50400
-		.long 0x04039
-		.long 0xde0400
-		.long 0x06139
-		.long 0xe60400
-		.long 0x08139
-		.long 0xee0400
-		.long 0x0a139
-		.long 0xf60400
-		.long 0x0c239
-		.long 0xff0400
-		.long 0x0e239
-		.long 0x00800
-		.long 0x00041
-		.long 0x80800
-		.long 0x02041
-		.long 0x100800
-		.long 0x04041
-		.long 0x180800
-		.long 0x06141
-		.long 0x200800
-		.long 0x08141
-		.long 0x290800
-		.long 0x0a141
-		.long 0x310800
-		.long 0x0c241
-		.long 0x390800
-		.long 0x0e241
-		.long 0x410800
-		.long 0x0004a
-		.long 0x4a0800
-		.long 0x0204a
-		.long 0x520800
-		.long 0x0404a
-		.long 0x5a0800
-		.long 0x0614a
-		.long 0x620800
-		.long 0x0814a
-		.long 0x6a0800
-		.long 0x0a14a
-		.long 0x730800
-		.long 0x0c24a
-		.long 0x7b0800
-		.long 0x0e24a
-		.long 0x830800
-		.long 0x00052
-		.long 0x8b0800
-		.long 0x02052
-		.long 0x940800
-		.long 0x04052
-		.long 0x9c0800
-		.long 0x06152
-		.long 0xa40800
-		.long 0x08152
-		.long 0xac0800
-		.long 0x0a152
-		.long 0xb40800
-		.long 0x0c252
-		.long 0xbd0800
-		.long 0x0e252
-		.long 0xc50800
-		.long 0x0005a
-		.long 0xcd0800
-		.long 0x0205a
-		.long 0xd50800
-		.long 0x0405a
-		.long 0xde0800
-		.long 0x0615a
-		.long 0xe60800
-		.long 0x0815a
-		.long 0xee0800
-		.long 0x0a15a
-		.long 0xf60800
-		.long 0x0c25a
-		.long 0xff0800
-		.long 0x0e25a
-		.long 0x00c00
-		.long 0x00062
-		.long 0x80c00
-		.long 0x02062
-		.long 0x100c00
-		.long 0x04062
-		.long 0x180c00
-		.long 0x06162
-		.long 0x200c00
-		.long 0x08162
-		.long 0x290c00
-		.long 0x0a162
-		.long 0x310c00
-		.long 0x0c262
-		.long 0x390c00
-		.long 0x0e262
-		.long 0x410c00
-		.long 0x0006a
-		.long 0x4a0c00
-		.long 0x0206a
-		.long 0x520c00
-		.long 0x0406a
-		.long 0x5a0c00
-		.long 0x0616a
-		.long 0x620c00
-		.long 0x0816a
-		.long 0x6a0c00
-		.long 0x0a16a
-		.long 0x730c00
-		.long 0x0c26a
-		.long 0x7b0c00
-		.long 0x0e26a
-		.long 0x830c00
-		.long 0x00073
-		.long 0x8b0c00
-		.long 0x02073
-		.long 0x940c00
-		.long 0x04073
-		.long 0x9c0c00
-		.long 0x06173
-		.long 0xa40c00
-		.long 0x08173
-		.long 0xac0c00
-		.long 0x0a173
-		.long 0xb40c00
-		.long 0x0c273
-		.long 0xbd0c00
-		.long 0x0e273
-		.long 0xc50c00
-		.long 0x0007b
-		.long 0xcd0c00
-		.long 0x0207b
-		.long 0xd50c00
-		.long 0x0407b
-		.long 0xde0c00
-		.long 0x0617b
-		.long 0xe60c00
-		.long 0x0817b
-		.long 0xee0c00
-		.long 0x0a17b
-		.long 0xf60c00
-		.long 0x0c27b
-		.long 0xff0c00
-		.long 0x0e27b
-		.long 0x01000
-		.long 0x00083
-		.long 0x81000
-		.long 0x02083
-		.long 0x101000
-		.long 0x04083
-		.long 0x181000
-		.long 0x06183
-		.long 0x201000
-		.long 0x08183
-		.long 0x291000
-		.long 0x0a183
-		.long 0x311000
-		.long 0x0c283
-		.long 0x391000
-		.long 0x0e283
-		.long 0x411000
-		.long 0x0008b
-		.long 0x4a1000
-		.long 0x0208b
-		.long 0x521000
-		.long 0x0408b
-		.long 0x5a1000
-		.long 0x0618b
-		.long 0x621000
-		.long 0x0818b
-		.long 0x6a1000
-		.long 0x0a18b
-		.long 0x731000
-		.long 0x0c28b
-		.long 0x7b1000
-		.long 0x0e28b
-		.long 0x831000
-		.long 0x00094
-		.long 0x8b1000
-		.long 0x02094
-		.long 0x941000
-		.long 0x04094
-		.long 0x9c1000
-		.long 0x06194
-		.long 0xa41000
-		.long 0x08194
-		.long 0xac1000
-		.long 0x0a194
-		.long 0xb41000
-		.long 0x0c294
-		.long 0xbd1000
-		.long 0x0e294
-		.long 0xc51000
-		.long 0x0009c
-		.long 0xcd1000
-		.long 0x0209c
-		.long 0xd51000
-		.long 0x0409c
-		.long 0xde1000
-		.long 0x0619c
-		.long 0xe61000
-		.long 0x0819c
-		.long 0xee1000
-		.long 0x0a19c
-		.long 0xf61000
-		.long 0x0c29c
-		.long 0xff1000
-		.long 0x0e29c
-		.long 0x01400
-		.long 0x000a4
-		.long 0x81400
-		.long 0x020a4
-		.long 0x101400
-		.long 0x040a4
-		.long 0x181400
-		.long 0x061a4
-		.long 0x201400
-		.long 0x081a4
-		.long 0x291400
-		.long 0x0a1a4
-		.long 0x311400
-		.long 0x0c2a4
-		.long 0x391400
-		.long 0x0e2a4
-		.long 0x411400
-		.long 0x000ac
-		.long 0x4a1400
-		.long 0x020ac
-		.long 0x521400
-		.long 0x040ac
-		.long 0x5a1400
-		.long 0x061ac
-		.long 0x621400
-		.long 0x081ac
-		.long 0x6a1400
-		.long 0x0a1ac
-		.long 0x731400
-		.long 0x0c2ac
-		.long 0x7b1400
-		.long 0x0e2ac
-		.long 0x831400
-		.long 0x000b4
-		.long 0x8b1400
-		.long 0x020b4
-		.long 0x941400
-		.long 0x040b4
-		.long 0x9c1400
-		.long 0x061b4
-		.long 0xa41400
-		.long 0x081b4
-		.long 0xac1400
-		.long 0x0a1b4
-		.long 0xb41400
-		.long 0x0c2b4
-		.long 0xbd1400
-		.long 0x0e2b4
-		.long 0xc51400
-		.long 0x000bd
-		.long 0xcd1400
-		.long 0x020bd
-		.long 0xd51400
-		.long 0x040bd
-		.long 0xde1400
-		.long 0x061bd
-		.long 0xe61400
-		.long 0x081bd
-		.long 0xee1400
-		.long 0x0a1bd
-		.long 0xf61400
-		.long 0x0c2bd
-		.long 0xff1400
-		.long 0x0e2bd
-		.long 0x01800
-		.long 0x000c5
-		.long 0x81800
-		.long 0x020c5
-		.long 0x101800
-		.long 0x040c5
-		.long 0x181800
-		.long 0x061c5
-		.long 0x201800
-		.long 0x081c5
-		.long 0x291800
-		.long 0x0a1c5
-		.long 0x311800
-		.long 0x0c2c5
-		.long 0x391800
-		.long 0x0e2c5
-		.long 0x411800
-		.long 0x000cd
-		.long 0x4a1800
-		.long 0x020cd
-		.long 0x521800
-		.long 0x040cd
-		.long 0x5a1800
-		.long 0x061cd
-		.long 0x621800
-		.long 0x081cd
-		.long 0x6a1800
-		.long 0x0a1cd
-		.long 0x731800
-		.long 0x0c2cd
-		.long 0x7b1800
-		.long 0x0e2cd
-		.long 0x831800
-		.long 0x000d5
-		.long 0x8b1800
-		.long 0x020d5
-		.long 0x941800
-		.long 0x040d5
-		.long 0x9c1800
-		.long 0x061d5
-		.long 0xa41800
-		.long 0x081d5
-		.long 0xac1800
-		.long 0x0a1d5
-		.long 0xb41800
-		.long 0x0c2d5
-		.long 0xbd1800
-		.long 0x0e2d5
-		.long 0xc51800
-		.long 0x000de
-		.long 0xcd1800
-		.long 0x020de
-		.long 0xd51800
-		.long 0x040de
-		.long 0xde1800
-		.long 0x061de
-		.long 0xe61800
-		.long 0x081de
-		.long 0xee1800
-		.long 0x0a1de
-		.long 0xf61800
-		.long 0x0c2de
-		.long 0xff1800
-		.long 0x0e2de
-		.long 0x01c00
-		.long 0x000e6
-		.long 0x81c00
-		.long 0x020e6
-		.long 0x101c00
-		.long 0x040e6
-		.long 0x181c00
-		.long 0x061e6
-		.long 0x201c00
-		.long 0x081e6
-		.long 0x291c00
-		.long 0x0a1e6
-		.long 0x311c00
-		.long 0x0c2e6
-		.long 0x391c00
-		.long 0x0e2e6
-		.long 0x411c00
-		.long 0x000ee
-		.long 0x4a1c00
-		.long 0x020ee
-		.long 0x521c00
-		.long 0x040ee
-		.long 0x5a1c00
-		.long 0x061ee
-		.long 0x621c00
-		.long 0x081ee
-		.long 0x6a1c00
-		.long 0x0a1ee
-		.long 0x731c00
-		.long 0x0c2ee
-		.long 0x7b1c00
-		.long 0x0e2ee
-		.long 0x831c00
-		.long 0x000f6
-		.long 0x8b1c00
-		.long 0x020f6
-		.long 0x941c00
-		.long 0x040f6
-		.long 0x9c1c00
-		.long 0x061f6
-		.long 0xa41c00
-		.long 0x081f6
-		.long 0xac1c00
-		.long 0x0a1f6
-		.long 0xb41c00
-		.long 0x0c2f6
-		.long 0xbd1c00
-		.long 0x0e2f6
-		.long 0xc51c00
-		.long 0x000ff
-		.long 0xcd1c00
-		.long 0x020ff
-		.long 0xd51c00
-		.long 0x040ff
-		.long 0xde1c00
-		.long 0x061ff
-		.long 0xe61c00
-		.long 0x081ff
-		.long 0xee1c00
-		.long 0x0a1ff
-		.long 0xf61c00
-		.long 0x0c2ff
-		.long 0xff1c00
-		.long 0x0e2ff
+                .long 0x00000
+                .long 0x00000
+                .long 0x80000
+                .long 0x02000
+                .long 0x100000
+                .long 0x04000
+                .long 0x180000
+                .long 0x06100
+                .long 0x200000
+                .long 0x08100
+                .long 0x290000
+                .long 0x0a100
+                .long 0x310000
+                .long 0x0c200
+                .long 0x390000
+                .long 0x0e200
+                .long 0x410000
+                .long 0x00008
+                .long 0x4a0000
+                .long 0x02008
+                .long 0x520000
+                .long 0x04008
+                .long 0x5a0000
+                .long 0x06108
+                .long 0x620000
+                .long 0x08108
+                .long 0x6a0000
+                .long 0x0a108
+                .long 0x730000
+                .long 0x0c208
+                .long 0x7b0000
+                .long 0x0e208
+                .long 0x830000
+                .long 0x00010
+                .long 0x8b0000
+                .long 0x02010
+                .long 0x940000
+                .long 0x04010
+                .long 0x9c0000
+                .long 0x06110
+                .long 0xa40000
+                .long 0x08110
+                .long 0xac0000
+                .long 0x0a110
+                .long 0xb40000
+                .long 0x0c210
+                .long 0xbd0000
+                .long 0x0e210
+                .long 0xc50000
+                .long 0x00018
+                .long 0xcd0000
+                .long 0x02018
+                .long 0xd50000
+                .long 0x04018
+                .long 0xde0000
+                .long 0x06118
+                .long 0xe60000
+                .long 0x08118
+                .long 0xee0000
+                .long 0x0a118
+                .long 0xf60000
+                .long 0x0c218
+                .long 0xff0000
+                .long 0x0e218
+                .long 0x00400
+                .long 0x00020
+                .long 0x80400
+                .long 0x02020
+                .long 0x100400
+                .long 0x04020
+                .long 0x180400
+                .long 0x06120
+                .long 0x200400
+                .long 0x08120
+                .long 0x290400
+                .long 0x0a120
+                .long 0x310400
+                .long 0x0c220
+                .long 0x390400
+                .long 0x0e220
+                .long 0x410400
+                .long 0x00029
+                .long 0x4a0400
+                .long 0x02029
+                .long 0x520400
+                .long 0x04029
+                .long 0x5a0400
+                .long 0x06129
+                .long 0x620400
+                .long 0x08129
+                .long 0x6a0400
+                .long 0x0a129
+                .long 0x730400
+                .long 0x0c229
+                .long 0x7b0400
+                .long 0x0e229
+                .long 0x830400
+                .long 0x00031
+                .long 0x8b0400
+                .long 0x02031
+                .long 0x940400
+                .long 0x04031
+                .long 0x9c0400
+                .long 0x06131
+                .long 0xa40400
+                .long 0x08131
+                .long 0xac0400
+                .long 0x0a131
+                .long 0xb40400
+                .long 0x0c231
+                .long 0xbd0400
+                .long 0x0e231
+                .long 0xc50400
+                .long 0x00039
+                .long 0xcd0400
+                .long 0x02039
+                .long 0xd50400
+                .long 0x04039
+                .long 0xde0400
+                .long 0x06139
+                .long 0xe60400
+                .long 0x08139
+                .long 0xee0400
+                .long 0x0a139
+                .long 0xf60400
+                .long 0x0c239
+                .long 0xff0400
+                .long 0x0e239
+                .long 0x00800
+                .long 0x00041
+                .long 0x80800
+                .long 0x02041
+                .long 0x100800
+                .long 0x04041
+                .long 0x180800
+                .long 0x06141
+                .long 0x200800
+                .long 0x08141
+                .long 0x290800
+                .long 0x0a141
+                .long 0x310800
+                .long 0x0c241
+                .long 0x390800
+                .long 0x0e241
+                .long 0x410800
+                .long 0x0004a
+                .long 0x4a0800
+                .long 0x0204a
+                .long 0x520800
+                .long 0x0404a
+                .long 0x5a0800
+                .long 0x0614a
+                .long 0x620800
+                .long 0x0814a
+                .long 0x6a0800
+                .long 0x0a14a
+                .long 0x730800
+                .long 0x0c24a
+                .long 0x7b0800
+                .long 0x0e24a
+                .long 0x830800
+                .long 0x00052
+                .long 0x8b0800
+                .long 0x02052
+                .long 0x940800
+                .long 0x04052
+                .long 0x9c0800
+                .long 0x06152
+                .long 0xa40800
+                .long 0x08152
+                .long 0xac0800
+                .long 0x0a152
+                .long 0xb40800
+                .long 0x0c252
+                .long 0xbd0800
+                .long 0x0e252
+                .long 0xc50800
+                .long 0x0005a
+                .long 0xcd0800
+                .long 0x0205a
+                .long 0xd50800
+                .long 0x0405a
+                .long 0xde0800
+                .long 0x0615a
+                .long 0xe60800
+                .long 0x0815a
+                .long 0xee0800
+                .long 0x0a15a
+                .long 0xf60800
+                .long 0x0c25a
+                .long 0xff0800
+                .long 0x0e25a
+                .long 0x00c00
+                .long 0x00062
+                .long 0x80c00
+                .long 0x02062
+                .long 0x100c00
+                .long 0x04062
+                .long 0x180c00
+                .long 0x06162
+                .long 0x200c00
+                .long 0x08162
+                .long 0x290c00
+                .long 0x0a162
+                .long 0x310c00
+                .long 0x0c262
+                .long 0x390c00
+                .long 0x0e262
+                .long 0x410c00
+                .long 0x0006a
+                .long 0x4a0c00
+                .long 0x0206a
+                .long 0x520c00
+                .long 0x0406a
+                .long 0x5a0c00
+                .long 0x0616a
+                .long 0x620c00
+                .long 0x0816a
+                .long 0x6a0c00
+                .long 0x0a16a
+                .long 0x730c00
+                .long 0x0c26a
+                .long 0x7b0c00
+                .long 0x0e26a
+                .long 0x830c00
+                .long 0x00073
+                .long 0x8b0c00
+                .long 0x02073
+                .long 0x940c00
+                .long 0x04073
+                .long 0x9c0c00
+                .long 0x06173
+                .long 0xa40c00
+                .long 0x08173
+                .long 0xac0c00
+                .long 0x0a173
+                .long 0xb40c00
+                .long 0x0c273
+                .long 0xbd0c00
+                .long 0x0e273
+                .long 0xc50c00
+                .long 0x0007b
+                .long 0xcd0c00
+                .long 0x0207b
+                .long 0xd50c00
+                .long 0x0407b
+                .long 0xde0c00
+                .long 0x0617b
+                .long 0xe60c00
+                .long 0x0817b
+                .long 0xee0c00
+                .long 0x0a17b
+                .long 0xf60c00
+                .long 0x0c27b
+                .long 0xff0c00
+                .long 0x0e27b
+                .long 0x01000
+                .long 0x00083
+                .long 0x81000
+                .long 0x02083
+                .long 0x101000
+                .long 0x04083
+                .long 0x181000
+                .long 0x06183
+                .long 0x201000
+                .long 0x08183
+                .long 0x291000
+                .long 0x0a183
+                .long 0x311000
+                .long 0x0c283
+                .long 0x391000
+                .long 0x0e283
+                .long 0x411000
+                .long 0x0008b
+                .long 0x4a1000
+                .long 0x0208b
+                .long 0x521000
+                .long 0x0408b
+                .long 0x5a1000
+                .long 0x0618b
+                .long 0x621000
+                .long 0x0818b
+                .long 0x6a1000
+                .long 0x0a18b
+                .long 0x731000
+                .long 0x0c28b
+                .long 0x7b1000
+                .long 0x0e28b
+                .long 0x831000
+                .long 0x00094
+                .long 0x8b1000
+                .long 0x02094
+                .long 0x941000
+                .long 0x04094
+                .long 0x9c1000
+                .long 0x06194
+                .long 0xa41000
+                .long 0x08194
+                .long 0xac1000
+                .long 0x0a194
+                .long 0xb41000
+                .long 0x0c294
+                .long 0xbd1000
+                .long 0x0e294
+                .long 0xc51000
+                .long 0x0009c
+                .long 0xcd1000
+                .long 0x0209c
+                .long 0xd51000
+                .long 0x0409c
+                .long 0xde1000
+                .long 0x0619c
+                .long 0xe61000
+                .long 0x0819c
+                .long 0xee1000
+                .long 0x0a19c
+                .long 0xf61000
+                .long 0x0c29c
+                .long 0xff1000
+                .long 0x0e29c
+                .long 0x01400
+                .long 0x000a4
+                .long 0x81400
+                .long 0x020a4
+                .long 0x101400
+                .long 0x040a4
+                .long 0x181400
+                .long 0x061a4
+                .long 0x201400
+                .long 0x081a4
+                .long 0x291400
+                .long 0x0a1a4
+                .long 0x311400
+                .long 0x0c2a4
+                .long 0x391400
+                .long 0x0e2a4
+                .long 0x411400
+                .long 0x000ac
+                .long 0x4a1400
+                .long 0x020ac
+                .long 0x521400
+                .long 0x040ac
+                .long 0x5a1400
+                .long 0x061ac
+                .long 0x621400
+                .long 0x081ac
+                .long 0x6a1400
+                .long 0x0a1ac
+                .long 0x731400
+                .long 0x0c2ac
+                .long 0x7b1400
+                .long 0x0e2ac
+                .long 0x831400
+                .long 0x000b4
+                .long 0x8b1400
+                .long 0x020b4
+                .long 0x941400
+                .long 0x040b4
+                .long 0x9c1400
+                .long 0x061b4
+                .long 0xa41400
+                .long 0x081b4
+                .long 0xac1400
+                .long 0x0a1b4
+                .long 0xb41400
+                .long 0x0c2b4
+                .long 0xbd1400
+                .long 0x0e2b4
+                .long 0xc51400
+                .long 0x000bd
+                .long 0xcd1400
+                .long 0x020bd
+                .long 0xd51400
+                .long 0x040bd
+                .long 0xde1400
+                .long 0x061bd
+                .long 0xe61400
+                .long 0x081bd
+                .long 0xee1400
+                .long 0x0a1bd
+                .long 0xf61400
+                .long 0x0c2bd
+                .long 0xff1400
+                .long 0x0e2bd
+                .long 0x01800
+                .long 0x000c5
+                .long 0x81800
+                .long 0x020c5
+                .long 0x101800
+                .long 0x040c5
+                .long 0x181800
+                .long 0x061c5
+                .long 0x201800
+                .long 0x081c5
+                .long 0x291800
+                .long 0x0a1c5
+                .long 0x311800
+                .long 0x0c2c5
+                .long 0x391800
+                .long 0x0e2c5
+                .long 0x411800
+                .long 0x000cd
+                .long 0x4a1800
+                .long 0x020cd
+                .long 0x521800
+                .long 0x040cd
+                .long 0x5a1800
+                .long 0x061cd
+                .long 0x621800
+                .long 0x081cd
+                .long 0x6a1800
+                .long 0x0a1cd
+                .long 0x731800
+                .long 0x0c2cd
+                .long 0x7b1800
+                .long 0x0e2cd
+                .long 0x831800
+                .long 0x000d5
+                .long 0x8b1800
+                .long 0x020d5
+                .long 0x941800
+                .long 0x040d5
+                .long 0x9c1800
+                .long 0x061d5
+                .long 0xa41800
+                .long 0x081d5
+                .long 0xac1800
+                .long 0x0a1d5
+                .long 0xb41800
+                .long 0x0c2d5
+                .long 0xbd1800
+                .long 0x0e2d5
+                .long 0xc51800
+                .long 0x000de
+                .long 0xcd1800
+                .long 0x020de
+                .long 0xd51800
+                .long 0x040de
+                .long 0xde1800
+                .long 0x061de
+                .long 0xe61800
+                .long 0x081de
+                .long 0xee1800
+                .long 0x0a1de
+                .long 0xf61800
+                .long 0x0c2de
+                .long 0xff1800
+                .long 0x0e2de
+                .long 0x01c00
+                .long 0x000e6
+                .long 0x81c00
+                .long 0x020e6
+                .long 0x101c00
+                .long 0x040e6
+                .long 0x181c00
+                .long 0x061e6
+                .long 0x201c00
+                .long 0x081e6
+                .long 0x291c00
+                .long 0x0a1e6
+                .long 0x311c00
+                .long 0x0c2e6
+                .long 0x391c00
+                .long 0x0e2e6
+                .long 0x411c00
+                .long 0x000ee
+                .long 0x4a1c00
+                .long 0x020ee
+                .long 0x521c00
+                .long 0x040ee
+                .long 0x5a1c00
+                .long 0x061ee
+                .long 0x621c00
+                .long 0x081ee
+                .long 0x6a1c00
+                .long 0x0a1ee
+                .long 0x731c00
+                .long 0x0c2ee
+                .long 0x7b1c00
+                .long 0x0e2ee
+                .long 0x831c00
+                .long 0x000f6
+                .long 0x8b1c00
+                .long 0x020f6
+                .long 0x941c00
+                .long 0x040f6
+                .long 0x9c1c00
+                .long 0x061f6
+                .long 0xa41c00
+                .long 0x081f6
+                .long 0xac1c00
+                .long 0x0a1f6
+                .long 0xb41c00
+                .long 0x0c2f6
+                .long 0xbd1c00
+                .long 0x0e2f6
+                .long 0xc51c00
+                .long 0x000ff
+                .long 0xcd1c00
+                .long 0x020ff
+                .long 0xd51c00
+                .long 0x040ff
+                .long 0xde1c00
+                .long 0x061ff
+                .long 0xe61c00
+                .long 0x081ff
+                .long 0xee1c00
+                .long 0x0a1ff
+                .long 0xf61c00
+                .long 0x0c2ff
+                .long 0xff1c00
+                .long 0x0e2ff
 
 _ConvertX86p16_32RGBA888_LUT_X86:
-		.long 0x00000
-		.long 0x000ff
-		.long 0x00800
-		.long 0x2000ff
-		.long 0x01000
-		.long 0x4000ff
-		.long 0x01800
-		.long 0x6100ff
-		.long 0x02000
-		.long 0x8100ff
-		.long 0x02900
-		.long 0xa100ff
-		.long 0x03100
-		.long 0xc200ff
-		.long 0x03900
-		.long 0xe200ff
-		.long 0x04100
-		.long 0x80000ff
-		.long 0x04a00
-		.long 0x82000ff
-		.long 0x05200
-		.long 0x84000ff
-		.long 0x05a00
-		.long 0x86100ff
-		.long 0x06200
-		.long 0x88100ff
-		.long 0x06a00
-		.long 0x8a100ff
-		.long 0x07300
-		.long 0x8c200ff
-		.long 0x07b00
-		.long 0x8e200ff
-		.long 0x08300
-		.long 0x100000ff
-		.long 0x08b00
-		.long 0x102000ff
-		.long 0x09400
-		.long 0x104000ff
-		.long 0x09c00
-		.long 0x106100ff
-		.long 0x0a400
-		.long 0x108100ff
-		.long 0x0ac00
-		.long 0x10a100ff
-		.long 0x0b400
-		.long 0x10c200ff
-		.long 0x0bd00
-		.long 0x10e200ff
-		.long 0x0c500
-		.long 0x180000ff
-		.long 0x0cd00
-		.long 0x182000ff
-		.long 0x0d500
-		.long 0x184000ff
-		.long 0x0de00
-		.long 0x186100ff
-		.long 0x0e600
-		.long 0x188100ff
-		.long 0x0ee00
-		.long 0x18a100ff
-		.long 0x0f600
-		.long 0x18c200ff
-		.long 0x0ff00
-		.long 0x18e200ff
-		.long 0x40000
-		.long 0x200000ff
-		.long 0x40800
-		.long 0x202000ff
-		.long 0x41000
-		.long 0x204000ff
-		.long 0x41800
-		.long 0x206100ff
-		.long 0x42000
-		.long 0x208100ff
-		.long 0x42900
-		.long 0x20a100ff
-		.long 0x43100
-		.long 0x20c200ff
-		.long 0x43900
-		.long 0x20e200ff
-		.long 0x44100
-		.long 0x290000ff
-		.long 0x44a00
-		.long 0x292000ff
-		.long 0x45200
-		.long 0x294000ff
-		.long 0x45a00
-		.long 0x296100ff
-		.long 0x46200
-		.long 0x298100ff
-		.long 0x46a00
-		.long 0x29a100ff
-		.long 0x47300
-		.long 0x29c200ff
-		.long 0x47b00
-		.long 0x29e200ff
-		.long 0x48300
-		.long 0x310000ff
-		.long 0x48b00
-		.long 0x312000ff
-		.long 0x49400
-		.long 0x314000ff
-		.long 0x49c00
-		.long 0x316100ff
-		.long 0x4a400
-		.long 0x318100ff
-		.long 0x4ac00
-		.long 0x31a100ff
-		.long 0x4b400
-		.long 0x31c200ff
-		.long 0x4bd00
-		.long 0x31e200ff
-		.long 0x4c500
-		.long 0x390000ff
-		.long 0x4cd00
-		.long 0x392000ff
-		.long 0x4d500
-		.long 0x394000ff
-		.long 0x4de00
-		.long 0x396100ff
-		.long 0x4e600
-		.long 0x398100ff
-		.long 0x4ee00
-		.long 0x39a100ff
-		.long 0x4f600
-		.long 0x39c200ff
-		.long 0x4ff00
-		.long 0x39e200ff
-		.long 0x80000
-		.long 0x410000ff
-		.long 0x80800
-		.long 0x412000ff
-		.long 0x81000
-		.long 0x414000ff
-		.long 0x81800
-		.long 0x416100ff
-		.long 0x82000
-		.long 0x418100ff
-		.long 0x82900
-		.long 0x41a100ff
-		.long 0x83100
-		.long 0x41c200ff
-		.long 0x83900
-		.long 0x41e200ff
-		.long 0x84100
-		.long 0x4a0000ff
-		.long 0x84a00
-		.long 0x4a2000ff
-		.long 0x85200
-		.long 0x4a4000ff
-		.long 0x85a00
-		.long 0x4a6100ff
-		.long 0x86200
-		.long 0x4a8100ff
-		.long 0x86a00
-		.long 0x4aa100ff
-		.long 0x87300
-		.long 0x4ac200ff
-		.long 0x87b00
-		.long 0x4ae200ff
-		.long 0x88300
-		.long 0x520000ff
-		.long 0x88b00
-		.long 0x522000ff
-		.long 0x89400
-		.long 0x524000ff
-		.long 0x89c00
-		.long 0x526100ff
-		.long 0x8a400
-		.long 0x528100ff
-		.long 0x8ac00
-		.long 0x52a100ff
-		.long 0x8b400
-		.long 0x52c200ff
-		.long 0x8bd00
-		.long 0x52e200ff
-		.long 0x8c500
-		.long 0x5a0000ff
-		.long 0x8cd00
-		.long 0x5a2000ff
-		.long 0x8d500
-		.long 0x5a4000ff
-		.long 0x8de00
-		.long 0x5a6100ff
-		.long 0x8e600
-		.long 0x5a8100ff
-		.long 0x8ee00
-		.long 0x5aa100ff
-		.long 0x8f600
-		.long 0x5ac200ff
-		.long 0x8ff00
-		.long 0x5ae200ff
-		.long 0xc0000
-		.long 0x620000ff
-		.long 0xc0800
-		.long 0x622000ff
-		.long 0xc1000
-		.long 0x624000ff
-		.long 0xc1800
-		.long 0x626100ff
-		.long 0xc2000
-		.long 0x628100ff
-		.long 0xc2900
-		.long 0x62a100ff
-		.long 0xc3100
-		.long 0x62c200ff
-		.long 0xc3900
-		.long 0x62e200ff
-		.long 0xc4100
-		.long 0x6a0000ff
-		.long 0xc4a00
-		.long 0x6a2000ff
-		.long 0xc5200
-		.long 0x6a4000ff
-		.long 0xc5a00
-		.long 0x6a6100ff
-		.long 0xc6200
-		.long 0x6a8100ff
-		.long 0xc6a00
-		.long 0x6aa100ff
-		.long 0xc7300
-		.long 0x6ac200ff
-		.long 0xc7b00
-		.long 0x6ae200ff
-		.long 0xc8300
-		.long 0x730000ff
-		.long 0xc8b00
-		.long 0x732000ff
-		.long 0xc9400
-		.long 0x734000ff
-		.long 0xc9c00
-		.long 0x736100ff
-		.long 0xca400
-		.long 0x738100ff
-		.long 0xcac00
-		.long 0x73a100ff
-		.long 0xcb400
-		.long 0x73c200ff
-		.long 0xcbd00
-		.long 0x73e200ff
-		.long 0xcc500
-		.long 0x7b0000ff
-		.long 0xccd00
-		.long 0x7b2000ff
-		.long 0xcd500
-		.long 0x7b4000ff
-		.long 0xcde00
-		.long 0x7b6100ff
-		.long 0xce600
-		.long 0x7b8100ff
-		.long 0xcee00
-		.long 0x7ba100ff
-		.long 0xcf600
-		.long 0x7bc200ff
-		.long 0xcff00
-		.long 0x7be200ff
-		.long 0x100000
-		.long 0x830000ff
-		.long 0x100800
-		.long 0x832000ff
-		.long 0x101000
-		.long 0x834000ff
-		.long 0x101800
-		.long 0x836100ff
-		.long 0x102000
-		.long 0x838100ff
-		.long 0x102900
-		.long 0x83a100ff
-		.long 0x103100
-		.long 0x83c200ff
-		.long 0x103900
-		.long 0x83e200ff
-		.long 0x104100
-		.long 0x8b0000ff
-		.long 0x104a00
-		.long 0x8b2000ff
-		.long 0x105200
-		.long 0x8b4000ff
-		.long 0x105a00
-		.long 0x8b6100ff
-		.long 0x106200
-		.long 0x8b8100ff
-		.long 0x106a00
-		.long 0x8ba100ff
-		.long 0x107300
-		.long 0x8bc200ff
-		.long 0x107b00
-		.long 0x8be200ff
-		.long 0x108300
-		.long 0x940000ff
-		.long 0x108b00
-		.long 0x942000ff
-		.long 0x109400
-		.long 0x944000ff
-		.long 0x109c00
-		.long 0x946100ff
-		.long 0x10a400
-		.long 0x948100ff
-		.long 0x10ac00
-		.long 0x94a100ff
-		.long 0x10b400
-		.long 0x94c200ff
-		.long 0x10bd00
-		.long 0x94e200ff
-		.long 0x10c500
-		.long 0x9c0000ff
-		.long 0x10cd00
-		.long 0x9c2000ff
-		.long 0x10d500
-		.long 0x9c4000ff
-		.long 0x10de00
-		.long 0x9c6100ff
-		.long 0x10e600
-		.long 0x9c8100ff
-		.long 0x10ee00
-		.long 0x9ca100ff
-		.long 0x10f600
-		.long 0x9cc200ff
-		.long 0x10ff00
-		.long 0x9ce200ff
-		.long 0x140000
-		.long 0xa40000ff
-		.long 0x140800
-		.long 0xa42000ff
-		.long 0x141000
-		.long 0xa44000ff
-		.long 0x141800
-		.long 0xa46100ff
-		.long 0x142000
-		.long 0xa48100ff
-		.long 0x142900
-		.long 0xa4a100ff
-		.long 0x143100
-		.long 0xa4c200ff
-		.long 0x143900
-		.long 0xa4e200ff
-		.long 0x144100
-		.long 0xac0000ff
-		.long 0x144a00
-		.long 0xac2000ff
-		.long 0x145200
-		.long 0xac4000ff
-		.long 0x145a00
-		.long 0xac6100ff
-		.long 0x146200
-		.long 0xac8100ff
-		.long 0x146a00
-		.long 0xaca100ff
-		.long 0x147300
-		.long 0xacc200ff
-		.long 0x147b00
-		.long 0xace200ff
-		.long 0x148300
-		.long 0xb40000ff
-		.long 0x148b00
-		.long 0xb42000ff
-		.long 0x149400
-		.long 0xb44000ff
-		.long 0x149c00
-		.long 0xb46100ff
-		.long 0x14a400
-		.long 0xb48100ff
-		.long 0x14ac00
-		.long 0xb4a100ff
-		.long 0x14b400
-		.long 0xb4c200ff
-		.long 0x14bd00
-		.long 0xb4e200ff
-		.long 0x14c500
-		.long 0xbd0000ff
-		.long 0x14cd00
-		.long 0xbd2000ff
-		.long 0x14d500
-		.long 0xbd4000ff
-		.long 0x14de00
-		.long 0xbd6100ff
-		.long 0x14e600
-		.long 0xbd8100ff
-		.long 0x14ee00
-		.long 0xbda100ff
-		.long 0x14f600
-		.long 0xbdc200ff
-		.long 0x14ff00
-		.long 0xbde200ff
-		.long 0x180000
-		.long 0xc50000ff
-		.long 0x180800
-		.long 0xc52000ff
-		.long 0x181000
-		.long 0xc54000ff
-		.long 0x181800
-		.long 0xc56100ff
-		.long 0x182000
-		.long 0xc58100ff
-		.long 0x182900
-		.long 0xc5a100ff
-		.long 0x183100
-		.long 0xc5c200ff
-		.long 0x183900
-		.long 0xc5e200ff
-		.long 0x184100
-		.long 0xcd0000ff
-		.long 0x184a00
-		.long 0xcd2000ff
-		.long 0x185200
-		.long 0xcd4000ff
-		.long 0x185a00
-		.long 0xcd6100ff
-		.long 0x186200
-		.long 0xcd8100ff
-		.long 0x186a00
-		.long 0xcda100ff
-		.long 0x187300
-		.long 0xcdc200ff
-		.long 0x187b00
-		.long 0xcde200ff
-		.long 0x188300
-		.long 0xd50000ff
-		.long 0x188b00
-		.long 0xd52000ff
-		.long 0x189400
-		.long 0xd54000ff
-		.long 0x189c00
-		.long 0xd56100ff
-		.long 0x18a400
-		.long 0xd58100ff
-		.long 0x18ac00
-		.long 0xd5a100ff
-		.long 0x18b400
-		.long 0xd5c200ff
-		.long 0x18bd00
-		.long 0xd5e200ff
-		.long 0x18c500
-		.long 0xde0000ff
-		.long 0x18cd00
-		.long 0xde2000ff
-		.long 0x18d500
-		.long 0xde4000ff
-		.long 0x18de00
-		.long 0xde6100ff
-		.long 0x18e600
-		.long 0xde8100ff
-		.long 0x18ee00
-		.long 0xdea100ff
-		.long 0x18f600
-		.long 0xdec200ff
-		.long 0x18ff00
-		.long 0xdee200ff
-		.long 0x1c0000
-		.long 0xe60000ff
-		.long 0x1c0800
-		.long 0xe62000ff
-		.long 0x1c1000
-		.long 0xe64000ff
-		.long 0x1c1800
-		.long 0xe66100ff
-		.long 0x1c2000
-		.long 0xe68100ff
-		.long 0x1c2900
-		.long 0xe6a100ff
-		.long 0x1c3100
-		.long 0xe6c200ff
-		.long 0x1c3900
-		.long 0xe6e200ff
-		.long 0x1c4100
-		.long 0xee0000ff
-		.long 0x1c4a00
-		.long 0xee2000ff
-		.long 0x1c5200
-		.long 0xee4000ff
-		.long 0x1c5a00
-		.long 0xee6100ff
-		.long 0x1c6200
-		.long 0xee8100ff
-		.long 0x1c6a00
-		.long 0xeea100ff
-		.long 0x1c7300
-		.long 0xeec200ff
-		.long 0x1c7b00
-		.long 0xeee200ff
-		.long 0x1c8300
-		.long 0xf60000ff
-		.long 0x1c8b00
-		.long 0xf62000ff
-		.long 0x1c9400
-		.long 0xf64000ff
-		.long 0x1c9c00
-		.long 0xf66100ff
-		.long 0x1ca400
-		.long 0xf68100ff
-		.long 0x1cac00
-		.long 0xf6a100ff
-		.long 0x1cb400
-		.long 0xf6c200ff
-		.long 0x1cbd00
-		.long 0xf6e200ff
-		.long 0x1cc500
-		.long 0xff0000ff
-		.long 0x1ccd00
-		.long 0xff2000ff
-		.long 0x1cd500
-		.long 0xff4000ff
-		.long 0x1cde00
-		.long 0xff6100ff
-		.long 0x1ce600
-		.long 0xff8100ff
-		.long 0x1cee00
-		.long 0xffa100ff
-		.long 0x1cf600
-		.long 0xffc200ff
-		.long 0x1cff00
-		.long 0xffe200ff
+                .long 0x00000
+                .long 0x000ff
+                .long 0x00800
+                .long 0x2000ff
+                .long 0x01000
+                .long 0x4000ff
+                .long 0x01800
+                .long 0x6100ff
+                .long 0x02000
+                .long 0x8100ff
+                .long 0x02900
+                .long 0xa100ff
+                .long 0x03100
+                .long 0xc200ff
+                .long 0x03900
+                .long 0xe200ff
+                .long 0x04100
+                .long 0x80000ff
+                .long 0x04a00
+                .long 0x82000ff
+                .long 0x05200
+                .long 0x84000ff
+                .long 0x05a00
+                .long 0x86100ff
+                .long 0x06200
+                .long 0x88100ff
+                .long 0x06a00
+                .long 0x8a100ff
+                .long 0x07300
+                .long 0x8c200ff
+                .long 0x07b00
+                .long 0x8e200ff
+                .long 0x08300
+                .long 0x100000ff
+                .long 0x08b00
+                .long 0x102000ff
+                .long 0x09400
+                .long 0x104000ff
+                .long 0x09c00
+                .long 0x106100ff
+                .long 0x0a400
+                .long 0x108100ff
+                .long 0x0ac00
+                .long 0x10a100ff
+                .long 0x0b400
+                .long 0x10c200ff
+                .long 0x0bd00
+                .long 0x10e200ff
+                .long 0x0c500
+                .long 0x180000ff
+                .long 0x0cd00
+                .long 0x182000ff
+                .long 0x0d500
+                .long 0x184000ff
+                .long 0x0de00
+                .long 0x186100ff
+                .long 0x0e600
+                .long 0x188100ff
+                .long 0x0ee00
+                .long 0x18a100ff
+                .long 0x0f600
+                .long 0x18c200ff
+                .long 0x0ff00
+                .long 0x18e200ff
+                .long 0x40000
+                .long 0x200000ff
+                .long 0x40800
+                .long 0x202000ff
+                .long 0x41000
+                .long 0x204000ff
+                .long 0x41800
+                .long 0x206100ff
+                .long 0x42000
+                .long 0x208100ff
+                .long 0x42900
+                .long 0x20a100ff
+                .long 0x43100
+                .long 0x20c200ff
+                .long 0x43900
+                .long 0x20e200ff
+                .long 0x44100
+                .long 0x290000ff
+                .long 0x44a00
+                .long 0x292000ff
+                .long 0x45200
+                .long 0x294000ff
+                .long 0x45a00
+                .long 0x296100ff
+                .long 0x46200
+                .long 0x298100ff
+                .long 0x46a00
+                .long 0x29a100ff
+                .long 0x47300
+                .long 0x29c200ff
+                .long 0x47b00
+                .long 0x29e200ff
+                .long 0x48300
+                .long 0x310000ff
+                .long 0x48b00
+                .long 0x312000ff
+                .long 0x49400
+                .long 0x314000ff
+                .long 0x49c00
+                .long 0x316100ff
+                .long 0x4a400
+                .long 0x318100ff
+                .long 0x4ac00
+                .long 0x31a100ff
+                .long 0x4b400
+                .long 0x31c200ff
+                .long 0x4bd00
+                .long 0x31e200ff
+                .long 0x4c500
+                .long 0x390000ff
+                .long 0x4cd00
+                .long 0x392000ff
+                .long 0x4d500
+                .long 0x394000ff
+                .long 0x4de00
+                .long 0x396100ff
+                .long 0x4e600
+                .long 0x398100ff
+                .long 0x4ee00
+                .long 0x39a100ff
+                .long 0x4f600
+                .long 0x39c200ff
+                .long 0x4ff00
+                .long 0x39e200ff
+                .long 0x80000
+                .long 0x410000ff
+                .long 0x80800
+                .long 0x412000ff
+                .long 0x81000
+                .long 0x414000ff
+                .long 0x81800
+                .long 0x416100ff
+                .long 0x82000
+                .long 0x418100ff
+                .long 0x82900
+                .long 0x41a100ff
+                .long 0x83100
+                .long 0x41c200ff
+                .long 0x83900
+                .long 0x41e200ff
+                .long 0x84100
+                .long 0x4a0000ff
+                .long 0x84a00
+                .long 0x4a2000ff
+                .long 0x85200
+                .long 0x4a4000ff
+                .long 0x85a00
+                .long 0x4a6100ff
+                .long 0x86200
+                .long 0x4a8100ff
+                .long 0x86a00
+                .long 0x4aa100ff
+                .long 0x87300
+                .long 0x4ac200ff
+                .long 0x87b00
+                .long 0x4ae200ff
+                .long 0x88300
+                .long 0x520000ff
+                .long 0x88b00
+                .long 0x522000ff
+                .long 0x89400
+                .long 0x524000ff
+                .long 0x89c00
+                .long 0x526100ff
+                .long 0x8a400
+                .long 0x528100ff
+                .long 0x8ac00
+                .long 0x52a100ff
+                .long 0x8b400
+                .long 0x52c200ff
+                .long 0x8bd00
+                .long 0x52e200ff
+                .long 0x8c500
+                .long 0x5a0000ff
+                .long 0x8cd00
+                .long 0x5a2000ff
+                .long 0x8d500
+                .long 0x5a4000ff
+                .long 0x8de00
+                .long 0x5a6100ff
+                .long 0x8e600
+                .long 0x5a8100ff
+                .long 0x8ee00
+                .long 0x5aa100ff
+                .long 0x8f600
+                .long 0x5ac200ff
+                .long 0x8ff00
+                .long 0x5ae200ff
+                .long 0xc0000
+                .long 0x620000ff
+                .long 0xc0800
+                .long 0x622000ff
+                .long 0xc1000
+                .long 0x624000ff
+                .long 0xc1800
+                .long 0x626100ff
+                .long 0xc2000
+                .long 0x628100ff
+                .long 0xc2900
+                .long 0x62a100ff
+                .long 0xc3100
+                .long 0x62c200ff
+                .long 0xc3900
+                .long 0x62e200ff
+                .long 0xc4100
+                .long 0x6a0000ff
+                .long 0xc4a00
+                .long 0x6a2000ff
+                .long 0xc5200
+                .long 0x6a4000ff
+                .long 0xc5a00
+                .long 0x6a6100ff
+                .long 0xc6200
+                .long 0x6a8100ff
+                .long 0xc6a00
+                .long 0x6aa100ff
+                .long 0xc7300
+                .long 0x6ac200ff
+                .long 0xc7b00
+                .long 0x6ae200ff
+                .long 0xc8300
+                .long 0x730000ff
+                .long 0xc8b00
+                .long 0x732000ff
+                .long 0xc9400
+                .long 0x734000ff
+                .long 0xc9c00
+                .long 0x736100ff
+                .long 0xca400
+                .long 0x738100ff
+                .long 0xcac00
+                .long 0x73a100ff
+                .long 0xcb400
+                .long 0x73c200ff
+                .long 0xcbd00
+                .long 0x73e200ff
+                .long 0xcc500
+                .long 0x7b0000ff
+                .long 0xccd00
+                .long 0x7b2000ff
+                .long 0xcd500
+                .long 0x7b4000ff
+                .long 0xcde00
+                .long 0x7b6100ff
+                .long 0xce600
+                .long 0x7b8100ff
+                .long 0xcee00
+                .long 0x7ba100ff
+                .long 0xcf600
+                .long 0x7bc200ff
+                .long 0xcff00
+                .long 0x7be200ff
+                .long 0x100000
+                .long 0x830000ff
+                .long 0x100800
+                .long 0x832000ff
+                .long 0x101000
+                .long 0x834000ff
+                .long 0x101800
+                .long 0x836100ff
+                .long 0x102000
+                .long 0x838100ff
+                .long 0x102900
+                .long 0x83a100ff
+                .long 0x103100
+                .long 0x83c200ff
+                .long 0x103900
+                .long 0x83e200ff
+                .long 0x104100
+                .long 0x8b0000ff
+                .long 0x104a00
+                .long 0x8b2000ff
+                .long 0x105200
+                .long 0x8b4000ff
+                .long 0x105a00
+                .long 0x8b6100ff
+                .long 0x106200
+                .long 0x8b8100ff
+                .long 0x106a00
+                .long 0x8ba100ff
+                .long 0x107300
+                .long 0x8bc200ff
+                .long 0x107b00
+                .long 0x8be200ff
+                .long 0x108300
+                .long 0x940000ff
+                .long 0x108b00
+                .long 0x942000ff
+                .long 0x109400
+                .long 0x944000ff
+                .long 0x109c00
+                .long 0x946100ff
+                .long 0x10a400
+                .long 0x948100ff
+                .long 0x10ac00
+                .long 0x94a100ff
+                .long 0x10b400
+                .long 0x94c200ff
+                .long 0x10bd00
+                .long 0x94e200ff
+                .long 0x10c500
+                .long 0x9c0000ff
+                .long 0x10cd00
+                .long 0x9c2000ff
+                .long 0x10d500
+                .long 0x9c4000ff
+                .long 0x10de00
+                .long 0x9c6100ff
+                .long 0x10e600
+                .long 0x9c8100ff
+                .long 0x10ee00
+                .long 0x9ca100ff
+                .long 0x10f600
+                .long 0x9cc200ff
+                .long 0x10ff00
+                .long 0x9ce200ff
+                .long 0x140000
+                .long 0xa40000ff
+                .long 0x140800
+                .long 0xa42000ff
+                .long 0x141000
+                .long 0xa44000ff
+                .long 0x141800
+                .long 0xa46100ff
+                .long 0x142000
+                .long 0xa48100ff
+                .long 0x142900
+                .long 0xa4a100ff
+                .long 0x143100
+                .long 0xa4c200ff
+                .long 0x143900
+                .long 0xa4e200ff
+                .long 0x144100
+                .long 0xac0000ff
+                .long 0x144a00
+                .long 0xac2000ff
+                .long 0x145200
+                .long 0xac4000ff
+                .long 0x145a00
+                .long 0xac6100ff
+                .long 0x146200
+                .long 0xac8100ff
+                .long 0x146a00
+                .long 0xaca100ff
+                .long 0x147300
+                .long 0xacc200ff
+                .long 0x147b00
+                .long 0xace200ff
+                .long 0x148300
+                .long 0xb40000ff
+                .long 0x148b00
+                .long 0xb42000ff
+                .long 0x149400
+                .long 0xb44000ff
+                .long 0x149c00
+                .long 0xb46100ff
+                .long 0x14a400
+                .long 0xb48100ff
+                .long 0x14ac00
+                .long 0xb4a100ff
+                .long 0x14b400
+                .long 0xb4c200ff
+                .long 0x14bd00
+                .long 0xb4e200ff
+                .long 0x14c500
+                .long 0xbd0000ff
+                .long 0x14cd00
+                .long 0xbd2000ff
+                .long 0x14d500
+                .long 0xbd4000ff
+                .long 0x14de00
+                .long 0xbd6100ff
+                .long 0x14e600
+                .long 0xbd8100ff
+                .long 0x14ee00
+                .long 0xbda100ff
+                .long 0x14f600
+                .long 0xbdc200ff
+                .long 0x14ff00
+                .long 0xbde200ff
+                .long 0x180000
+                .long 0xc50000ff
+                .long 0x180800
+                .long 0xc52000ff
+                .long 0x181000
+                .long 0xc54000ff
+                .long 0x181800
+                .long 0xc56100ff
+                .long 0x182000
+                .long 0xc58100ff
+                .long 0x182900
+                .long 0xc5a100ff
+                .long 0x183100
+                .long 0xc5c200ff
+                .long 0x183900
+                .long 0xc5e200ff
+                .long 0x184100
+                .long 0xcd0000ff
+                .long 0x184a00
+                .long 0xcd2000ff
+                .long 0x185200
+                .long 0xcd4000ff
+                .long 0x185a00
+                .long 0xcd6100ff
+                .long 0x186200
+                .long 0xcd8100ff
+                .long 0x186a00
+                .long 0xcda100ff
+                .long 0x187300
+                .long 0xcdc200ff
+                .long 0x187b00
+                .long 0xcde200ff
+                .long 0x188300
+                .long 0xd50000ff
+                .long 0x188b00
+                .long 0xd52000ff
+                .long 0x189400
+                .long 0xd54000ff
+                .long 0x189c00
+                .long 0xd56100ff
+                .long 0x18a400
+                .long 0xd58100ff
+                .long 0x18ac00
+                .long 0xd5a100ff
+                .long 0x18b400
+                .long 0xd5c200ff
+                .long 0x18bd00
+                .long 0xd5e200ff
+                .long 0x18c500
+                .long 0xde0000ff
+                .long 0x18cd00
+                .long 0xde2000ff
+                .long 0x18d500
+                .long 0xde4000ff
+                .long 0x18de00
+                .long 0xde6100ff
+                .long 0x18e600
+                .long 0xde8100ff
+                .long 0x18ee00
+                .long 0xdea100ff
+                .long 0x18f600
+                .long 0xdec200ff
+                .long 0x18ff00
+                .long 0xdee200ff
+                .long 0x1c0000
+                .long 0xe60000ff
+                .long 0x1c0800
+                .long 0xe62000ff
+                .long 0x1c1000
+                .long 0xe64000ff
+                .long 0x1c1800
+                .long 0xe66100ff
+                .long 0x1c2000
+                .long 0xe68100ff
+                .long 0x1c2900
+                .long 0xe6a100ff
+                .long 0x1c3100
+                .long 0xe6c200ff
+                .long 0x1c3900
+                .long 0xe6e200ff
+                .long 0x1c4100
+                .long 0xee0000ff
+                .long 0x1c4a00
+                .long 0xee2000ff
+                .long 0x1c5200
+                .long 0xee4000ff
+                .long 0x1c5a00
+                .long 0xee6100ff
+                .long 0x1c6200
+                .long 0xee8100ff
+                .long 0x1c6a00
+                .long 0xeea100ff
+                .long 0x1c7300
+                .long 0xeec200ff
+                .long 0x1c7b00
+                .long 0xeee200ff
+                .long 0x1c8300
+                .long 0xf60000ff
+                .long 0x1c8b00
+                .long 0xf62000ff
+                .long 0x1c9400
+                .long 0xf64000ff
+                .long 0x1c9c00
+                .long 0xf66100ff
+                .long 0x1ca400
+                .long 0xf68100ff
+                .long 0x1cac00
+                .long 0xf6a100ff
+                .long 0x1cb400
+                .long 0xf6c200ff
+                .long 0x1cbd00
+                .long 0xf6e200ff
+                .long 0x1cc500
+                .long 0xff0000ff
+                .long 0x1ccd00
+                .long 0xff2000ff
+                .long 0x1cd500
+                .long 0xff4000ff
+                .long 0x1cde00
+                .long 0xff6100ff
+                .long 0x1ce600
+                .long 0xff8100ff
+                .long 0x1cee00
+                .long 0xffa100ff
+                .long 0x1cf600
+                .long 0xffc200ff
+                .long 0x1cff00
+                .long 0xffe200ff
 
 _ConvertX86p16_32BGRA888_LUT_X86:
-		.long 0x00000
-		.long 0x000ff
-		.long 0x8000000
-		.long 0x2000ff
-		.long 0x10000000
-		.long 0x4000ff
-		.long 0x18000000
-		.long 0x6100ff
-		.long 0x20000000
-		.long 0x8100ff
-		.long 0x29000000
-		.long 0xa100ff
-		.long 0x31000000
-		.long 0xc200ff
-		.long 0x39000000
-		.long 0xe200ff
-		.long 0x41000000
-		.long 0x008ff
-		.long 0x4a000000
-		.long 0x2008ff
-		.long 0x52000000
-		.long 0x4008ff
-		.long 0x5a000000
-		.long 0x6108ff
-		.long 0x62000000
-		.long 0x8108ff
-		.long 0x6a000000
-		.long 0xa108ff
-		.long 0x73000000
-		.long 0xc208ff
-		.long 0x7b000000
-		.long 0xe208ff
-		.long 0x83000000
-		.long 0x010ff
-		.long 0x8b000000
-		.long 0x2010ff
-		.long 0x94000000
-		.long 0x4010ff
-		.long 0x9c000000
-		.long 0x6110ff
-		.long 0xa4000000
-		.long 0x8110ff
-		.long 0xac000000
-		.long 0xa110ff
-		.long 0xb4000000
-		.long 0xc210ff
-		.long 0xbd000000
-		.long 0xe210ff
-		.long 0xc5000000
-		.long 0x018ff
-		.long 0xcd000000
-		.long 0x2018ff
-		.long 0xd5000000
-		.long 0x4018ff
-		.long 0xde000000
-		.long 0x6118ff
-		.long 0xe6000000
-		.long 0x8118ff
-		.long 0xee000000
-		.long 0xa118ff
-		.long 0xf6000000
-		.long 0xc218ff
-		.long 0xff000000
-		.long 0xe218ff
-		.long 0x40000
-		.long 0x020ff
-		.long 0x8040000
-		.long 0x2020ff
-		.long 0x10040000
-		.long 0x4020ff
-		.long 0x18040000
-		.long 0x6120ff
-		.long 0x20040000
-		.long 0x8120ff
-		.long 0x29040000
-		.long 0xa120ff
-		.long 0x31040000
-		.long 0xc220ff
-		.long 0x39040000
-		.long 0xe220ff
-		.long 0x41040000
-		.long 0x029ff
-		.long 0x4a040000
-		.long 0x2029ff
-		.long 0x52040000
-		.long 0x4029ff
-		.long 0x5a040000
-		.long 0x6129ff
-		.long 0x62040000
-		.long 0x8129ff
-		.long 0x6a040000
-		.long 0xa129ff
-		.long 0x73040000
-		.long 0xc229ff
-		.long 0x7b040000
-		.long 0xe229ff
-		.long 0x83040000
-		.long 0x031ff
-		.long 0x8b040000
-		.long 0x2031ff
-		.long 0x94040000
-		.long 0x4031ff
-		.long 0x9c040000
-		.long 0x6131ff
-		.long 0xa4040000
-		.long 0x8131ff
-		.long 0xac040000
-		.long 0xa131ff
-		.long 0xb4040000
-		.long 0xc231ff
-		.long 0xbd040000
-		.long 0xe231ff
-		.long 0xc5040000
-		.long 0x039ff
-		.long 0xcd040000
-		.long 0x2039ff
-		.long 0xd5040000
-		.long 0x4039ff
-		.long 0xde040000
-		.long 0x6139ff
-		.long 0xe6040000
-		.long 0x8139ff
-		.long 0xee040000
-		.long 0xa139ff
-		.long 0xf6040000
-		.long 0xc239ff
-		.long 0xff040000
-		.long 0xe239ff
-		.long 0x80000
-		.long 0x041ff
-		.long 0x8080000
-		.long 0x2041ff
-		.long 0x10080000
-		.long 0x4041ff
-		.long 0x18080000
-		.long 0x6141ff
-		.long 0x20080000
-		.long 0x8141ff
-		.long 0x29080000
-		.long 0xa141ff
-		.long 0x31080000
-		.long 0xc241ff
-		.long 0x39080000
-		.long 0xe241ff
-		.long 0x41080000
-		.long 0x04aff
-		.long 0x4a080000
-		.long 0x204aff
-		.long 0x52080000
-		.long 0x404aff
-		.long 0x5a080000
-		.long 0x614aff
-		.long 0x62080000
-		.long 0x814aff
-		.long 0x6a080000
-		.long 0xa14aff
-		.long 0x73080000
-		.long 0xc24aff
-		.long 0x7b080000
-		.long 0xe24aff
-		.long 0x83080000
-		.long 0x052ff
-		.long 0x8b080000
-		.long 0x2052ff
-		.long 0x94080000
-		.long 0x4052ff
-		.long 0x9c080000
-		.long 0x6152ff
-		.long 0xa4080000
-		.long 0x8152ff
-		.long 0xac080000
-		.long 0xa152ff
-		.long 0xb4080000
-		.long 0xc252ff
-		.long 0xbd080000
-		.long 0xe252ff
-		.long 0xc5080000
-		.long 0x05aff
-		.long 0xcd080000
-		.long 0x205aff
-		.long 0xd5080000
-		.long 0x405aff
-		.long 0xde080000
-		.long 0x615aff
-		.long 0xe6080000
-		.long 0x815aff
-		.long 0xee080000
-		.long 0xa15aff
-		.long 0xf6080000
-		.long 0xc25aff
-		.long 0xff080000
-		.long 0xe25aff
-		.long 0xc0000
-		.long 0x062ff
-		.long 0x80c0000
-		.long 0x2062ff
-		.long 0x100c0000
-		.long 0x4062ff
-		.long 0x180c0000
-		.long 0x6162ff
-		.long 0x200c0000
-		.long 0x8162ff
-		.long 0x290c0000
-		.long 0xa162ff
-		.long 0x310c0000
-		.long 0xc262ff
-		.long 0x390c0000
-		.long 0xe262ff
-		.long 0x410c0000
-		.long 0x06aff
-		.long 0x4a0c0000
-		.long 0x206aff
-		.long 0x520c0000
-		.long 0x406aff
-		.long 0x5a0c0000
-		.long 0x616aff
-		.long 0x620c0000
-		.long 0x816aff
-		.long 0x6a0c0000
-		.long 0xa16aff
-		.long 0x730c0000
-		.long 0xc26aff
-		.long 0x7b0c0000
-		.long 0xe26aff
-		.long 0x830c0000
-		.long 0x073ff
-		.long 0x8b0c0000
-		.long 0x2073ff
-		.long 0x940c0000
-		.long 0x4073ff
-		.long 0x9c0c0000
-		.long 0x6173ff
-		.long 0xa40c0000
-		.long 0x8173ff
-		.long 0xac0c0000
-		.long 0xa173ff
-		.long 0xb40c0000
-		.long 0xc273ff
-		.long 0xbd0c0000
-		.long 0xe273ff
-		.long 0xc50c0000
-		.long 0x07bff
-		.long 0xcd0c0000
-		.long 0x207bff
-		.long 0xd50c0000
-		.long 0x407bff
-		.long 0xde0c0000
-		.long 0x617bff
-		.long 0xe60c0000
-		.long 0x817bff
-		.long 0xee0c0000
-		.long 0xa17bff
-		.long 0xf60c0000
-		.long 0xc27bff
-		.long 0xff0c0000
-		.long 0xe27bff
-		.long 0x100000
-		.long 0x083ff
-		.long 0x8100000
-		.long 0x2083ff
-		.long 0x10100000
-		.long 0x4083ff
-		.long 0x18100000
-		.long 0x6183ff
-		.long 0x20100000
-		.long 0x8183ff
-		.long 0x29100000
-		.long 0xa183ff
-		.long 0x31100000
-		.long 0xc283ff
-		.long 0x39100000
-		.long 0xe283ff
-		.long 0x41100000
-		.long 0x08bff
-		.long 0x4a100000
-		.long 0x208bff
-		.long 0x52100000
-		.long 0x408bff
-		.long 0x5a100000
-		.long 0x618bff
-		.long 0x62100000
-		.long 0x818bff
-		.long 0x6a100000
-		.long 0xa18bff
-		.long 0x73100000
-		.long 0xc28bff
-		.long 0x7b100000
-		.long 0xe28bff
-		.long 0x83100000
-		.long 0x094ff
-		.long 0x8b100000
-		.long 0x2094ff
-		.long 0x94100000
-		.long 0x4094ff
-		.long 0x9c100000
-		.long 0x6194ff
-		.long 0xa4100000
-		.long 0x8194ff
-		.long 0xac100000
-		.long 0xa194ff
-		.long 0xb4100000
-		.long 0xc294ff
-		.long 0xbd100000
-		.long 0xe294ff
-		.long 0xc5100000
-		.long 0x09cff
-		.long 0xcd100000
-		.long 0x209cff
-		.long 0xd5100000
-		.long 0x409cff
-		.long 0xde100000
-		.long 0x619cff
-		.long 0xe6100000
-		.long 0x819cff
-		.long 0xee100000
-		.long 0xa19cff
-		.long 0xf6100000
-		.long 0xc29cff
-		.long 0xff100000
-		.long 0xe29cff
-		.long 0x140000
-		.long 0x0a4ff
-		.long 0x8140000
-		.long 0x20a4ff
-		.long 0x10140000
-		.long 0x40a4ff
-		.long 0x18140000
-		.long 0x61a4ff
-		.long 0x20140000
-		.long 0x81a4ff
-		.long 0x29140000
-		.long 0xa1a4ff
-		.long 0x31140000
-		.long 0xc2a4ff
-		.long 0x39140000
-		.long 0xe2a4ff
-		.long 0x41140000
-		.long 0x0acff
-		.long 0x4a140000
-		.long 0x20acff
-		.long 0x52140000
-		.long 0x40acff
-		.long 0x5a140000
-		.long 0x61acff
-		.long 0x62140000
-		.long 0x81acff
-		.long 0x6a140000
-		.long 0xa1acff
-		.long 0x73140000
-		.long 0xc2acff
-		.long 0x7b140000
-		.long 0xe2acff
-		.long 0x83140000
-		.long 0x0b4ff
-		.long 0x8b140000
-		.long 0x20b4ff
-		.long 0x94140000
-		.long 0x40b4ff
-		.long 0x9c140000
-		.long 0x61b4ff
-		.long 0xa4140000
-		.long 0x81b4ff
-		.long 0xac140000
-		.long 0xa1b4ff
-		.long 0xb4140000
-		.long 0xc2b4ff
-		.long 0xbd140000
-		.long 0xe2b4ff
-		.long 0xc5140000
-		.long 0x0bdff
-		.long 0xcd140000
-		.long 0x20bdff
-		.long 0xd5140000
-		.long 0x40bdff
-		.long 0xde140000
-		.long 0x61bdff
-		.long 0xe6140000
-		.long 0x81bdff
-		.long 0xee140000
-		.long 0xa1bdff
-		.long 0xf6140000
-		.long 0xc2bdff
-		.long 0xff140000
-		.long 0xe2bdff
-		.long 0x180000
-		.long 0x0c5ff
-		.long 0x8180000
-		.long 0x20c5ff
-		.long 0x10180000
-		.long 0x40c5ff
-		.long 0x18180000
-		.long 0x61c5ff
-		.long 0x20180000
-		.long 0x81c5ff
-		.long 0x29180000
-		.long 0xa1c5ff
-		.long 0x31180000
-		.long 0xc2c5ff
-		.long 0x39180000
-		.long 0xe2c5ff
-		.long 0x41180000
-		.long 0x0cdff
-		.long 0x4a180000
-		.long 0x20cdff
-		.long 0x52180000
-		.long 0x40cdff
-		.long 0x5a180000
-		.long 0x61cdff
-		.long 0x62180000
-		.long 0x81cdff
-		.long 0x6a180000
-		.long 0xa1cdff
-		.long 0x73180000
-		.long 0xc2cdff
-		.long 0x7b180000
-		.long 0xe2cdff
-		.long 0x83180000
-		.long 0x0d5ff
-		.long 0x8b180000
-		.long 0x20d5ff
-		.long 0x94180000
-		.long 0x40d5ff
-		.long 0x9c180000
-		.long 0x61d5ff
-		.long 0xa4180000
-		.long 0x81d5ff
-		.long 0xac180000
-		.long 0xa1d5ff
-		.long 0xb4180000
-		.long 0xc2d5ff
-		.long 0xbd180000
-		.long 0xe2d5ff
-		.long 0xc5180000
-		.long 0x0deff
-		.long 0xcd180000
-		.long 0x20deff
-		.long 0xd5180000
-		.long 0x40deff
-		.long 0xde180000
-		.long 0x61deff
-		.long 0xe6180000
-		.long 0x81deff
-		.long 0xee180000
-		.long 0xa1deff
-		.long 0xf6180000
-		.long 0xc2deff
-		.long 0xff180000
-		.long 0xe2deff
-		.long 0x1c0000
-		.long 0x0e6ff
-		.long 0x81c0000
-		.long 0x20e6ff
-		.long 0x101c0000
-		.long 0x40e6ff
-		.long 0x181c0000
-		.long 0x61e6ff
-		.long 0x201c0000
-		.long 0x81e6ff
-		.long 0x291c0000
-		.long 0xa1e6ff
-		.long 0x311c0000
-		.long 0xc2e6ff
-		.long 0x391c0000
-		.long 0xe2e6ff
-		.long 0x411c0000
-		.long 0x0eeff
-		.long 0x4a1c0000
-		.long 0x20eeff
-		.long 0x521c0000
-		.long 0x40eeff
-		.long 0x5a1c0000
-		.long 0x61eeff
-		.long 0x621c0000
-		.long 0x81eeff
-		.long 0x6a1c0000
-		.long 0xa1eeff
-		.long 0x731c0000
-		.long 0xc2eeff
-		.long 0x7b1c0000
-		.long 0xe2eeff
-		.long 0x831c0000
-		.long 0x0f6ff
-		.long 0x8b1c0000
-		.long 0x20f6ff
-		.long 0x941c0000
-		.long 0x40f6ff
-		.long 0x9c1c0000
-		.long 0x61f6ff
-		.long 0xa41c0000
-		.long 0x81f6ff
-		.long 0xac1c0000
-		.long 0xa1f6ff
-		.long 0xb41c0000
-		.long 0xc2f6ff
-		.long 0xbd1c0000
-		.long 0xe2f6ff
-		.long 0xc51c0000
-		.long 0x0ffff
-		.long 0xcd1c0000
-		.long 0x20ffff
-		.long 0xd51c0000
-		.long 0x40ffff
-		.long 0xde1c0000
-		.long 0x61ffff
-		.long 0xe61c0000
-		.long 0x81ffff
-		.long 0xee1c0000
-		.long 0xa1ffff
-		.long 0xf61c0000
-		.long 0xc2ffff
-		.long 0xff1c0000
-		.long 0xe2ffff
+                .long 0x00000
+                .long 0x000ff
+                .long 0x8000000
+                .long 0x2000ff
+                .long 0x10000000
+                .long 0x4000ff
+                .long 0x18000000
+                .long 0x6100ff
+                .long 0x20000000
+                .long 0x8100ff
+                .long 0x29000000
+                .long 0xa100ff
+                .long 0x31000000
+                .long 0xc200ff
+                .long 0x39000000
+                .long 0xe200ff
+                .long 0x41000000
+                .long 0x008ff
+                .long 0x4a000000
+                .long 0x2008ff
+                .long 0x52000000
+                .long 0x4008ff
+                .long 0x5a000000
+                .long 0x6108ff
+                .long 0x62000000
+                .long 0x8108ff
+                .long 0x6a000000
+                .long 0xa108ff
+                .long 0x73000000
+                .long 0xc208ff
+                .long 0x7b000000
+                .long 0xe208ff
+                .long 0x83000000
+                .long 0x010ff
+                .long 0x8b000000
+                .long 0x2010ff
+                .long 0x94000000
+                .long 0x4010ff
+                .long 0x9c000000
+                .long 0x6110ff
+                .long 0xa4000000
+                .long 0x8110ff
+                .long 0xac000000
+                .long 0xa110ff
+                .long 0xb4000000
+                .long 0xc210ff
+                .long 0xbd000000
+                .long 0xe210ff
+                .long 0xc5000000
+                .long 0x018ff
+                .long 0xcd000000
+                .long 0x2018ff
+                .long 0xd5000000
+                .long 0x4018ff
+                .long 0xde000000
+                .long 0x6118ff
+                .long 0xe6000000
+                .long 0x8118ff
+                .long 0xee000000
+                .long 0xa118ff
+                .long 0xf6000000
+                .long 0xc218ff
+                .long 0xff000000
+                .long 0xe218ff
+                .long 0x40000
+                .long 0x020ff
+                .long 0x8040000
+                .long 0x2020ff
+                .long 0x10040000
+                .long 0x4020ff
+                .long 0x18040000
+                .long 0x6120ff
+                .long 0x20040000
+                .long 0x8120ff
+                .long 0x29040000
+                .long 0xa120ff
+                .long 0x31040000
+                .long 0xc220ff
+                .long 0x39040000
+                .long 0xe220ff
+                .long 0x41040000
+                .long 0x029ff
+                .long 0x4a040000
+                .long 0x2029ff
+                .long 0x52040000
+                .long 0x4029ff
+                .long 0x5a040000
+                .long 0x6129ff
+                .long 0x62040000
+                .long 0x8129ff
+                .long 0x6a040000
+                .long 0xa129ff
+                .long 0x73040000
+                .long 0xc229ff
+                .long 0x7b040000
+                .long 0xe229ff
+                .long 0x83040000
+                .long 0x031ff
+                .long 0x8b040000
+                .long 0x2031ff
+                .long 0x94040000
+                .long 0x4031ff
+                .long 0x9c040000
+                .long 0x6131ff
+                .long 0xa4040000
+                .long 0x8131ff
+                .long 0xac040000
+                .long 0xa131ff
+                .long 0xb4040000
+                .long 0xc231ff
+                .long 0xbd040000
+                .long 0xe231ff
+                .long 0xc5040000
+                .long 0x039ff
+                .long 0xcd040000
+                .long 0x2039ff
+                .long 0xd5040000
+                .long 0x4039ff
+                .long 0xde040000
+                .long 0x6139ff
+                .long 0xe6040000
+                .long 0x8139ff
+                .long 0xee040000
+                .long 0xa139ff
+                .long 0xf6040000
+                .long 0xc239ff
+                .long 0xff040000
+                .long 0xe239ff
+                .long 0x80000
+                .long 0x041ff
+                .long 0x8080000
+                .long 0x2041ff
+                .long 0x10080000
+                .long 0x4041ff
+                .long 0x18080000
+                .long 0x6141ff
+                .long 0x20080000
+                .long 0x8141ff
+                .long 0x29080000
+                .long 0xa141ff
+                .long 0x31080000
+                .long 0xc241ff
+                .long 0x39080000
+                .long 0xe241ff
+                .long 0x41080000
+                .long 0x04aff
+                .long 0x4a080000
+                .long 0x204aff
+                .long 0x52080000
+                .long 0x404aff
+                .long 0x5a080000
+                .long 0x614aff
+                .long 0x62080000
+                .long 0x814aff
+                .long 0x6a080000
+                .long 0xa14aff
+                .long 0x73080000
+                .long 0xc24aff
+                .long 0x7b080000
+                .long 0xe24aff
+                .long 0x83080000
+                .long 0x052ff
+                .long 0x8b080000
+                .long 0x2052ff
+                .long 0x94080000
+                .long 0x4052ff
+                .long 0x9c080000
+                .long 0x6152ff
+                .long 0xa4080000
+                .long 0x8152ff
+                .long 0xac080000
+                .long 0xa152ff
+                .long 0xb4080000
+                .long 0xc252ff
+                .long 0xbd080000
+                .long 0xe252ff
+                .long 0xc5080000
+                .long 0x05aff
+                .long 0xcd080000
+                .long 0x205aff
+                .long 0xd5080000
+                .long 0x405aff
+                .long 0xde080000
+                .long 0x615aff
+                .long 0xe6080000
+                .long 0x815aff
+                .long 0xee080000
+                .long 0xa15aff
+                .long 0xf6080000
+                .long 0xc25aff
+                .long 0xff080000
+                .long 0xe25aff
+                .long 0xc0000
+                .long 0x062ff
+                .long 0x80c0000
+                .long 0x2062ff
+                .long 0x100c0000
+                .long 0x4062ff
+                .long 0x180c0000
+                .long 0x6162ff
+                .long 0x200c0000
+                .long 0x8162ff
+                .long 0x290c0000
+                .long 0xa162ff
+                .long 0x310c0000
+                .long 0xc262ff
+                .long 0x390c0000
+                .long 0xe262ff
+                .long 0x410c0000
+                .long 0x06aff
+                .long 0x4a0c0000
+                .long 0x206aff
+                .long 0x520c0000
+                .long 0x406aff
+                .long 0x5a0c0000
+                .long 0x616aff
+                .long 0x620c0000
+                .long 0x816aff
+                .long 0x6a0c0000
+                .long 0xa16aff
+                .long 0x730c0000
+                .long 0xc26aff
+                .long 0x7b0c0000
+                .long 0xe26aff
+                .long 0x830c0000
+                .long 0x073ff
+                .long 0x8b0c0000
+                .long 0x2073ff
+                .long 0x940c0000
+                .long 0x4073ff
+                .long 0x9c0c0000
+                .long 0x6173ff
+                .long 0xa40c0000
+                .long 0x8173ff
+                .long 0xac0c0000
+                .long 0xa173ff
+                .long 0xb40c0000
+                .long 0xc273ff
+                .long 0xbd0c0000
+                .long 0xe273ff
+                .long 0xc50c0000
+                .long 0x07bff
+                .long 0xcd0c0000
+                .long 0x207bff
+                .long 0xd50c0000
+                .long 0x407bff
+                .long 0xde0c0000
+                .long 0x617bff
+                .long 0xe60c0000
+                .long 0x817bff
+                .long 0xee0c0000
+                .long 0xa17bff
+                .long 0xf60c0000
+                .long 0xc27bff
+                .long 0xff0c0000
+                .long 0xe27bff
+                .long 0x100000
+                .long 0x083ff
+                .long 0x8100000
+                .long 0x2083ff
+                .long 0x10100000
+                .long 0x4083ff
+                .long 0x18100000
+                .long 0x6183ff
+                .long 0x20100000
+                .long 0x8183ff
+                .long 0x29100000
+                .long 0xa183ff
+                .long 0x31100000
+                .long 0xc283ff
+                .long 0x39100000
+                .long 0xe283ff
+                .long 0x41100000
+                .long 0x08bff
+                .long 0x4a100000
+                .long 0x208bff
+                .long 0x52100000
+                .long 0x408bff
+                .long 0x5a100000
+                .long 0x618bff
+                .long 0x62100000
+                .long 0x818bff
+                .long 0x6a100000
+                .long 0xa18bff
+                .long 0x73100000
+                .long 0xc28bff
+                .long 0x7b100000
+                .long 0xe28bff
+                .long 0x83100000
+                .long 0x094ff
+                .long 0x8b100000
+                .long 0x2094ff
+                .long 0x94100000
+                .long 0x4094ff
+                .long 0x9c100000
+                .long 0x6194ff
+                .long 0xa4100000
+                .long 0x8194ff
+                .long 0xac100000
+                .long 0xa194ff
+                .long 0xb4100000
+                .long 0xc294ff
+                .long 0xbd100000
+                .long 0xe294ff
+                .long 0xc5100000
+                .long 0x09cff
+                .long 0xcd100000
+                .long 0x209cff
+                .long 0xd5100000
+                .long 0x409cff
+                .long 0xde100000
+                .long 0x619cff
+                .long 0xe6100000
+                .long 0x819cff
+                .long 0xee100000
+                .long 0xa19cff
+                .long 0xf6100000
+                .long 0xc29cff
+                .long 0xff100000
+                .long 0xe29cff
+                .long 0x140000
+                .long 0x0a4ff
+                .long 0x8140000
+                .long 0x20a4ff
+                .long 0x10140000
+                .long 0x40a4ff
+                .long 0x18140000
+                .long 0x61a4ff
+                .long 0x20140000
+                .long 0x81a4ff
+                .long 0x29140000
+                .long 0xa1a4ff
+                .long 0x31140000
+                .long 0xc2a4ff
+                .long 0x39140000
+                .long 0xe2a4ff
+                .long 0x41140000
+                .long 0x0acff
+                .long 0x4a140000
+                .long 0x20acff
+                .long 0x52140000
+                .long 0x40acff
+                .long 0x5a140000
+                .long 0x61acff
+                .long 0x62140000
+                .long 0x81acff
+                .long 0x6a140000
+                .long 0xa1acff
+                .long 0x73140000
+                .long 0xc2acff
+                .long 0x7b140000
+                .long 0xe2acff
+                .long 0x83140000
+                .long 0x0b4ff
+                .long 0x8b140000
+                .long 0x20b4ff
+                .long 0x94140000
+                .long 0x40b4ff
+                .long 0x9c140000
+                .long 0x61b4ff
+                .long 0xa4140000
+                .long 0x81b4ff
+                .long 0xac140000
+                .long 0xa1b4ff
+                .long 0xb4140000
+                .long 0xc2b4ff
+                .long 0xbd140000
+                .long 0xe2b4ff
+                .long 0xc5140000
+                .long 0x0bdff
+                .long 0xcd140000
+                .long 0x20bdff
+                .long 0xd5140000
+                .long 0x40bdff
+                .long 0xde140000
+                .long 0x61bdff
+                .long 0xe6140000
+                .long 0x81bdff
+                .long 0xee140000
+                .long 0xa1bdff
+                .long 0xf6140000
+                .long 0xc2bdff
+                .long 0xff140000
+                .long 0xe2bdff
+                .long 0x180000
+                .long 0x0c5ff
+                .long 0x8180000
+                .long 0x20c5ff
+                .long 0x10180000
+                .long 0x40c5ff
+                .long 0x18180000
+                .long 0x61c5ff
+                .long 0x20180000
+                .long 0x81c5ff
+                .long 0x29180000
+                .long 0xa1c5ff
+                .long 0x31180000
+                .long 0xc2c5ff
+                .long 0x39180000
+                .long 0xe2c5ff
+                .long 0x41180000
+                .long 0x0cdff
+                .long 0x4a180000
+                .long 0x20cdff
+                .long 0x52180000
+                .long 0x40cdff
+                .long 0x5a180000
+                .long 0x61cdff
+                .long 0x62180000
+                .long 0x81cdff
+                .long 0x6a180000
+                .long 0xa1cdff
+                .long 0x73180000
+                .long 0xc2cdff
+                .long 0x7b180000
+                .long 0xe2cdff
+                .long 0x83180000
+                .long 0x0d5ff
+                .long 0x8b180000
+                .long 0x20d5ff
+                .long 0x94180000
+                .long 0x40d5ff
+                .long 0x9c180000
+                .long 0x61d5ff
+                .long 0xa4180000
+                .long 0x81d5ff
+                .long 0xac180000
+                .long 0xa1d5ff
+                .long 0xb4180000
+                .long 0xc2d5ff
+                .long 0xbd180000
+                .long 0xe2d5ff
+                .long 0xc5180000
+                .long 0x0deff
+                .long 0xcd180000
+                .long 0x20deff
+                .long 0xd5180000
+                .long 0x40deff
+                .long 0xde180000
+                .long 0x61deff
+                .long 0xe6180000
+                .long 0x81deff
+                .long 0xee180000
+                .long 0xa1deff
+                .long 0xf6180000
+                .long 0xc2deff
+                .long 0xff180000
+                .long 0xe2deff
+                .long 0x1c0000
+                .long 0x0e6ff
+                .long 0x81c0000
+                .long 0x20e6ff
+                .long 0x101c0000
+                .long 0x40e6ff
+                .long 0x181c0000
+                .long 0x61e6ff
+                .long 0x201c0000
+                .long 0x81e6ff
+                .long 0x291c0000
+                .long 0xa1e6ff
+                .long 0x311c0000
+                .long 0xc2e6ff
+                .long 0x391c0000
+                .long 0xe2e6ff
+                .long 0x411c0000
+                .long 0x0eeff
+                .long 0x4a1c0000
+                .long 0x20eeff
+                .long 0x521c0000
+                .long 0x40eeff
+                .long 0x5a1c0000
+                .long 0x61eeff
+                .long 0x621c0000
+                .long 0x81eeff
+                .long 0x6a1c0000
+                .long 0xa1eeff
+                .long 0x731c0000
+                .long 0xc2eeff
+                .long 0x7b1c0000
+                .long 0xe2eeff
+                .long 0x831c0000
+                .long 0x0f6ff
+                .long 0x8b1c0000
+                .long 0x20f6ff
+                .long 0x941c0000
+                .long 0x40f6ff
+                .long 0x9c1c0000
+                .long 0x61f6ff
+                .long 0xa41c0000
+                .long 0x81f6ff
+                .long 0xac1c0000
+                .long 0xa1f6ff
+                .long 0xb41c0000
+                .long 0xc2f6ff
+                .long 0xbd1c0000
+                .long 0xe2f6ff
+                .long 0xc51c0000
+                .long 0x0ffff
+                .long 0xcd1c0000
+                .long 0x20ffff
+                .long 0xd51c0000
+                .long 0x40ffff
+                .long 0xde1c0000
+                .long 0x61ffff
+                .long 0xe61c0000
+                .long 0x81ffff
+                .long 0xee1c0000
+                .long 0xa1ffff
+                .long 0xf61c0000
+                .long 0xc2ffff
+                .long 0xff1c0000
+                .long 0xe2ffff
 

+ 24 - 24
packages/hermes/src/i386/x86_clr.as

@@ -2,7 +2,7 @@
 # x86 surface clear routines for HERMES
 # Copyright (c) 1998 Christian Nentwich ([email protected])
 # This source code is licensed under the GNU LGPL
-# 
+#
 # Please refer to the file COPYING.LIB contained in the distribution for
 # licensing conditions
 #
@@ -18,7 +18,7 @@
 
 .text
 
-##   
+##
 ## --------------------------------------------------------------------------
 ## HermesClearInterface (ebp+..)
 ##   0: char8 *dest
@@ -28,18 +28,18 @@
 ##  16: int add
 
 .align 8
-_ClearX86_32: 
+_ClearX86_32:
         pushl %ebp
         movl %esp,%ebp
 
         movl 8(%ebp),%ebp
 
         movl (%ebp),%edi        # destination
-        movl 4(%ebp),%eax       # pixel value   
+        movl 4(%ebp),%eax       # pixel value
 
         movl 12(%ebp),%edx      # height
 .align 4
-_ClearX86_32.L_y: 
+_ClearX86_32.L_y:
         movl 8(%ebp),%ecx
         rep
  stosl
@@ -54,20 +54,20 @@ _ClearX86_32.L_y:
 
 
 
-_ClearX86_24: 
+_ClearX86_24:
         ret
 
 
 
 .align 8
-_ClearX86_16: 
+_ClearX86_16:
         pushl %ebp
         movl %esp,%ebp
 
         movl 8(%ebp),%ebp
 
         movl (%ebp),%edi        # destination
-        movl 4(%ebp),%eax       # pixel value   
+        movl 4(%ebp),%eax       # pixel value
 
         movl 12(%ebp),%edx      # height
         movl %eax,%ebx
@@ -76,7 +76,7 @@ _ClearX86_16:
         andl $0x0ffff,%ebx
 
         orl %ebx,%eax
-_ClearX86_16.L_y: 
+_ClearX86_16.L_y:
         movl 8(%ebp),%ecx
 
         testl $3,%edi           # Check if destination is aligned mod 4
@@ -88,7 +88,7 @@ _ClearX86_16.L_y:
         decl %ecx
         jz _ClearX86_16.L_endline
 
-_ClearX86_16.L_aligned: 
+_ClearX86_16.L_aligned:
         shrl %ecx
 
 rep
@@ -99,7 +99,7 @@ rep
         movw %ax,(%edi)
         addl $2,%edi
 
-_ClearX86_16.L_endline: 
+_ClearX86_16.L_endline:
         addl 16(%ebp),%edi
 
         decl %edx
@@ -111,13 +111,13 @@ _ClearX86_16.L_endline:
 
 
 .align 8
-_ClearX86_8: 
+_ClearX86_8:
         pushl %ebp
         movl %esp,%ebp
 
         movl 8(%ebp),%ebp
 
-        movl 4(%ebp),%eax       # pixel value           
+        movl 4(%ebp),%eax       # pixel value
         movl 12(%ebp),%edx      # height
 
         movb %al,%ah
@@ -135,7 +135,7 @@ _ClearX86_8:
         jbe _ClearX86_8.L_short_y
 
 .align 4
-_ClearX86_8.L_y: 
+_ClearX86_8.L_y:
         testl $3,%edi
         jz _ClearX86_8.L_aligned
 
@@ -148,7 +148,7 @@ _ClearX86_8.L_y:
         rep
  stosb
 
-_ClearX86_8.L_aligned: 
+_ClearX86_8.L_aligned:
         movl %ebx,%ecx
 
         shrl $2,%ecx
@@ -172,7 +172,7 @@ _ClearX86_8.L_aligned:
 
 ## Short loop
 .align 4
-_ClearX86_8.L_short_y: 
+_ClearX86_8.L_short_y:
         movl %ebx,%ecx
 
         rep
@@ -185,19 +185,19 @@ _ClearX86_8.L_short_y:
         popl %ebp
         ret
 
-## ClearX86_8 version 2,  
-## Im not sure wheather this is faster or not... 
+## ClearX86_8 version 2,
+## Im not sure wheather this is faster or not...
 ## too many jumps could confuse the CPU branch quessing
 
 
 .align 8
-_ClearX86_8_2: 
+_ClearX86_8_2:
         pushl %ebp
         movl %esp,%ebp
 
         movl 8(%ebp),%ebp
 
-        movl 4(%ebp),%eax       # pixel value           
+        movl 4(%ebp),%eax       # pixel value
         movl 12(%ebp),%edx      # height
 
         movb %al,%ah
@@ -216,7 +216,7 @@ _ClearX86_8_2:
 
 
 .align 4
-_ClearX86_8_2.L_y: 
+_ClearX86_8_2.L_y:
         testl $3,%edi
         jz _ClearX86_8_2.L_aligned
 
@@ -240,7 +240,7 @@ _ClearX86_8_2.L_y:
         movb %al,(%edi)
         incl %edi
 
-_ClearX86_8_2.L_aligned: 
+_ClearX86_8_2.L_aligned:
         movl %ebx,%ecx
 
         shrl $2,%ecx
@@ -271,7 +271,7 @@ _ClearX86_8_2.L_aligned:
         movb %al,(%edi)
         incl %edi
 
-_ClearX86_8_2.L_endline: 
+_ClearX86_8_2.L_endline:
         addl 16(%ebp),%edi
 
         decl %edx
@@ -283,7 +283,7 @@ _ClearX86_8_2.L_endline:
 
 ## Short loop
 .align 4
-_ClearX86_8_2.L_short_y: 
+_ClearX86_8_2.L_short_y:
         movl %ebx,%ecx
 
         rep

+ 11 - 11
packages/hermes/src/i386/x86_main.as

@@ -2,9 +2,9 @@
 # x86 format converters for HERMES
 # Some routines Copyright (c) 1998 Christian Nentwich ([email protected])
 # This source code is licensed under the GNU LGPL
-# 
+#
 # Please refer to the file COPYING.LIB contained in the distribution for
-# licensing conditions          
+# licensing conditions
 #
 
 
@@ -36,7 +36,7 @@ cpu_flags: .long 0
 .equ s_pitch, 40
 .equ d_pitch, 44
 
-## _ConvertX86:  
+## _ConvertX86:
 ## [ESP+8] ConverterInfo*
 ## --------------------------------------------------------------------------
 ##
@@ -45,7 +45,7 @@ cpu_flags: .long 0
 ##      - s_add for the x increment
 ## because they're unused anyway and this is thread safe.. (it's a per
 ## converter handle structure)
-_ConvertX86Stretch: 
+_ConvertX86Stretch:
         pushl %ebp
         movl %esp,%ebp
 
@@ -73,7 +73,7 @@ _ConvertX86Stretch:
         jmp *conv_func(%ebp)
 
 .align 8
-_x86return_S: 
+_x86return_S:
 
         decl d_height(%ebp)
         jz endconvert_S
@@ -98,14 +98,14 @@ _x86return_S:
 
         jmp *conv_func(%ebp)
 
-endconvert_S: 
+endconvert_S:
 
         popl %ebp
         ret
 
 
 
-_ConvertX86: 
+_ConvertX86:
         pushl %ebp
         movl %esp,%ebp
 
@@ -118,7 +118,7 @@ _ConvertX86:
         jmp *32(%ebp)
 
 .align 8
-_x86return: 
+_x86return:
         decl s_height(%ebp)
         jz endconvert
 
@@ -129,7 +129,7 @@ _x86return:
         jmp *32(%ebp)
 
 
-endconvert: 
+endconvert:
         popl %ebp
         ret
 
@@ -137,7 +137,7 @@ endconvert:
 
 ## Hermes_X86_CPU returns the CPUID flags in eax
 
-_Hermes_X86_CPU: 
+_Hermes_X86_CPU:
         pushfl
         popl %eax
 
@@ -178,5 +178,5 @@ _Hermes_X86_CPU:
 
         movl cpu_flags,%eax
 
-_Hermes_X86_CPU.L1: 
+_Hermes_X86_CPU.L1:
         ret

+ 32 - 32
packages/hermes/src/i386/x86p_16.as

@@ -2,13 +2,13 @@
 # x86 format converters for HERMES
 # Copyright (c) 1998 Glenn Fielder ([email protected])
 # This source code is licensed under the GNU LGPL
-# 
+#
 # Please refer to the file COPYING.LIB contained in the distribution for
-# licensing conditions          
-# 
+# licensing conditions
+#
 # Routines adjusted for Hermes by Christian Nentwich ([email protected])
 # Used with permission.
-# 
+#
 
 
 #BITS 32
@@ -38,7 +38,7 @@
 
 
 
-_ConvertX86p16_32RGB888: 
+_ConvertX86p16_32RGB888:
 
     # check short
     cmpl $32,%ecx
@@ -57,7 +57,7 @@ _ConvertX86p16_32RGB888.L1: movb (%esi),%bl             # ebx = lower byte pixel
     addl $4,%edi
     decl %ecx
     jnz _ConvertX86p16_32RGB888.L1
-_ConvertX86p16_32RGB888.L2: 
+_ConvertX86p16_32RGB888.L2:
     jmp _x86return
 
 
@@ -75,7 +75,7 @@ _ConvertX86p16_32RGB888.L3:  # save ebp
     leal (%esi,%ebp,4),%esi
     leal (%edi,%ebp,8),%edi
 
-    # negative counter 
+    # negative counter
     negl %ebp
 
     # clear
@@ -129,7 +129,7 @@ _ConvertX86p16_32RGB888.L6: popl %ebp
 
 
 
-_ConvertX86p16_32BGR888: 
+_ConvertX86p16_32BGR888:
 
     # check short
     cmpl $32,%ecx
@@ -148,7 +148,7 @@ _ConvertX86p16_32BGR888.L1: movb (%esi),%bl             # ebx = lower byte pixel
     addl $4,%edi
     decl %ecx
     jnz _ConvertX86p16_32BGR888.L1
-_ConvertX86p16_32BGR888.L2: 
+_ConvertX86p16_32BGR888.L2:
     jmp _x86return
 
 _ConvertX86p16_32BGR888.L3:  # save ebp
@@ -165,7 +165,7 @@ _ConvertX86p16_32BGR888.L3:  # save ebp
     leal (%esi,%ebp,4),%esi
     leal (%edi,%ebp,8),%edi
 
-    # negative counter 
+    # negative counter
     negl %ebp
 
     # clear
@@ -219,7 +219,7 @@ _ConvertX86p16_32BGR888.L6: popl %ebp
 
 
 
-_ConvertX86p16_32RGBA888: 
+_ConvertX86p16_32RGBA888:
 
     # check short
     cmpl $32,%ecx
@@ -238,7 +238,7 @@ _ConvertX86p16_32RGBA888.L1: movb (%esi),%bl             # ebx = lower byte pixe
     addl $4,%edi
     decl %ecx
     jnz _ConvertX86p16_32RGBA888.L1
-_ConvertX86p16_32RGBA888.L2: 
+_ConvertX86p16_32RGBA888.L2:
     jmp _x86return
 
 _ConvertX86p16_32RGBA888.L3:  # save ebp
@@ -255,7 +255,7 @@ _ConvertX86p16_32RGBA888.L3:  # save ebp
     leal (%esi,%ebp,4),%esi
     leal (%edi,%ebp,8),%edi
 
-    # negative counter 
+    # negative counter
     negl %ebp
 
     # clear
@@ -309,7 +309,7 @@ _ConvertX86p16_32RGBA888.L6: popl %ebp
 
 
 
-_ConvertX86p16_32BGRA888: 
+_ConvertX86p16_32BGRA888:
 
     # check short
     cmpl $32,%ecx
@@ -327,7 +327,7 @@ _ConvertX86p16_32BGRA888.L1: movb (%esi),%bl             # ebx = lower byte pixe
     addl $4,%edi
     decl %ecx
     jnz _ConvertX86p16_32BGRA888.L1
-_ConvertX86p16_32BGRA888.L2: 
+_ConvertX86p16_32BGRA888.L2:
     jmp _x86return
 
 _ConvertX86p16_32BGRA888.L3:  # save ebp
@@ -344,7 +344,7 @@ _ConvertX86p16_32BGRA888.L3:  # save ebp
     leal (%esi,%ebp,4),%esi
     leal (%edi,%ebp,8),%edi
 
-    # negative counter 
+    # negative counter
     negl %ebp
 
     # clear
@@ -398,7 +398,7 @@ _ConvertX86p16_32BGRA888.L6: popl %ebp
 
 
 
-_ConvertX86p16_24RGB888: 
+_ConvertX86p16_24RGB888:
 
     # check short
     cmpl $32,%ecx
@@ -544,7 +544,7 @@ _ConvertX86p16_24RGB888.L9: popl %ebp
 
 
 
-_ConvertX86p16_24BGR888: 
+_ConvertX86p16_24BGR888:
 
     # check short
     cmpl $32,%ecx
@@ -566,7 +566,7 @@ _ConvertX86p16_24BGR888.L1: movb (%esi),%dl
     addl $3,%edi
     decl %ecx
     jnz _ConvertX86p16_24BGR888.L1
-_ConvertX86p16_24BGR888.L2: 
+_ConvertX86p16_24BGR888.L2:
     jmp _x86return
 
 
@@ -690,7 +690,7 @@ _ConvertX86p16_24BGR888.L9: popl %ebp
 
 
 
-_ConvertX86p16_16BGR565: 
+_ConvertX86p16_16BGR565:
 
     # check short
     cmpl $16,%ecx
@@ -714,7 +714,7 @@ _ConvertX86p16_16BGR565.L1:  # short loop
     addl $2,%edi
     decl %ecx
     jnz _ConvertX86p16_16BGR565.L1
-_ConvertX86p16_16BGR565.L2: 
+_ConvertX86p16_16BGR565.L2:
     jmp _x86return
 
 _ConvertX86p16_16BGR565.L3:  # head
@@ -747,7 +747,7 @@ _ConvertX86p16_16BGR565.L4:  # save count
     leal (%esi,%ecx,4),%esi
     leal (%edi,%ecx,4),%edi
 
-    # negative counter 
+    # negative counter
     negl %ecx
     jmp _ConvertX86p16_16BGR565.L6
 
@@ -792,7 +792,7 @@ _ConvertX86p16_16BGR565.L6: movl (%esi,%ecx,4),%eax
     addl $2,%esi
     addl $2,%edi
 
-_ConvertX86p16_16BGR565.L7: 
+_ConvertX86p16_16BGR565.L7:
     jmp _x86return
 
 
@@ -800,7 +800,7 @@ _ConvertX86p16_16BGR565.L7:
 
 
 
-_ConvertX86p16_16RGB555: 
+_ConvertX86p16_16RGB555:
 
     # check short
     cmpl $32,%ecx
@@ -821,7 +821,7 @@ _ConvertX86p16_16RGB555.L1:  # short loop
     addl $2,%edi
     decl %ecx
     jnz _ConvertX86p16_16RGB555.L1
-_ConvertX86p16_16RGB555.L2: 
+_ConvertX86p16_16RGB555.L2:
     jmp _x86return
 
 _ConvertX86p16_16RGB555.L3:  # head
@@ -854,7 +854,7 @@ _ConvertX86p16_16RGB555.L4:  # save ebp
     leal (%esi,%ecx,8),%esi
     leal (%edi,%ecx,8),%edi
 
-    # negative counter 
+    # negative counter
     xorl %ebp,%ebp
     subl %ecx,%ebp
 
@@ -908,7 +908,7 @@ _ConvertX86p16_16RGB555.L7: popl %ebp
 
 
 
-_ConvertX86p16_16BGR555: 
+_ConvertX86p16_16BGR555:
 
     # check short
     cmpl $16,%ecx
@@ -934,7 +934,7 @@ _ConvertX86p16_16BGR555.L1:  # short loop
     addl $2,%edi
     decl %ecx
     jnz _ConvertX86p16_16BGR555.L1
-_ConvertX86p16_16BGR555.L2: 
+_ConvertX86p16_16BGR555.L2:
     jmp _x86return
 
 _ConvertX86p16_16BGR555.L3:  # head
@@ -969,7 +969,7 @@ _ConvertX86p16_16BGR555.L4:  # save count
     leal (%esi,%ecx,4),%esi
     leal (%edi,%ecx,4),%edi
 
-    # negative counter 
+    # negative counter
     negl %ecx
     jmp _ConvertX86p16_16BGR555.L6
 
@@ -1018,7 +1018,7 @@ _ConvertX86p16_16BGR555.L6: movl (%esi,%ecx,4),%eax
     addl $2,%esi
     addl $2,%edi
 
-_ConvertX86p16_16BGR555.L7: 
+_ConvertX86p16_16BGR555.L7:
     jmp _x86return
 
 
@@ -1026,7 +1026,7 @@ _ConvertX86p16_16BGR555.L7:
 
 
 
-_ConvertX86p16_8RGB332: 
+_ConvertX86p16_8RGB332:
 
     # check short
     cmpl $16,%ecx
@@ -1051,7 +1051,7 @@ _ConvertX86p16_8RGB332.L1:  # short loop
     incl %edi
     decl %ecx
     jnz _ConvertX86p16_8RGB332.L1
-_ConvertX86p16_8RGB332.L2: 
+_ConvertX86p16_8RGB332.L2:
     jmp _x86return
 
 _ConvertX86p16_8RGB332.L3: movl %edi,%eax

+ 49 - 49
packages/hermes/src/i386/x86p_32.as

@@ -2,12 +2,12 @@
 # x86 format converters for HERMES
 # Some routines Copyright (c) 1998 Christian Nentwich ([email protected])
 # This source code is licensed under the GNU LGPL
-# 
+#
 # Please refer to the file COPYING.LIB contained in the distribution for
-# licensing conditions          
+# licensing conditions
 #
 # Most routines are (c) Glenn Fiedler ([email protected]), used with permission
-# 
+#
 
 
 
@@ -28,15 +28,15 @@
 
 
 ## _Convert_*
-## Paramters:   
-##   ESI = source 
+## Paramters:
+##   ESI = source
 ##   EDI = dest
 ##   ECX = amount (NOT 0!!! (the _ConvertX86 routine checks for that though))
 ## Destroys:
 ##   EAX, EBX, EDX
 
 
-_ConvertX86p32_32BGR888: 
+_ConvertX86p32_32BGR888:
 
     # check short
     cmpl $32,%ecx
@@ -51,7 +51,7 @@ _ConvertX86p32_32BGR888.L1:  # short loop
     addl $4,%edi
     decl %ecx
     jnz _ConvertX86p32_32BGR888.L1
-_ConvertX86p32_32BGR888.L2: 
+_ConvertX86p32_32BGR888.L2:
     jmp _x86return
 
 _ConvertX86p32_32BGR888.L3:  # save ebp
@@ -117,7 +117,7 @@ _ConvertX86p32_32BGR888.L6: popl %ebp
 
 
 
-_ConvertX86p32_32RGBA888: 
+_ConvertX86p32_32RGBA888:
 
     # check short
     cmpl $32,%ecx
@@ -131,7 +131,7 @@ _ConvertX86p32_32RGBA888.L1:  # short loop
     addl $4,%edi
     decl %ecx
     jnz _ConvertX86p32_32RGBA888.L1
-_ConvertX86p32_32RGBA888.L2: 
+_ConvertX86p32_32RGBA888.L2:
     jmp _x86return
 
 _ConvertX86p32_32RGBA888.L3:  # save ebp
@@ -188,7 +188,7 @@ _ConvertX86p32_32RGBA888.L6: popl %ebp
 
 
 
-_ConvertX86p32_32BGRA888: 
+_ConvertX86p32_32BGRA888:
 
     # check short
     cmpl $32,%ecx
@@ -202,7 +202,7 @@ _ConvertX86p32_32BGRA888.L1:  # short loop
     addl $4,%edi
     decl %ecx
     jnz _ConvertX86p32_32BGRA888.L1
-_ConvertX86p32_32BGRA888.L2: 
+_ConvertX86p32_32BGRA888.L2:
     jmp _x86return
 
 _ConvertX86p32_32BGRA888.L3:  # save ebp
@@ -263,7 +263,7 @@ _ConvertX86p32_32BGRA888.L6: popl %ebp
 
 ## 32 bit RGB 888 to 24 BIT RGB 888
 
-_ConvertX86p32_24RGB888: 
+_ConvertX86p32_24RGB888:
 
         # check short
         cmpl $32,%ecx
@@ -280,7 +280,7 @@ _ConvertX86p32_24RGB888.L1:  # short loop
         addl $3,%edi
         decl %ecx
         jnz _ConvertX86p32_24RGB888.L1
-_ConvertX86p32_24RGB888.L2: 
+_ConvertX86p32_24RGB888.L2:
         jmp _x86return
 
 _ConvertX86p32_24RGB888.L3:  #        head
@@ -360,7 +360,7 @@ _ConvertX86p32_24RGB888.L7: popl %ebp
 
 ## 32 bit RGB 888 to 24 bit BGR 888
 
-_ConvertX86p32_24BGR888: 
+_ConvertX86p32_24BGR888:
 
         # check short
         cmpl $32,%ecx
@@ -378,7 +378,7 @@ _ConvertX86p32_24BGR888.L1:  # short loop
         addl $3,%edi
         decl %ecx
         jnz _ConvertX86p32_24BGR888.L1
-_ConvertX86p32_24BGR888.L2: 
+_ConvertX86p32_24BGR888.L2:
         jmp _x86return
 
 _ConvertX86p32_24BGR888.L3:  # head
@@ -404,7 +404,7 @@ _ConvertX86p32_24BGR888.L4:  # unroll 4 times
         # save count
         pushl %ecx
 
-_ConvertX86p32_24BGR888.L5: 
+_ConvertX86p32_24BGR888.L5:
         movl (%esi),%eax                # first dword            eax = [A][R][G][B]
         movl 4(%esi),%ebx               # second dword           ebx = [a][r][g][b]
 
@@ -412,7 +412,7 @@ _ConvertX86p32_24BGR888.L5:
 
         bswapl %ebx                     #                        ebx = [b][g][r][a]
 
-        movb 4+2(%esi),%al              #                        eax = [B][G][R][r] 
+        movb 4+2(%esi),%al              #                        eax = [B][G][R][r]
         movb 4+4+1(%esi),%bh            #                        ebx = [b][g][G][a]
 
         rorl $8,%eax                    #                        eax = [r][B][G][R] (done)
@@ -452,16 +452,16 @@ _ConvertX86p32_24BGR888.L6:  # tail loop
         decl %ecx
         jnz _ConvertX86p32_24BGR888.L6
 
-_ConvertX86p32_24BGR888.L7: 
+_ConvertX86p32_24BGR888.L7:
         popl %ebp
         jmp _x86return
 
 
 
 
-## 32 bit RGB 888 to 16 BIT RGB 565 
+## 32 bit RGB 888 to 16 BIT RGB 565
 .align 8
-_ConvertX86p32_16RGB565: 
+_ConvertX86p32_16RGB565:
         # check short
         cmpl $16,%ecx
         ja _ConvertX86p32_16RGB565.L3
@@ -505,7 +505,7 @@ _ConvertX86p32_16RGB565.L3:  # head
         addl $2,%edi
         decl %ecx
 
-_ConvertX86p32_16RGB565.L4: 
+_ConvertX86p32_16RGB565.L4:
     # save count
         pushl %ecx
 
@@ -516,14 +516,14 @@ _ConvertX86p32_16RGB565.L4:
         leal (%esi,%ecx,8),%esi
         leal (%edi,%ecx,4),%edi
 
-    # negative counter 
+    # negative counter
         negl %ecx
         jmp _ConvertX86p32_16RGB565.L6
 
-_ConvertX86p32_16RGB565.L5: 
+_ConvertX86p32_16RGB565.L5:
         movl %eax,-4(%edi,%ecx,4)
 .align 8
-_ConvertX86p32_16RGB565.L6: 
+_ConvertX86p32_16RGB565.L6:
         movl (%esi,%ecx,8),%eax
 
         shrb $2,%ah
@@ -569,15 +569,15 @@ _ConvertX86p32_16RGB565.L6:
         addl $4,%esi
         addl $2,%edi
 
-_ConvertX86p32_16RGB565.L7: 
+_ConvertX86p32_16RGB565.L7:
         jmp _x86return
 
 
 
 
-## 32 bit RGB 888 to 16 BIT BGR 565 
+## 32 bit RGB 888 to 16 BIT BGR 565
 
-_ConvertX86p32_16BGR565: 
+_ConvertX86p32_16BGR565:
 
         # check short
         cmpl $16,%ecx
@@ -598,7 +598,7 @@ _ConvertX86p32_16BGR565.L1:  # short loop
         addl $2,%edi
         decl %ecx
         jnz _ConvertX86p32_16BGR565.L1
-_ConvertX86p32_16BGR565.L2: 
+_ConvertX86p32_16BGR565.L2:
         jmp _x86return
 
 _ConvertX86p32_16BGR565.L3:  # head
@@ -633,9 +633,9 @@ _ConvertX86p32_16BGR565.L4:  # save count
         negl %ecx
         jmp _ConvertX86p32_16BGR565.L6
 
-_ConvertX86p32_16BGR565.L5: 
+_ConvertX86p32_16BGR565.L5:
         movl %eax,-4(%edi,%ecx,4)
-_ConvertX86p32_16BGR565.L6: 
+_ConvertX86p32_16BGR565.L6:
         movl 4(%esi,%ecx,8),%edx
 
         movb 4(%esi,%ecx,8),%bh
@@ -683,7 +683,7 @@ _ConvertX86p32_16BGR565.L6:
         addl $4,%esi
         addl $2,%edi
 
-_ConvertX86p32_16BGR565.L7: 
+_ConvertX86p32_16BGR565.L7:
         jmp _x86return
 
 
@@ -691,7 +691,7 @@ _ConvertX86p32_16BGR565.L7:
 
 ## 32 BIT RGB TO 16 BIT RGB 555
 
-_ConvertX86p32_16RGB555: 
+_ConvertX86p32_16RGB555:
 
         # check short
         cmpl $16,%ecx
@@ -712,7 +712,7 @@ _ConvertX86p32_16RGB555.L1:  # short loop
         addl $2,%edi
         decl %ecx
         jnz _ConvertX86p32_16RGB555.L1
-_ConvertX86p32_16RGB555.L2: 
+_ConvertX86p32_16RGB555.L2:
         jmp _x86return
 
 _ConvertX86p32_16RGB555.L3:  # head
@@ -743,13 +743,13 @@ _ConvertX86p32_16RGB555.L4:  # save count
         leal (%esi,%ecx,8),%esi
         leal (%edi,%ecx,4),%edi
 
-        # negative counter 
+        # negative counter
         negl %ecx
         jmp _ConvertX86p32_16RGB555.L6
 
-_ConvertX86p32_16RGB555.L5: 
+_ConvertX86p32_16RGB555.L5:
         movl %eax,-4(%edi,%ecx,4)
-_ConvertX86p32_16RGB555.L6: 
+_ConvertX86p32_16RGB555.L6:
         movl (%esi,%ecx,8),%eax
 
         shrb $3,%ah
@@ -794,7 +794,7 @@ _ConvertX86p32_16RGB555.L6:
         addl $4,%esi
         addl $2,%edi
 
-_ConvertX86p32_16RGB555.L7: 
+_ConvertX86p32_16RGB555.L7:
         jmp _x86return
 
 
@@ -802,7 +802,7 @@ _ConvertX86p32_16RGB555.L7:
 
 ## 32 BIT RGB TO 16 BIT BGR 555
 
-_ConvertX86p32_16BGR555: 
+_ConvertX86p32_16BGR555:
 
         # check short
         cmpl $16,%ecx
@@ -824,7 +824,7 @@ _ConvertX86p32_16BGR555.L1:  # short loop
         addl $2,%edi
         decl %ecx
         jnz _ConvertX86p32_16BGR555.L1
-_ConvertX86p32_16BGR555.L2: 
+_ConvertX86p32_16BGR555.L2:
         jmp _x86return
 
 _ConvertX86p32_16BGR555.L3:  # head
@@ -855,13 +855,13 @@ _ConvertX86p32_16BGR555.L4:  # save count
         leal (%esi,%ecx,8),%esi
         leal (%edi,%ecx,4),%edi
 
-        # negative counter 
+        # negative counter
         negl %ecx
         jmp _ConvertX86p32_16BGR555.L6
 
-_ConvertX86p32_16BGR555.L5: 
+_ConvertX86p32_16BGR555.L5:
         movl %eax,-4(%edi,%ecx,4)
-_ConvertX86p32_16BGR555.L6: 
+_ConvertX86p32_16BGR555.L6:
         movl 4(%esi,%ecx,8),%edx
 
         movb 4(%esi,%ecx,8),%bh
@@ -909,7 +909,7 @@ _ConvertX86p32_16BGR555.L6:
         addl $4,%esi
         addl $2,%edi
 
-_ConvertX86p32_16BGR555.L7: 
+_ConvertX86p32_16BGR555.L7:
         jmp _x86return
 
 
@@ -919,10 +919,10 @@ _ConvertX86p32_16BGR555.L7:
 ## FROM 32 BIT RGB to 8 BIT RGB (rrrgggbbb)
 ## This routine writes FOUR pixels at once (dword) and then, if they exist
 ## the trailing three pixels
-_ConvertX86p32_8RGB332: 
+_ConvertX86p32_8RGB332:
 
 
-_ConvertX86p32_8RGB332.L_ALIGNED: 
+_ConvertX86p32_8RGB332.L_ALIGNED:
         pushl %ecx
 
         shrl $2,%ecx            # We will draw 4 pixels at once
@@ -930,7 +930,7 @@ _ConvertX86p32_8RGB332.L_ALIGNED:
 
         jmp _ConvertX86p32_8RGB332.L2 # short jump out of range :(
 
-_ConvertX86p32_8RGB332.L1: 
+_ConvertX86p32_8RGB332.L1:
         movl (%esi),%eax        # first pair of pixels
         movl 4(%esi),%edx
 
@@ -1008,14 +1008,14 @@ _ConvertX86p32_8RGB332.L1:
         jz _ConvertX86p32_8RGB332.L2 # L1 out of range for short jump :(
 
         jmp _ConvertX86p32_8RGB332.L1
-_ConvertX86p32_8RGB332.L2: 
+_ConvertX86p32_8RGB332.L2:
 
         popl %ecx
         andl $3,%ecx            # mask out number of pixels to draw
 
         jz _ConvertX86p32_8RGB332.L4 # Nothing to do anymore
 
-_ConvertX86p32_8RGB332.L3: 
+_ConvertX86p32_8RGB332.L3:
         movl (%esi),%eax        # single pixel conversion for trailing pixels
 
         movl %eax,%ebx
@@ -1039,5 +1039,5 @@ _ConvertX86p32_8RGB332.L3:
         decl %ecx
         jnz _ConvertX86p32_8RGB332.L3
 
-_ConvertX86p32_8RGB332.L4: 
+_ConvertX86p32_8RGB332.L4:
         jmp _x86return

+ 13 - 13
packages/hermes/src/i386/x86p_cpy.as

@@ -15,13 +15,13 @@
 
 ## _Copy*
 ## Paramters:
-##   ESI = source 
+##   ESI = source
 ##   EDI = dest
 ##   ECX = amount (NOT 0!!! (the _ConvertX86 routine checks for that though))
 ## Destroys:
 ##   EAX, EBX, EDX
 
-_CopyX86p_4byte: 
+_CopyX86p_4byte:
 
         rep
  movsl
@@ -29,14 +29,14 @@ _CopyX86p_4byte:
         jmp _x86return
 
 
-_CopyX86p_3byte: 
+_CopyX86p_3byte:
 
         leal (%ecx,%ecx,2),%ecx
         jmp _CopyX86p_1byte
 
 
 
-_CopyX86p_2byte: 
+_CopyX86p_2byte:
 
         testl $3,%edi                   # Check if video memory is aligned
         jz _CopyX86p_2byte.L_ALIGNED
@@ -50,7 +50,7 @@ _CopyX86p_2byte:
         decl %ecx
         jz _CopyX86p_2byte.L3
 
-_CopyX86p_2byte.L_ALIGNED: 
+_CopyX86p_2byte.L_ALIGNED:
 
         movl %ecx,%ebx                  # Save ecx for later
 
@@ -60,7 +60,7 @@ _CopyX86p_2byte.L_ALIGNED:
         rep
  movsl
 
-_CopyX86p_2byte.L2: 
+_CopyX86p_2byte.L2:
         andl $1,%ebx
         jz _CopyX86p_2byte.L3
 
@@ -70,14 +70,14 @@ _CopyX86p_2byte.L2:
         movw %ax,(%edi)
         addl $2,%edi
 
-_CopyX86p_2byte.L3: 
+_CopyX86p_2byte.L3:
         jmp _x86return
 
 
 
-_CopyX86p_1byte: 
+_CopyX86p_1byte:
 
-_CopyX86p_1byte.L_alignloop: 
+_CopyX86p_1byte.L_alignloop:
         testl $3,%edi
         jz _CopyX86p_1byte.L_aligned
 
@@ -91,7 +91,7 @@ _CopyX86p_1byte.L_alignloop:
         jz _CopyX86p_1byte.L4
         jmp _CopyX86p_1byte.L_alignloop
 
-_CopyX86p_1byte.L_aligned: 
+_CopyX86p_1byte.L_aligned:
         movl %ecx,%edx
 
         shrl $2,%ecx
@@ -100,13 +100,13 @@ _CopyX86p_1byte.L_aligned:
         rep
  movsl
 
-_CopyX86p_1byte.L2: 
+_CopyX86p_1byte.L2:
         movl %edx,%ecx          # Get the remaining pixels to draw
 
         andl $3,%ecx
         jz _CopyX86p_1byte.L4   # width was modulo 4
 
-_CopyX86p_1byte.L3: 
+_CopyX86p_1byte.L3:
         movb (%esi),%al
         incl %esi
 
@@ -116,5 +116,5 @@ _CopyX86p_1byte.L3:
         decl %ecx
         jnz _CopyX86p_1byte.L3
 
-_CopyX86p_1byte.L4: 
+_CopyX86p_1byte.L4:
         jmp _x86return

+ 16 - 22
packages/hermes/src/i386/x86p_i8.as

@@ -2,10 +2,10 @@
 # x86 format converters for HERMES
 # Copyright (c) 1998 Christian Nentwich ([email protected])
 # This source code is licensed under the GNU LGPL
-# 
+#
 # Please refer to the file COPYING.LIB contained in the distribution for
-# licensing conditions          
-# 
+# licensing conditions
+#
 # Some routines are (c) Glenn Fiedler ([email protected]), used with permission
 #
 
@@ -22,18 +22,18 @@
 
 
 ## Convert_*
-## Paramters:   
-##   ESI = source 
+## Paramters:
+##   ESI = source
 ##   EDI = dest
 ##   ECX = amount (NOT 0!!! (the ConvertX86 routine checks for that though))
 ## Destroys:
 ##   EAX, EBX, EDX
 
-_ConvertX86pI8_32: 
+_ConvertX86pI8_32:
 
         xorl %ebx,%ebx
         movl 36(%ebp),%edx
-_ConvertX86pI8_32.L1: 
+_ConvertX86pI8_32.L1:
         movb (%esi),%bl
         incl %esi
 
@@ -49,7 +49,7 @@ _ConvertX86pI8_32.L1:
 
 
 
-_ConvertX86pI8_24: 
+_ConvertX86pI8_24:
         movl 36(%ebp),%ebx
 
         xorl %edx,%edx
@@ -70,7 +70,7 @@ _ConvertX86pI8_24.L1:  # short loop
         addl $3,%edi
         decl %ecx
         jnz _ConvertX86pI8_24.L1
-_ConvertX86pI8_24.L2: 
+_ConvertX86pI8_24.L2:
         jmp _x86return
 
 _ConvertX86pI8_24.L3:  # head
@@ -99,7 +99,7 @@ _ConvertX86pI8_24.L4:  # save ebp
         shrl $2,%ecx
 
 _ConvertX86pI8_24.L5: pushl %ecx        # save ecx
-        movb (%esi),%dl                 # index to "A"           
+        movb (%esi),%dl                 # index to "A"
 
         movl (%ebp,%edx,4),%eax         # eax = [xx][A2][A1][A0]
         shll $8,%eax                    # eax = [A2][A1][A0][xx]
@@ -142,7 +142,7 @@ _ConvertX86pI8_24.L5: pushl %ecx        # save ecx
         andl $0b11,%ecx
         jz _ConvertX86pI8_24.L7
 
-_ConvertX86pI8_24.L6: 
+_ConvertX86pI8_24.L6:
         movb (%esi),%dl
         movl (%ebx,%edx,4),%eax
         movb %al,(%edi) # blue
@@ -159,7 +159,7 @@ _ConvertX86pI8_24.L7: popl %ebp
 
 
 .align 8
-_ConvertX86pI8_16: 
+_ConvertX86pI8_16:
         xorl %ebx,%ebx
         movl 36(%ebp),%edx
 
@@ -177,7 +177,7 @@ _ConvertX86pI8_16:
         decl %ecx
         jz _ConvertX86pI8_16.out
 
-_ConvertX86pI8_16.Laligned: 
+_ConvertX86pI8_16.Laligned:
         pushl %ecx
 
         xorl %eax,%eax
@@ -186,7 +186,7 @@ _ConvertX86pI8_16.Laligned:
         shrl %ecx
         jz _ConvertX86pI8_16.last_pixel
 .align 8
-_ConvertX86pI8_16.Ly: 
+_ConvertX86pI8_16.Ly:
         movb 1(%esi),%bl
         movb (%esi),%al
 
@@ -206,7 +206,7 @@ _ConvertX86pI8_16.Ly:
         decl %ecx
         jnz _ConvertX86pI8_16.Ly
 
-_ConvertX86pI8_16.last_pixel: 
+_ConvertX86pI8_16.last_pixel:
         popl %ecx
 
         testb $1,%cl
@@ -220,11 +220,5 @@ _ConvertX86pI8_16.last_pixel:
         movw %ax,(%edi)
         addl $2,%edi
 
-_ConvertX86pI8_16.out: 
+_ConvertX86pI8_16.out:
         jmp _x86return
-
-
-
-
-
-

+ 6 - 8
packages/hermes/src/i386/x86p_s32.as

@@ -8,7 +8,7 @@
 .extern _x86return_S
 
 ## _Convert*_S
-## Paramters:   
+## Paramters:
 ##   ESI = source
 ##   EDI = dest
 ##   ECX = amount (NOT 0!!! (the _ConvertX86 routine checks for that though))
@@ -17,7 +17,7 @@
 ##   EAX, EBX, ECX, EDX
 
 
-_ConvertX86p32_16RGB565_S: 
+_ConvertX86p32_16RGB565_S:
 
         pushl %ebp
         pushl %edx              # increment now at [esp+4]!
@@ -29,10 +29,10 @@ _ConvertX86p32_16RGB565_S:
         jnz _ConvertX86p32_16RGB565_S.L_ok
         jmp _ConvertX86p32_16RGB565_S.L_final
 
-_ConvertX86p32_16RGB565_S.L_ok: 
+_ConvertX86p32_16RGB565_S.L_ok:
 
 .align 8
-_ConvertX86p32_16RGB565_S.Lx: 
+_ConvertX86p32_16RGB565_S.Lx:
         movl %ebp,%eax
 
         shrl $14,%eax
@@ -82,7 +82,7 @@ _ConvertX86p32_16RGB565_S.Lx:
         decl %ecx
         jnz _ConvertX86p32_16RGB565_S.Lx
 
-_ConvertX86p32_16RGB565_S.L_final: 
+_ConvertX86p32_16RGB565_S.L_final:
         popl %ecx
         andl $1,%ecx
         jz _ConvertX86p32_16RGB565_S.L_out
@@ -107,10 +107,8 @@ _ConvertX86p32_16RGB565_S.L_final:
         movw %ax,(%edi)
         addl $2,%edi
 
-_ConvertX86p32_16RGB565_S.L_out: 
+_ConvertX86p32_16RGB565_S.L_out:
 
         popl %edx
         popl %ebp
         jmp _x86return_S
-
-

+ 5 - 7
packages/hermes/src/i386/x86pscpy.as

@@ -13,30 +13,28 @@
 
 ## _Copy*
 ## Paramters:
-##   ESI = source 
+##   ESI = source
 ##   EDI = dest
 ##   ECX = amount (NOT 0!!! (the _ConvertX86 routine checks for that though))
 ## Destroys:
 ##   EAX, EBX, EDX
 
-_CopyX86p_4byte_S: 
+_CopyX86p_4byte_S:
 
 
         jmp _x86return_S
 
 
-_CopyX86p_3byte_S: 
+_CopyX86p_3byte_S:
 
         jmp _x86return_S
 
 
 
-_CopyX86p_2byte_S: 
+_CopyX86p_2byte_S:
 
         jmp _x86return_S
 
-_CopyX86p_1byte_S: 
+_CopyX86p_1byte_S:
 
         jmp _x86return_S
-
-

+ 0 - 212
packages/hermes/src/list.inc

@@ -1,212 +0,0 @@
-{
-    Free Pascal port of the Hermes C library.
-    Copyright (C) 2001-2003  Nikolay Nikolov ([email protected])
-    Original C version by Christian Nentwich ([email protected])
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library 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
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-}
-
-Type
-  TListFreeCallback = Procedure(p : Pointer);
-  PHermesListElementStruct = ^THermesListElementStruct;
-  THermesListElementStruct = Record
-    handle : THermesHandle;
-    data : Pointer;
-    next : PHermesListElementStruct;
-  End;
-  PHermesListElement = ^THermesListElement;
-  THermesListElement = THermesListElementStruct;
-  PHermesList = ^THermesList;
-  THermesList = Record
-    first, last : PHermesListElement;
-  End;
-
-{Function Hermes_ListNew : PHermesList;
-Procedure Hermes_ListDestroy(list : PHermesList);
-Function Hermes_ListElementNew(handle : THermesHandle) : PHermesListElement;
-Procedure Hermes_ListAdd(list : PHermesList; element : PHermesListElement);
-Procedure Hermes_ListAddFront(list : PHermesList; element : PHermesListElement);
-Function Hermes_ListDeleteElement(list : PHermesList; handle : THermesHandle) : Boolean;
-Function Hermes_ListLookup(list : PHermesList;
-                           handle : THermesHandle) : PHermesListElement;}
-
-Function Hermes_ListNew : PHermesList;
-
-Var
-  tmp : PHermesList;
-
-Begin
-{  New(tmp);}
-  tmp := malloc(SizeOf(THermesList));
-  If tmp = Nil Then
-  Begin
-    Hermes_ListNew := Nil;
-    Exit;
-  End;
-  tmp^.first := Nil;
-  tmp^.last := Nil;
-  Hermes_ListNew := tmp;
-End;
-
-Procedure Hermes_ListDestroy(list : PHermesList);
-
-Var
-  tmp, run : PHermesListElement;
-
-Begin
-  If list = Nil Then
-    Exit;
-  run := list^.first;
-  While run <> Nil Do
-  Begin
-    tmp := run;
-    run := run^.next;
-    If tmp^.data <> Nil Then
-    Begin
-      {to do: free(tmp->data)}
-      free(tmp^.data);
-    End;
-    free(tmp);
-  End;
-  free(list);
-  list := Nil;
-End;
-
-Function Hermes_ListElementNew(handle : THermesHandle) : PHermesListElement;
-
-Var
-  tmp : PHermesListElement;
-
-Begin
-  tmp := malloc(SizeOf(THermesListElement));
-  If tmp = Nil Then
-  Begin
-    Hermes_ListElementNew := Nil;
-    Exit;
-  End;
-  tmp^.handle := handle;
-  tmp^.next := Nil;
-  tmp^.data := Nil;
-  Hermes_ListElementNew := tmp;
-End;
-
-Procedure Hermes_ListAdd(list : PHermesList; element : PHermesListElement);
-
-Begin
-  If (list = Nil) Or (element = Nil) Then
-    Exit;
-  If list^.first = Nil Then
-  Begin
-    list^.first := element;
-    list^.last := element;
-    element^.next := Nil;
-    Exit;
-  End;
-  list^.last^.next := element;
-  list^.last := element;
-  element^.next := Nil;
-End;
-
-Procedure Hermes_ListAddFront(list : PHermesList; element : PHermesListElement);
-
-Begin
-  If (list = Nil) Or (element = Nil) Then
-    Exit;
-  If list^.first = Nil Then
-  Begin
-    list^.first := element;
-    list^.last := element;
-    element^.next := Nil;
-    Exit;
-  End;
-  element^.next := list^.first;
-  list^.first := element;
-End;
-
-Function Hermes_ListDeleteElement(list : PHermesList; handle : THermesHandle; user_free : TListFreeCallback) : Boolean;
-
-Var
-  run, previous : PHermesListElement;
-
-Begin
-  If list = Nil Then
-  Begin
-    Hermes_ListDeleteElement := False;
-    Exit;
-  End;
-  previous := Nil;
-  run := list^.first;
-  While run <> Nil Do
-  Begin
-    If run^.handle = handle Then
-    Begin
-      If run = list^.first Then
-        list^.first := run^.next
-      Else
-        previous^.next := run^.next;
-      If run = list^.last Then
-      Begin
-        list^.last := previous;
-        If list^.last <> Nil Then
-          list^.last^.next := Nil;
-      End;
-      If run^.data <> Nil Then
-      Begin
-        If user_free <> Nil Then
-        Begin
-          user_free(run^.data);
-        End;
-        free(run^.data);
-      End;
-      free(run);
-      Hermes_ListDeleteElement := True;
-      Exit;
-    End;
-    previous := run;
-    run := run^.next;
-  End;
-  Hermes_ListDeleteElement := False;
-End;
-
-Function Hermes_ListDeleteElement(list : PHermesList; handle : THermesHandle) : Boolean;
-
-Begin
-  Hermes_ListDeleteElement := Hermes_ListDeleteElement(list, handle, Nil);
-End;
-
-Function Hermes_ListLookup(list : PHermesList;
-                           handle : THermesHandle) : PHermesListElement;
-
-Var
-  run : PHermesListElement;
-
-Begin
-  If list = Nil Then
-  Begin
-    Hermes_ListLookup := Nil;
-    Exit;
-  End;
-  run := list^.first;
-  While run <> Nil Do
-  Begin
-    If run^.handle = handle Then
-    Begin
-      Hermes_ListLookup := run;
-      Exit;
-    End;
-    run := run^.next;
-  End;
-  Hermes_ListLookup := Nil;
-End;

+ 0 - 31
packages/hermes/src/malloc.inc

@@ -1,31 +0,0 @@
-{
-    Free Pascal port of the Hermes C library.
-    Copyright (C) 2001-2003  Nikolay Nikolov ([email protected])
-    Original C version by Christian Nentwich ([email protected])
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library 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
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-}
-
-Function malloc(size : DWord) : Pointer;
-
-Begin
-  malloc := GetMem(size);
-End;
-
-Procedure free(ptr : Pointer);
-
-Begin
-  FreeMem(ptr);
-End;

+ 499 - 511
packages/hermes/src/p_16.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -28,357 +40,337 @@
 }
 
 { TO 32 BIT RGB }
-Procedure ConvertP_16rgb565_32rgb888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
+procedure ConvertP_16rgb565_32rgb888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_pixel: Uint32;
+begin
+  repeat
+    d_pixel := PUint16(source)^;
 
-Var
-  d_pixel : int32;
+    d_pixel := ((d_pixel and $f800) shl 8) or ((d_pixel and $7e0) shl 5) or
+               ((d_pixel and $1f) shl 3) or $030103;
 
-Begin
-  Repeat
-    d_pixel := Pshort16(source)^;
-
-    d_pixel := ((d_pixel And $f800) Shl 8) Or ((d_pixel And $7e0) Shl 5) Or
-               ((d_pixel And $1f) Shl 3) Or $030103;
-
-    Pint32(dest)^ := d_pixel;
+    PUint32(dest)^ := d_pixel;
 
     Inc(source, 2);
     Inc(dest, 4);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
 { TO 32 BIT BGR }
-Procedure ConvertP_16rgb565_32bgr888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_pixel : int32;
-
-Begin
-  Repeat
-    d_pixel := Pshort16(source)^;
+procedure ConvertP_16rgb565_32bgr888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_pixel: Uint32;
+begin
+  repeat
+    d_pixel := PUint16(source)^;
 
-    d_pixel := ((d_pixel And $f800) Shr 8) Or ((d_pixel And $7e0) Shl 5) Or
-               ((d_pixel And $1f) Shl 19) Or $030103;
+    d_pixel := ((d_pixel and $f800) shr 8) or ((d_pixel and $7e0) shl 5) or
+               ((d_pixel and $1f) shl 19) or $030103;
 
-    Pint32(dest)^ := d_pixel;
+    PUint32(dest)^ := d_pixel;
 
     Inc(source, 2);
     Inc(dest, 4);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
 { TO 32 BIT RGBA }
-Procedure ConvertP_16rgb565_32rgba888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
+procedure ConvertP_16rgb565_32rgba888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_pixel: Uint32;
+begin
+  repeat
+    d_pixel := PUint16(source)^;
 
-Var
-  d_pixel : int32;
+    d_pixel := ((d_pixel and $f800) shl 8) or ((d_pixel and $7e0) shl 5) or
+               ((d_pixel and $1f) shl 3) or $030103;
 
-Begin
-  Repeat
-    d_pixel := Pshort16(source)^;
-
-    d_pixel := ((d_pixel And $f800) Shl 8) Or ((d_pixel And $7e0) Shl 5) Or
-               ((d_pixel And $1f) Shl 3) Or $030103;
-
-    Pint32(dest)^ := (d_pixel Shl 8) Or $ff;
+    PUint32(dest)^ := (d_pixel shl 8) or $ff;
 
     Inc(source, 2);
     Inc(dest, 4);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
 { TO 32 BIT BGRA }
-Procedure ConvertP_16rgb565_32bgra888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_pixel : int32;
-
-Begin
-  Repeat
-    d_pixel := Pshort16(source)^;
+procedure ConvertP_16rgb565_32bgra888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_pixel: Uint32;
+begin
+  repeat
+    d_pixel := PUint16(source)^;
 
-    d_pixel := ((d_pixel And $f800) Shr 8) Or ((d_pixel And $7e0) Shl 5) Or
-               ((d_pixel And $1f) Shl 19) Or $030103;
+    d_pixel := ((d_pixel and $f800) shr 8) or ((d_pixel and $7e0) shl 5) or
+               ((d_pixel and $1f) shl 19) or $030103;
 
-    Pint32(dest)^ := (d_pixel Shl 8) Or $ff;
+    PUint32(dest)^ := (d_pixel shl 8) or $ff;
 
     Inc(source, 2);
     Inc(dest, 4);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
 { TO 24 BIT RGB }
-Procedure ConvertP_16rgb565_24rgb888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_pixel : int32;
-  d_ptr : Pchar8;
-
-Begin
-  d_ptr := @d_pixel;
-  Repeat
-    d_pixel := Pshort16(source)^;
-
-    d_pixel := ((d_pixel And $f800) Shl 8) Or ((d_pixel And $7e0) Shl 5) Or
-               ((d_pixel And $1f) Shl 3) Or $030103;
-
-    (dest + R_24)^ := (d_ptr + R_32)^;
-    (dest + G_24)^ := (d_ptr + G_32)^;
-    (dest + B_24)^ := (d_ptr + B_32)^;
+procedure ConvertP_16rgb565_24rgb888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_pixel: Uint32;
+  d_ptr: PUint8;
+begin
+  d_ptr := PUint8(@d_pixel) + (R_32 - R_24);
+  repeat
+    d_pixel := PUint16(source)^;
+
+    d_pixel := ((d_pixel and $f800) shl 8) or ((d_pixel and $7e0) shl 5) or
+               ((d_pixel and $1f) shl 3) or $030103;
+
+    (dest + 0)^ := (d_ptr + 0)^;
+    (dest + 1)^ := (d_ptr + 1)^;
+    (dest + 2)^ := (d_ptr + 2)^;
 
     Inc(source, 2);
     Inc(dest, 3);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
 { TO 24 BIT BGR }
-Procedure ConvertP_16rgb565_24bgr888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_pixel : int32;
-  d_ptr : Pchar8;
-
-Begin
-  d_ptr := @d_pixel;
-  Repeat
-    d_pixel := Pshort16(source)^;
-
-    d_pixel := ((d_pixel And $f800) Shl 8) Or ((d_pixel And $7e0) Shl 5) Or
-               ((d_pixel And $1f) Shl 3) Or $030103;
+procedure ConvertP_16rgb565_24bgr888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_pixel: Uint32;
+  d_ptr: PUint8;
+begin
+  d_ptr := PUint8(@d_pixel) + (R_32 - R_24);
+  repeat
+    d_pixel := PUint16(source)^;
+
+    d_pixel := ((d_pixel and $f800) shl 8) or ((d_pixel and $7e0) shl 5) or
+               ((d_pixel and $1f) shl 3) or $030103;
 
     { Red and blue are swapped here }
-    (dest + R_24)^ := (d_ptr + B_32)^;
-    (dest + G_24)^ := (d_ptr + G_32)^;
-    (dest + B_24)^ := (d_ptr + R_32)^;
+    (dest + 0)^ := (d_ptr + 2)^;
+    (dest + 1)^ := (d_ptr + 1)^;
+    (dest + 2)^ := (d_ptr + 0)^;
 
     Inc(source, 2);
     Inc(dest, 3);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
 { TO 16 BIT BGR 565 }
-Procedure ConvertP_16rgb565_16bgr565(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  i : DWord;
-  s_pixel : int32;
-
-Begin
-  { If we are not aligned to a dword, try and convert a single pixel }
-  If (PtrUInt(dest) And $3) <> 0 Then
-  Begin
-    s_pixel := Pshort16(source)^;
+procedure ConvertP_16rgb565_16bgr565(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  i: DWord;
+  s_pixel: Uint32;
+begin
+  { if we are not aligned to a dword, try and convert a single pixel }
+  if (PtrUInt(dest) and $3) <> 0 then
+  begin
+    s_pixel := PUint16(source)^;
 
     { Swap around R and B, leave G unchanged }
-    s_pixel := (s_pixel Shr 11) Or (s_pixel And $7e0) Or
-               ((s_pixel Shl 11) And $f800);
+    s_pixel := (s_pixel shr 11) or (s_pixel and $7e0) or
+               ((s_pixel shl 11) and $f800);
 
-    Pshort16(dest)^ := s_pixel;
+    PUint16(dest)^ := s_pixel;
 
     Dec(count);
     Inc(dest, 2); Inc(source, 2);
-  End;
+  end;
 
   { Now copy blocks of dwords }
-  For i := 1 To count Shr 1 Do
-  Begin
-    s_pixel := Pint32(source)^;
+  for i := 1 to count shr 1 do
+  begin
+    s_pixel := PUint32(source)^;
 
     { Leave G unchanged, shift R to the right and B to the left }
-    s_pixel := (s_pixel And $07e007e0) Or ((s_pixel And $f800f800) Shr 11) Or
-               ((s_pixel And $001f001f) Shl 11);
+    s_pixel := (s_pixel and $07e007e0) or ((s_pixel and $f800f800) shr 11) or
+               ((s_pixel and $001f001f) shl 11);
 
-    Pint32(dest)^ := s_pixel;
+    PUint32(dest)^ := s_pixel;
     Inc(source, 4); Inc(dest, 4);
-  End;
+  end;
 
-  If (count And 1) <> 0 Then
-  Begin
-    s_pixel := Pshort16(source)^;
+  if (count and 1) <> 0 then
+  begin
+    s_pixel := PUint16(source)^;
 
     { Swap around R and B, leave G unchanged }
-    s_pixel := (s_pixel Shr 11) Or (s_pixel And $7e0) Or
-               ((s_pixel Shl 11) And $f800);
+    s_pixel := (s_pixel shr 11) or (s_pixel and $7e0) or
+               ((s_pixel shl 11) and $f800);
 
-    Pshort16(dest)^ := s_pixel;
-  End;
-End;
+    PUint16(dest)^ := s_pixel;
+  end;
+end;
 
 { TO 16 BIT RGB 555 }
-Procedure ConvertP_16rgb565_16rgb555(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  i : DWord;
-  s_pixel : int32;
-
-Begin
-  { If we are not aligned to a dword, try and convert a single pixel }
-  If (PtrUInt(dest) And $3) <> 0 Then
-  Begin
-    s_pixel := Pshort16(source)^;
+procedure ConvertP_16rgb565_16rgb555(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  i: DWord;
+  s_pixel: Uint32;
+begin
+  { if we are not aligned to a dword, try and convert a single pixel }
+  if (PtrUInt(dest) and $3) <> 0 then
+  begin
+    s_pixel := PUint16(source)^;
 
     { Leave blue untouched, mask red and shift by one, mask green and shift
       by one }
-    s_pixel := (s_pixel And $1f) Or ((s_pixel And $f800) Shr 1) Or
-               ((s_pixel And $7c0) Shr 1);
+    s_pixel := (s_pixel and $1f) or ((s_pixel and $f800) shr 1) or
+               ((s_pixel and $7c0) shr 1);
 
-    Pshort16(dest)^ := s_pixel;
+    PUint16(dest)^ := s_pixel;
 
     Dec(count);
     Inc(dest, 2); Inc(source, 2);
-  End;
+  end;
 
   { Now copy blocks of dwords }
-  For i := 1 To count Shr 1 Do
-  Begin
-    s_pixel := Pint32(source)^;
+  for i := 1 to count shr 1 do
+  begin
+    s_pixel := PUint32(source)^;
 
     { Leave blue untouched, mask red and shift by one, mask green and shift
       by one }
-    s_pixel := (s_pixel And $001f001f) Or ((s_pixel And $f800f800) Shr 1) Or
-               ((s_pixel And $07c007c0) Shr 1);
+    s_pixel := (s_pixel and $001f001f) or ((s_pixel and $f800f800) shr 1) or
+               ((s_pixel and $07c007c0) shr 1);
 
-    Pint32(dest)^ := s_pixel;
+    PUint32(dest)^ := s_pixel;
     Inc(source, 4); Inc(dest, 4);
-  End;
+  end;
 
-  If (count And 1) <> 0 Then
-  Begin
-    s_pixel := Pshort16(source)^;
+  if (count and 1) <> 0 then
+  begin
+    s_pixel := PUint16(source)^;
 
     { Leave blue untouched, mask red and shift by one, mask green and shift
       by one }
-    s_pixel := (s_pixel And $1f) Or ((s_pixel And $f800) Shr 1) Or
-               ((s_pixel And $7c0) Shr 1);
+    s_pixel := (s_pixel and $1f) or ((s_pixel and $f800) shr 1) or
+               ((s_pixel and $7c0) shr 1);
 
-    Pshort16(dest)^ := s_pixel;
-  End;
-End;
+    PUint16(dest)^ := s_pixel;
+  end;
+end;
 
 { TO 16 BIT BGR 555 }
-Procedure ConvertP_16rgb565_16bgr555(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  i : DWord;
-  s_pixel : int32;
-
-Begin
-  { If we are not aligned to a dword, try and convert a single pixel }
-  If (PtrUInt(dest) And $3) <> 0 Then
-  Begin
-    s_pixel := Pshort16(source)^;
+procedure ConvertP_16rgb565_16bgr555(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  i: DWord;
+  s_pixel: Uint32;
+begin
+  { if we are not aligned to a dword, try and convert a single pixel }
+  if (PtrUInt(dest) and $3) <> 0 then
+  begin
+    s_pixel := PUint16(source)^;
 
     { Shift red right by 11, mask green and shift right one, shift blue
       left ten }
-    s_pixel := ((s_pixel And $f800) Shr 11) Or ((s_pixel And $7c0) Shr 1) Or
-               ((s_pixel And $1f) Shl 10);
+    s_pixel := ((s_pixel and $f800) shr 11) or ((s_pixel and $7c0) shr 1) or
+               ((s_pixel and $1f) shl 10);
 
-    Pshort16(dest)^ := s_pixel;
+    PUint16(dest)^ := s_pixel;
 
     Dec(count);
     Inc(dest, 2); Inc(source, 2);
-  End;
+  end;
 
   { Now copy blocks of dwords }
-  For i := 1 To count Shr 1 Do
-  Begin
-    s_pixel := Pint32(source)^;
+  for i := 1 to count shr 1 do
+  begin
+    s_pixel := PUint32(source)^;
 
     { Shift red right by 11, mask green and shift right one, shift blue
       left ten }
-    s_pixel := ((s_pixel And $f800f800) Shr 11) Or
-               ((s_pixel And $07c007c0) Shr 1) Or
-               ((s_pixel And $001f001f) Shl 10);
+    s_pixel := ((s_pixel and $f800f800) shr 11) or
+               ((s_pixel and $07c007c0) shr 1) or
+               ((s_pixel and $001f001f) shl 10);
 
-    Pint32(dest)^ := s_pixel;
+    PUint32(dest)^ := s_pixel;
     Inc(source, 4); Inc(dest, 4);
-  End;
+  end;
 
-  If (count And 1) <> 0 Then
-  Begin
-    s_pixel := Pshort16(source)^;
+  if (count and 1) <> 0 then
+  begin
+    s_pixel := PUint16(source)^;
 
     { Shift red right by 11, mask green and shift right one, shift blue
       left ten }
-    s_pixel := ((s_pixel And $f800) Shr 11) Or ((s_pixel And $7c0) Shr 1) Or
-               ((s_pixel And $1f) Shl 10);
+    s_pixel := ((s_pixel and $f800) shr 11) or ((s_pixel and $7c0) shr 1) or
+               ((s_pixel and $1f) shl 10);
 
-    Pshort16(dest)^ := s_pixel;
-  End;
-End;
+    PUint16(dest)^ := s_pixel;
+  end;
+end;
 
 { TO 8 BIT RGB 332 }
-Procedure ConvertP_16rgb565_8rgb332(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  s_block, d_block : int32;
-  i : DWord;
-
-Begin
+procedure ConvertP_16rgb565_8rgb332(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  s_block, d_block: Uint32;
+  i: DWord;
+begin
   { Align to dword first }
-  While (PtrUInt(dest) And $3) <> 0 Do
-  Begin
-    s_block := Pshort16(source)^;
+  while (PtrUInt(dest) and $3) <> 0 do
+  begin
+    s_block := PUint16(source)^;
 
-    s_block := ((s_block And $e000) Shr 8) Or ((s_block And $0700) Shr 6) Or
-               ((s_block And $18) Shr 3);
+    s_block := ((s_block and $e000) shr 8) or ((s_block and $0700) shr 6) or
+               ((s_block and $18) shr 3);
 
     dest^ := s_block;
 
     Dec(count);
-    If count = 0 Then
-      Exit;
+    if count = 0 then
+      exit;
 
     Inc(source, 2);
     Inc(dest);
-  End;
+  end;
 
   { Write blocks of four pixels }
-  For i := 1 To count Shr 2 Do
-  Begin
+  for i := 1 to count shr 2 do
+  begin
     { Read and process first two pixels }
-    s_block := Pint32(source)^;
+    s_block := PUint32(source)^;
 
-    d_block := ((s_block And $e000e000) Shr 8) Or
-               ((s_block And $07000700) Shr 6) Or
-               ((s_block And $00180018) Shr 3);
-    d_block := (d_block And $ff) Or ((d_block And $ff0000) Shr 8);
+    d_block := ((s_block and $e000e000) shr 8) or
+               ((s_block and $07000700) shr 6) or
+               ((s_block and $00180018) shr 3);
+    d_block := (d_block and $ff) or ((d_block and $ff0000) shr 8);
 
-    { And the second two }
-    s_block := (Pint32(source)+1)^;
+    { and the second two }
+    s_block := (PUint32(source)+1)^;
 
-    s_block := ((s_block And $e000e000) Shr 8) Or
-               ((s_block And $07000700) Shr 6) Or
-               ((s_block And $00180018) Shr 3);
-    s_block := (s_block And $ff) Or ((s_block And $ff0000) Shr 8);
+    s_block := ((s_block and $e000e000) shr 8) or
+               ((s_block and $07000700) shr 6) or
+               ((s_block and $00180018) shr 3);
+    s_block := (s_block and $ff) or ((s_block and $ff0000) shr 8);
 
     { Put it all in one dword and write it }
-    d_block := d_block Or (s_block Shl 16);
+    d_block := (d_block shl DWORD_SMALLINT0_SHL) or (s_block shl DWORD_SMALLINT1_SHL);
 
-    Pint32(dest)^ := d_block;
+    PUint32(dest)^ := d_block;
     Inc(source, 8);
     Inc(dest, 4);
-  End;
+  end;
 
   { Clean up remaining pixels }
-  count := count And 3;
-  While count > 0 Do
-  Begin
+  count := count and 3;
+  while count > 0 do
+  begin
     Dec(count);
-    s_block := Pshort16(source)^;
+    s_block := PUint16(source)^;
 
-    dest^ := ((s_block And $e000) Shr 8) Or ((s_block And $0700) Shr 6) Or
-             ((s_block And $18) Shr 3);
+    dest^ := ((s_block and $e000) shr 8) or ((s_block and $0700) shr 6) or
+             ((s_block and $18) shr 3);
     Inc(dest);
     Inc(source, 2);
-  End;
-End;
+  end;
+end;
 
 { -------------------------------------------------------------------------
 
@@ -387,409 +379,405 @@ End;
   ------------------------------------------------------------------------- }
 
 
-Procedure ConvertP_16rgb565_32rgb888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x : DWord;
-  p : int32;
-
-Begin
+procedure ConvertP_16rgb565_32rgb888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+  p: Uint32;
+begin
   x := 0;
-  Repeat
-    p := (((Pshort16(source) + (x Shr 16))^ And $f800) Shl 8) Or
-         (((Pshort16(source) + (x Shr 16))^ And $7e0) Shl 5) Or
-         (((Pshort16(source) + (x Shr 16))^ And $1f) Shl 3) Or $30103;
+  repeat
+    p := (((PUint16(source) + (x shr 16))^ and $f800) shl 8) or
+         (((PUint16(source) + (x shr 16))^ and $7e0) shl 5) or
+         (((PUint16(source) + (x shr 16))^ and $1f) shl 3) or $30103;
 
     Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
 
     Inc(dest, 4);
     Dec(count);
-  Until count = 0;
-End;
-
-Procedure ConvertP_16rgb565_32bgr888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_pixel : int32;
-  x : DWord;
-
-Begin
+  until count = 0;
+end;
+
+procedure ConvertP_16rgb565_32bgr888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_pixel: Uint32;
+  x: DWord;
+begin
   x := 0;
 
-  Repeat
-    d_pixel := (Pshort16(source) + (x Shr 16))^;
+  repeat
+    d_pixel := (PUint16(source) + (x shr 16))^;
 
-    d_pixel := ((d_pixel And $f800) Shr 8) Or ((d_pixel And $7e0) Shl 5) Or
-               ((d_pixel And $1f) Shl 19) Or $30103;
+    d_pixel := ((d_pixel and $f800) shr 8) or ((d_pixel and $7e0) shl 5) or
+               ((d_pixel and $1f) shl 19) or $30103;
 
-    Pint32(dest)^ := d_pixel;
+    PUint32(dest)^ := d_pixel;
 
     Inc(dest, 4);
     Inc(x, inc_source);
     Dec(count);
-  Until count = 0;
-End;
-
-Procedure ConvertP_16rgb565_32rgba888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x : DWord;
-  p : int32;
-
-Begin
+  until count = 0;
+end;
+
+procedure ConvertP_16rgb565_32rgba888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+  p: Uint32;
+begin
   x := 0;
-  Repeat
-    p := (((Pshort16(source) + (x Shr 16))^ And $f800) Shl (8+8)) Or
-         (((Pshort16(source) + (x Shr 16))^ And $7e0) Shl (5+8)) Or
-         (((Pshort16(source) + (x Shr 16))^ And $1f) Shl (3+8)) Or $30103ff;
+  repeat
+    p := (((PUint16(source) + (x shr 16))^ and $f800) shl (8+8)) or
+         (((PUint16(source) + (x shr 16))^ and $7e0) shl (5+8)) or
+         (((PUint16(source) + (x shr 16))^ and $1f) shl (3+8)) or $30103ff;
 
     Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
 
     Inc(dest, 4);
     Dec(count);
-  Until count = 0;
-End;
-
-Procedure ConvertP_16rgb565_32bgra888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_pixel : int32;
-  x : DWord;
-
-Begin
+  until count = 0;
+end;
+
+procedure ConvertP_16rgb565_32bgra888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_pixel: Uint32;
+  x: DWord;
+begin
   x := 0;
 
-  Repeat
-    d_pixel := (Pshort16(source) + (x Shr 16))^;
+  repeat
+    d_pixel := (PUint16(source) + (x shr 16))^;
 
-    d_pixel := ((d_pixel And $f800) {Shr 8}) Or ((d_pixel And $7e0) Shl (5+8)) Or
-               ((d_pixel And $1f) Shl (19+8)) Or $30103ff;
+    d_pixel := ((d_pixel and $f800) {Shr 8}) or ((d_pixel and $7e0) shl (5+8)) or
+               ((d_pixel and $1f) shl (19+8)) or $30103ff;
 
-    Pint32(dest)^ := d_pixel;
+    PUint32(dest)^ := d_pixel;
 
     Inc(dest, 4);
     Inc(x, inc_source);
     Dec(count);
-  Until count = 0;
-End;
-
-Procedure ConvertP_16rgb565_24rgb888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x : DWord;
-  p1, p2, p3, p4 : DWord;
-  c : DWord;
-
-Begin
+  until count = 0;
+end;
+
+procedure ConvertP_16rgb565_24rgb888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+  p1, p2, p3, p4: DWord;
+  c: DWord;
+begin
   x := 0;
-  While (PtrUInt(dest) And 3) <> 0 Do
-  Begin
-    p1 := (((Pshort16(source) + (x Shr 16))^ And $f800) Shl 8) Or
-          (((Pshort16(source) + (x Shr 16))^ And $7e0) Shl 5) Or
-          (((Pshort16(source) + (x Shr 16))^ And $1f) Shl 3) Or $30103;
-    Pshort16(dest)^ := p1 And $FFFF;
-    (dest + 2)^ := p1 Shr 16;
-    
+  while (PtrUInt(dest) and 3) <> 0 do
+  begin
+    p1 := (((PUint16(source) + (x shr 16))^ and $f800) shl 8) or
+          (((PUint16(source) + (x shr 16))^ and $7e0) shl 5) or
+          (((PUint16(source) + (x shr 16))^ and $1f) shl 3) or $30103;
+    (dest + B_24)^ := p1 and $FF;
+    (dest + G_24)^ := (p1 shr 8) and $FF;
+    (dest + R_24)^ := p1 shr 16;
+
     Inc(dest, 3);
     Inc(x, inc_source);
     Dec(count);
-    If count = 0 Then
-      Exit;
-  End;
-  
-  c := count Shr 2;
-  While c > 0 Do
-  Begin
-    p1 := (Pshort16(source) + (x Shr 16))^;
-    p2 := (Pshort16(source) + ((x + inc_source) Shr 16))^;
-    p3 := (Pshort16(source) + ((x + 2*inc_source) Shr 16))^;
-    p4 := (Pshort16(source) + ((x + 3*inc_source) Shr 16))^;
-
-    Pint32(dest + 0)^ := ((p2 And $001F) Shl 27) Or ((p1 And $F800) Shl 8) Or ((p1 And $07E0) Shl 5) Or ((p1 And $001F) Shl 3) Or $03030103;
-    Pint32(dest + 4)^ := ((p3 And $07E0) Shl 21) Or ((p3 And $001F) Shl 19) Or (p2 And $F800) Or ((p2 And $07E0) Shr 3) Or $01030301;
-    Pint32(dest + 8)^ := ((p4 And $F800) Shl 16) Or ((p4 And $07E0) Shl 13) Or ((p4 And $001F) Shl 11) Or ((p3 And $F800) Shr 8) Or $03010303;
-    
+    if count = 0 then
+      exit;
+  end;
+
+  c := count shr 2;
+  while c > 0 do
+  begin
+    p1 := (PUint16(source) + (x shr 16))^;
+    p2 := (PUint16(source) + ((x + inc_source) shr 16))^;
+    p3 := (PUint16(source) + ((x + 2*inc_source) shr 16))^;
+    p4 := (PUint16(source) + ((x + 3*inc_source) shr 16))^;
+
+    {$IFDEF FPC_LITTLE_ENDIAN}
+    PUint32(dest + 0)^ := ((p2 and $001F) shl 27) or ((p1 and $F800) shl 8) or ((p1 and $07E0) shl 5) or ((p1 and $001F) shl 3) or $03030103;
+    PUint32(dest + 4)^ := ((p3 and $07E0) shl 21) or ((p3 and $001F) shl 19) or (p2 and $F800) or ((p2 and $07E0) shr 3) or $01030301;
+    PUint32(dest + 8)^ := ((p4 and $F800) shl 16) or ((p4 and $07E0) shl 13) or ((p4 and $001F) shl 11) or ((p3 and $F800) shr 8) or $03010303;
+    {$ELSE FPC_LITTLE_ENDIAN}
+    PUint32(dest + 0)^ := ((p1 and $F800) shl 16) or ((p1 and $07E0) shl 13) or ((p1 and $001F) shl 11) or ((p2 and $F800) shr 8) or $03010303;
+    PUint32(dest + 4)^ := ((p2 and $07E0) shl 21) or ((p2 and $001F) shl 19) or (p3 and $F800) or ((p3 and $07E0) shr 3) or $01030301;
+    PUint32(dest + 8)^ := ((p3 and $001F) shl 27) or ((p4 and $F800) shl 8) or ((p4 and $07E0) shl 5) or ((p4 and $001F) shl 3) or $03030103;
+    {$ENDIF FPC_LITTLE_ENDIAN}
+
     Inc(x, 4*inc_source);
     Inc(dest, 12);
     Dec(c);
-  End;
-  
-  count := count And 3;
-  While count > 0 Do
-  Begin
-    p1 := (((Pshort16(source) + (x Shr 16))^ And $f800) Shl 8) Or
-          (((Pshort16(source) + (x Shr 16))^ And $7e0) Shl 5) Or
-          (((Pshort16(source) + (x Shr 16))^ And $1f) Shl 3) Or $30103;
-    Pshort16(dest)^ := p1 And $FFFF;
-    (dest + 2)^ := p1 Shr 16;
-    
+  end;
+
+  count := count and 3;
+  while count > 0 do
+  begin
+    p1 := (((PUint16(source) + (x shr 16))^ and $f800) shl 8) or
+          (((PUint16(source) + (x shr 16))^ and $7e0) shl 5) or
+          (((PUint16(source) + (x shr 16))^ and $1f) shl 3) or $30103;
+    (dest + B_24)^ := p1 and $FF;
+    (dest + G_24)^ := (p1 shr 8) and $FF;
+    (dest + R_24)^ := p1 shr 16;
+
     Inc(dest, 3);
     Inc(x, inc_source);
     Dec(count);
-  End;
-End;
-
-Procedure ConvertP_16rgb565_24bgr888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x : DWord;
-  p1, p2, p3, p4 : DWord;
-  c : DWord;
-
-Begin
+  end;
+end;
+
+procedure ConvertP_16rgb565_24bgr888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+  p1, p2, p3, p4: DWord;
+  c: DWord;
+begin
   x := 0;
-  While (PtrUInt(dest) And 3) <> 0 Do
-  Begin
-    p1 := (((Pshort16(source) + (x Shr 16))^ And $f800) Shr 8) Or
-          (((Pshort16(source) + (x Shr 16))^ And $7e0) Shl 5) Or
-          (((Pshort16(source) + (x Shr 16))^ And $1f) Shl 19) Or $30103;
-    Pshort16(dest)^ := p1 And $FFFF;
-    (dest + 2)^ := p1 Shr 16;
-    
+  while (PtrUInt(dest) and 3) <> 0 do
+  begin
+    p1 := (((PUint16(source) + (x shr 16))^ and $f800) shr 8) or
+          (((PUint16(source) + (x shr 16))^ and $7e0) shl 5) or
+          (((PUint16(source) + (x shr 16))^ and $1f) shl 19) or $30103;
+    (dest + B_24)^ := p1 and $FF;
+    (dest + G_24)^ := (p1 shr 8) and $FF;
+    (dest + R_24)^ := p1 shr 16;
+
     Inc(dest, 3);
     Inc(x, inc_source);
     Dec(count);
-    If count = 0 Then
-      Exit;
-  End;
-  
-  c := count Shr 2;
-  While c > 0 Do
-  Begin
-    p1 := (Pshort16(source) + (x Shr 16))^;
-    p2 := (Pshort16(source) + ((x + inc_source) Shr 16))^;
-    p3 := (Pshort16(source) + ((x + 2*inc_source) Shr 16))^;
-    p4 := (Pshort16(source) + ((x + 3*inc_source) Shr 16))^;
-
-    Pint32(dest + 0)^ := ((p2 And $F800) Shl 16) Or ((p1 And $001F) Shl 19) Or ((p1 And $07E0) Shl 5) Or ((p1 And $F800) Shr 8) Or $03030103;
-    Pint32(dest + 4)^ := ((p3 And $07E0) Shl 21) Or ((p3 And $F800) Shl 8) Or ((p2 And $001F) Shl 11) Or ((p2 And $07E0) Shr 3) Or $01030301;
-    Pint32(dest + 8)^ := ((p4 And $001F) Shl 27) Or ((p4 And $07E0) Shl 13) Or (p4 And $F800) Or ((p3 And $001F) Shl 3) Or $03010303;
-    
+    if count = 0 then
+      exit;
+  end;
+
+  c := count shr 2;
+  while c > 0 do
+  begin
+    p1 := (PUint16(source) + (x shr 16))^;
+    p2 := (PUint16(source) + ((x + inc_source) shr 16))^;
+    p3 := (PUint16(source) + ((x + 2*inc_source) shr 16))^;
+    p4 := (PUint16(source) + ((x + 3*inc_source) shr 16))^;
+
+    {$IFDEF FPC_LITTLE_ENDIAN}
+    PUint32(dest + 0)^ := ((p2 and $F800) shl 16) or ((p1 and $001F) shl 19) or ((p1 and $07E0) shl 5) or ((p1 and $F800) shr 8) or $03030103;
+    PUint32(dest + 4)^ := ((p3 and $07E0) shl 21) or ((p3 and $F800) shl 8) or ((p2 and $001F) shl 11) or ((p2 and $07E0) shr 3) or $01030301;
+    PUint32(dest + 8)^ := ((p4 and $001F) shl 27) or ((p4 and $07E0) shl 13) or (p4 and $F800) or ((p3 and $001F) shl 3) or $03010303;
+    {$ELSE FPC_LITTLE_ENDIAN}
+    PUint32(dest + 0)^ := ((p1 and $001F) shl 27) or ((p1 and $07E0) shl 13) or (p1 and $F800) or ((p2 and $001F) shl 3) or $03010303;
+    PUint32(dest + 4)^ := ((p2 and $07E0) shl 21) or ((p2 and $F800) shl 8) or ((p3 and $001F) shl 11) or ((p3 and $07E0) shr 3) or $01030301;
+    PUint32(dest + 8)^ := ((p3 and $F800) shl 16) or ((p4 and $001F) shl 19) or ((p4 and $07E0) shl 5) or ((p4 and $F800) shr 8) or $03030103;
+    {$ENDIF FPC_LITTLE_ENDIAN}
+
     Inc(x, 4*inc_source);
     Inc(dest, 12);
     Dec(c);
-  End;
-  
-  count := count And 3;
-  While count > 0 Do
-  Begin
-    p1 := (((Pshort16(source) + (x Shr 16))^ And $f800) Shr 8) Or
-          (((Pshort16(source) + (x Shr 16))^ And $7e0) Shl 5) Or
-          (((Pshort16(source) + (x Shr 16))^ And $1f) Shl 19) Or $30103;
-    Pshort16(dest)^ := p1 And $FFFF;
-    (dest + 2)^ := p1 Shr 16;
-    
+  end;
+
+  count := count and 3;
+  while count > 0 do
+  begin
+    p1 := (((PUint16(source) + (x shr 16))^ and $f800) shr 8) or
+          (((PUint16(source) + (x shr 16))^ and $7e0) shl 5) or
+          (((PUint16(source) + (x shr 16))^ and $1f) shl 19) or $30103;
+    (dest + B_24)^ := p1 and $FF;
+    (dest + G_24)^ := (p1 shr 8) and $FF;
+    (dest + R_24)^ := p1 shr 16;
+
     Inc(dest, 3);
     Inc(x, inc_source);
     Dec(count);
-  End;
-End;
-
-Procedure ConvertP_16rgb565_16bgr565_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x, c : DWord;
-  p : int32;
-
-Begin
+  end;
+end;
+
+procedure ConvertP_16rgb565_16bgr565_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x, c: DWord;
+  p: Uint32;
+begin
   x := 0;
-  { If we are not aligned to a dword, try and convert a single pixel }
-  If (PtrUInt(dest) And $3) <> 0 Then
-  Begin
+  { if we are not aligned to a dword, try and convert a single pixel }
+  if (PtrUInt(dest) and $3) <> 0 then
+  begin
     { Swap r and b, leave g untouched }
-    Pshort16(dest)^ := ((Pshort16(source) + (x Shr 16))^ Shr 11) Or
-                       ((Pshort16(source) + (x Shr 16))^ And $7e0) Or
-                       (((Pshort16(source) + (x Shr 16))^ Shl 11) And $f800);
+    PUint16(dest)^ := ((PUint16(source) + (x shr 16))^ shr 11) or
+                       ((PUint16(source) + (x shr 16))^ and $7e0) or
+                       (((PUint16(source) + (x shr 16))^ shl 11) and $f800);
     Inc(x, inc_source);
     Inc(dest, 2);
     Dec(count);
-  End;
+  end;
 
-  c := count Shr 1;
-  While c <> 0 Do
-  Begin
+  c := count shr 1;
+  while c <> 0 do
+  begin
     Dec(c);
 
     { Swap r and b, leave g untouched }
-    p := ((Pshort16(source) + (x Shr 16))^ Shr 11) Or
-         ((Pshort16(source) + (x Shr 16))^ And $7e0) Or
-         (((Pshort16(source) + (x Shr 16))^ Shl 11) And $f800);
+    p := (((PUint16(source) + (x shr 16))^ shr 11) or
+          ((PUint16(source) + (x shr 16))^ and $7e0) or
+          (((PUint16(source) + (x shr 16))^ shl 11) and $f800)) shl DWORD_SMALLINT0_SHL;
     Inc(x, inc_source);
 
-    p := p Or ((((Pshort16(source) + (x Shr 16))^ Shr 11) Or
-                ((Pshort16(source) + (x Shr 16))^ And $7e0) Or
-                (((Pshort16(source) + (x Shr 16))^ Shl 11) And $f800)) Shl 16);
+    p := p or ((((PUint16(source) + (x shr 16))^ shr 11) or
+                ((PUint16(source) + (x shr 16))^ and $7e0) or
+                (((PUint16(source) + (x shr 16))^ shl 11) and $f800)) shl DWORD_SMALLINT1_SHL);
     Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
     Inc(dest, 4);
-  End;
-
-  If (count And 1) <> 0 Then
-    Pshort16(dest)^ := ((Pshort16(source) + (x Shr 16))^ Shr 11) Or
-                       ((Pshort16(source) + (x Shr 16))^ And $7e0) Or
-                       (((Pshort16(source) + (x Shr 16))^ Shl 11) And $f800);
-End;
-
-Procedure ConvertP_16rgb565_16rgb555_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x, c : DWord;
-  p : int32;
-
-Begin
+  end;
+
+  if (count and 1) <> 0 then
+    PUint16(dest)^ := ((PUint16(source) + (x shr 16))^ shr 11) or
+                       ((PUint16(source) + (x shr 16))^ and $7e0) or
+                       (((PUint16(source) + (x shr 16))^ shl 11) and $f800);
+end;
+
+procedure ConvertP_16rgb565_16rgb555_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x, c: DWord;
+  p: Uint32;
+begin
   x := 0;
-  { If we are not aligned to a dword, try and convert a single pixel }
-  If (PtrUInt(dest) And $3) <> 0 Then
-  Begin
-    Pshort16(dest)^ := (((Pshort16(source) + (x Shr 16))^ And $f800) Shr 1) Or
-                       (((Pshort16(source) + (x Shr 16))^ And $7c0) Shr 1) Or
-                       ((Pshort16(source) + (x Shr 16))^ And $1f);
+  { if we are not aligned to a dword, try and convert a single pixel }
+  if (PtrUInt(dest) and $3) <> 0 then
+  begin
+    PUint16(dest)^ := (((PUint16(source) + (x shr 16))^ and $f800) shr 1) or
+                       (((PUint16(source) + (x shr 16))^ and $7c0) shr 1) or
+                       ((PUint16(source) + (x shr 16))^ and $1f);
     Inc(dest, 2);
     Inc(x, inc_source);
     Dec(count);
-  End;
+  end;
 
-  c := count Shr 1;
-  While c <> 0 Do
-  Begin
+  c := count shr 1;
+  while c <> 0 do
+  begin
     Dec(c);
 
     { Leave blue untouched, mask red and shift by one, mask green and shift
       by one }
-    p := (((Pshort16(source) + (x Shr 16))^ And $f800) Shr 1) Or
-         (((Pshort16(source) + (x Shr 16))^ And $7c0) Shr 1) Or
-         ((Pshort16(source) + (x Shr 16))^ And $1f);
+    p := ((((PUint16(source) + (x shr 16))^ and $f800) shr 1) or
+          (((PUint16(source) + (x shr 16))^ and $7c0) shr 1) or
+          ((PUint16(source) + (x shr 16))^ and $1f)) shl DWORD_SMALLINT0_SHL;
     Inc(x, inc_source);
 
-    p := p Or (((((Pshort16(source) + (x Shr 16))^ And $f800) Shr 1) Or
-                (((Pshort16(source) + (x Shr 16))^ And $7c0) Shr 1) Or
-                ((Pshort16(source) + (x Shr 16))^ And $1f)) Shl 16);
+    p := p or (((((PUint16(source) + (x shr 16))^ and $f800) shr 1) or
+                (((PUint16(source) + (x shr 16))^ and $7c0) shr 1) or
+                ((PUint16(source) + (x shr 16))^ and $1f)) shl DWORD_SMALLINT1_SHL);
     Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
     Inc(dest, 4);
-  End;
-
-  If (count And 1) <> 0 Then
-    Pshort16(dest)^ := (((Pshort16(source) + (x Shr 16))^ And $f800) Shr 1) Or
-                       (((Pshort16(source) + (x Shr 16))^ And $7c0) Shr 1) Or
-                       ((Pshort16(source) + (x Shr 16))^ And $1f);
-End;
-
-Procedure ConvertP_16rgb565_16bgr555_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x, c : DWord;
-  p : int32;
-
-Begin
+  end;
+
+  if (count and 1) <> 0 then
+    PUint16(dest)^ := (((PUint16(source) + (x shr 16))^ and $f800) shr 1) or
+                       (((PUint16(source) + (x shr 16))^ and $7c0) shr 1) or
+                       ((PUint16(source) + (x shr 16))^ and $1f);
+end;
+
+procedure ConvertP_16rgb565_16bgr555_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x, c: DWord;
+  p: Uint32;
+begin
   x := 0;
-  { If we are not aligned to a dword, try and convert a single pixel }
-  If (PtrUInt(dest) And $3) <> 0 Then
-  Begin
-    Pshort16(dest)^ := (((Pshort16(source) + (x Shr 16))^ And $f800) Shr 11) Or
-                       (((Pshort16(source) + (x Shr 16))^ And $7c0) Shr 1) Or
-                       (((Pshort16(source) + (x Shr 16))^ And $1f) Shl 10);
+  { if we are not aligned to a dword, try and convert a single pixel }
+  if (PtrUInt(dest) and $3) <> 0 then
+  begin
+    PUint16(dest)^ := (((PUint16(source) + (x shr 16))^ and $f800) shr 11) or
+                       (((PUint16(source) + (x shr 16))^ and $7c0) shr 1) or
+                       (((PUint16(source) + (x shr 16))^ and $1f) shl 10);
     Inc(dest, 2);
     Inc(x, inc_source);
     Dec(count);
-  End;
+  end;
 
-  c := count Shr 1;
-  While c <> 0 Do
-  Begin
+  c := count shr 1;
+  while c <> 0 do
+  begin
     Dec(c);
 
-    p := (((Pshort16(source) + (x Shr 16))^ And $f800) Shr 11) Or
-         (((Pshort16(source) + (x Shr 16))^ And $7c0) Shr 1) Or
-         (((Pshort16(source) + (x Shr 16))^ And $1f) Shl 10);
+    p := ((((PUint16(source) + (x shr 16))^ and $f800) shr 11) or
+          (((PUint16(source) + (x shr 16))^ and $7c0) shr 1) or
+          (((PUint16(source) + (x shr 16))^ and $1f) shl 10)) shl DWORD_SMALLINT0_SHL;
     Inc(x, inc_source);
 
-    p := p Or (((((Pshort16(source) + (x Shr 16))^ And $f800) Shr 11) Or
-                (((Pshort16(source) + (x Shr 16))^ And $7c0) Shr 1) Or
-                (((Pshort16(source) + (x Shr 16))^ And $1f) Shl 10)) Shl 16);
+    p := p or (((((PUint16(source) + (x shr 16))^ and $f800) shr 11) or
+                (((PUint16(source) + (x shr 16))^ and $7c0) shr 1) or
+                (((PUint16(source) + (x shr 16))^ and $1f) shl 10)) shl DWORD_SMALLINT1_SHL);
     Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
     Inc(dest, 4);
-  End;
-
-  If (count And 1) <> 0 Then
-    Pshort16(dest)^ := (((Pshort16(source) + (x Shr 16))^ And $f800) Shr 11) Or
-                       (((Pshort16(source) + (x Shr 16))^ And $7c0) Shr 1) Or
-                       (((Pshort16(source) + (x Shr 16))^ And $1f) Shl 10);
-End;
-
-Procedure ConvertP_16rgb565_8rgb332_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x, c : DWord;
-  p : int32;
-
-Begin
+  end;
+
+  if (count and 1) <> 0 then
+    PUint16(dest)^ := (((PUint16(source) + (x shr 16))^ and $f800) shr 11) or
+                       (((PUint16(source) + (x shr 16))^ and $7c0) shr 1) or
+                       (((PUint16(source) + (x shr 16))^ and $1f) shl 10);
+end;
+
+procedure ConvertP_16rgb565_8rgb332_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x, c: DWord;
+  p: Uint32;
+begin
   x := 0;
 
   { Write single pixels until the destination address is aligned mod 4 }
-  While (PtrUInt(dest) And $3) <> 0 Do
-  Begin
-    dest^ := (((Pshort16(source) + (x Shr 16))^ Shr 8) And $e0) Or
-             (((Pshort16(source) + (x Shr 16))^ Shr 6) And $1c) Or
-             (((Pshort16(source) + (x Shr 16))^ Shr 3) And $3);
+  while (PtrUInt(dest) and $3) <> 0 do
+  begin
+    dest^ := (((PUint16(source) + (x shr 16))^ shr 8) and $e0) or
+             (((PUint16(source) + (x shr 16))^ shr 6) and $1c) or
+             (((PUint16(source) + (x shr 16))^ shr 3) and $3);
     Inc(x, inc_source);
     Inc(dest);
     Dec(count);
-    If count = 0 Then
-      Exit;
-  End;
+    if count = 0 then
+      exit;
+  end;
 
 
   {* Write blocks of four pixels now }
-  c := count Shr 2;
-  While c <> 0 Do
-  Begin
+  c := count shr 2;
+  while c <> 0 do
+  begin
     Dec(c);
-    p := (((Pshort16(source) + (x Shr 16))^ Shr 8) And $e0) Or
-         (((Pshort16(source) + (x Shr 16))^ Shr 6) And $1c) Or
-         (((Pshort16(source) + (x Shr 16))^ Shr 3) And $3);
+    p := ((((PUint16(source) + (x shr 16))^ shr 8) and $e0) or
+          (((PUint16(source) + (x shr 16))^ shr 6) and $1c) or
+          (((PUint16(source) + (x shr 16))^ shr 3) and $3)) shl DWORD_BYTE0_SHL;
     Inc(x, inc_source);
 
-    p := p Or
-      (((((Pshort16(source) + (x Shr 16))^ Shr 8) And $e0) Or
-        (((Pshort16(source) + (x Shr 16))^ Shr 6) And $1c) Or
-        (((Pshort16(source) + (x Shr 16))^ Shr 3) And $3)) Shl 8);
+    p := p or
+      (((((PUint16(source) + (x shr 16))^ shr 8) and $e0) or
+        (((PUint16(source) + (x shr 16))^ shr 6) and $1c) or
+        (((PUint16(source) + (x shr 16))^ shr 3) and $3)) shl DWORD_BYTE1_SHL);
     Inc(x, inc_source);
 
-    p := p Or
-      (((((Pshort16(source) + (x Shr 16))^ Shr 8) And $e0) Or
-        (((Pshort16(source) + (x Shr 16))^ Shr 6) And $1c) Or
-        (((Pshort16(source) + (x Shr 16))^ Shr 3) And $3)) Shl 16);
+    p := p or
+      (((((PUint16(source) + (x shr 16))^ shr 8) and $e0) or
+        (((PUint16(source) + (x shr 16))^ shr 6) and $1c) or
+        (((PUint16(source) + (x shr 16))^ shr 3) and $3)) shl DWORD_BYTE2_SHL);
     Inc(x, inc_source);
 
-    p := p Or
-      (((((Pshort16(source) + (x Shr 16))^ Shr 8) And $e0) Or
-        (((Pshort16(source) + (x Shr 16))^ Shr 6) And $1c) Or
-        (((Pshort16(source) + (x Shr 16))^ Shr 3) And $3)) Shl 24);
+    p := p or
+      (((((PUint16(source) + (x shr 16))^ shr 8) and $e0) or
+        (((PUint16(source) + (x shr 16))^ shr 6) and $1c) or
+        (((PUint16(source) + (x shr 16))^ shr 3) and $3)) shl DWORD_BYTE3_SHL);
     Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
 
     Inc(dest, 4);
-  End;
+  end;
 
   { Write up to three trailing pixels }
-  c := count And $3;
-  While c <> 0 Do
-  Begin
+  c := count and $3;
+  while c <> 0 do
+  begin
     Dec(c);
-    dest^ := (((Pshort16(source) + (x Shr 16))^ Shr 8) And $e0) Or
-             (((Pshort16(source) + (x Shr 16))^ Shr 6) And $1c) Or
-             (((Pshort16(source) + (x Shr 16))^ Shr 3) And $3);
+    dest^ := (((PUint16(source) + (x shr 16))^ shr 8) and $e0) or
+             (((PUint16(source) + (x shr 16))^ shr 6) and $1c) or
+             (((PUint16(source) + (x shr 16))^ shr 3) and $3);
     Inc(x, inc_source);
     Inc(dest);
-  End;
-End;
+  end;
+end;

+ 499 - 523
packages/hermes/src/p_24.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -33,103 +45,93 @@
 
   ------------------------------------------------------------------------- }
 { FROM 24 BIT ROUTINES }
-Procedure ConvertP_24rgb888_32rgb888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_block : int32;
-
-Begin
-  Repeat
-    d_block := ((source + R_24)^ Shl 16) Or
-               ((source + G_24)^ Shl 8) Or
+procedure ConvertP_24rgb888_32rgb888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_block: Uint32;
+begin
+  repeat
+    d_block := ((source + R_24)^ shl 16) or
+               ((source + G_24)^ shl 8) or
                (source + B_24)^;
-    Pint32(dest)^ := d_block;
+    PUint32(dest)^ := d_block;
     Inc(dest, 4);
     Inc(source, 3);
     Dec(count);
-  Until count = 0;
-End;
-
-Procedure ConvertP_24rgb888_32bgr888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_block : int32;
-
-Begin
-  Repeat
-    d_block := (source + R_24)^ Or
-               ((source + G_24)^ Shl 8) Or
-               ((source + B_24)^ Shl 16);
-    Pint32(dest)^ := d_block;
+  until count = 0;
+end;
+
+procedure ConvertP_24rgb888_32bgr888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_block: Uint32;
+begin
+  repeat
+    d_block := (source + R_24)^ or
+               ((source + G_24)^ shl 8) or
+               ((source + B_24)^ shl 16);
+    PUint32(dest)^ := d_block;
     Inc(dest, 4);
     Inc(source, 3);
     Dec(count);
-  Until count = 0;
-End;
-
-Procedure ConvertP_24rgb888_32rgba888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_block : int32;
-
-Begin
-  Repeat
-    d_block := ((source + R_24)^ Shl 24) Or
-               ((source + G_24)^ Shl 16) Or
-               ((source + B_24)^ Shl 8) Or $ff;
-    Pint32(dest)^ := d_block;
+  until count = 0;
+end;
+
+procedure ConvertP_24rgb888_32rgba888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_block: Uint32;
+begin
+  repeat
+    d_block := ((source + R_24)^ shl 24) or
+               ((source + G_24)^ shl 16) or
+               ((source + B_24)^ shl 8) or $ff;
+    PUint32(dest)^ := d_block;
     Inc(dest, 4);
     Inc(source, 3);
     Dec(count);
-  Until count = 0;
-End;
-
-Procedure ConvertP_24rgb888_32bgra888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_block : int32;
-
-Begin
-  Repeat
-    d_block := ((source + R_24)^ Shl 8) Or
-               ((source + G_24)^ Shl 16) Or
-               ((source + B_24)^ Shl 24) Or $ff;
-    Pint32(dest)^ := d_block;
+  until count = 0;
+end;
+
+procedure ConvertP_24rgb888_32bgra888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_block: Uint32;
+begin
+  repeat
+    d_block := ((source + R_24)^ shl 8) or
+               ((source + G_24)^ shl 16) or
+               ((source + B_24)^ shl 24) or $ff;
+    PUint32(dest)^ := d_block;
     Inc(dest, 4);
     Inc(source, 3);
     Dec(count);
-  Until count = 0;
-End;
-
-Procedure ConvertP_24rgb888_24bgr888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_pix1, d_pix2, d_pix3 : int32;
-  c_pix1, c_pix2, c_pix3 : Pchar8;
-  c : DWord;
-  tmp : char8;
-
-Begin
-  While ((PtrUInt(dest) And 3) <> 0) And (count > 0) Do
-  Begin
+  until count = 0;
+end;
+
+procedure ConvertP_24rgb888_24bgr888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_pix1, d_pix2, d_pix3: Uint32;
+  c_pix1, c_pix2, c_pix3: PUint8;
+  c: DWord;
+  tmp: Uint8;
+begin
+  while ((PtrUInt(dest) and 3) <> 0) and (count > 0) do
+  begin
     (dest + 0)^ := (source + 2)^;
     (dest + 1)^ := (source + 1)^;
     (dest + 2)^ := (source + 0)^;
     Dec(count);
     Inc(dest, 3);
     Inc(source, 3);
-  End;
-  
+  end;
+
   c_pix1 := @d_pix1;
   c_pix2 := @d_pix2;
   c_pix3 := @d_pix3;
 
-  c := count Shr 2;
-  While c > 0 Do
-  Begin
-    d_pix1 := Pint32(source)^;
-    d_pix2 := Pint32(source + 4)^;
-    d_pix3 := Pint32(source + 8)^;
+  c := count shr 2;
+  while c > 0 do
+  begin
+    d_pix1 := PUint32(source)^;
+    d_pix2 := PUint32(source + 4)^;
+    d_pix3 := PUint32(source + 8)^;
 
     { Swap R and B in all three pixels }
     tmp := (c_pix1 + 0)^; (c_pix1 + 0)^ := (c_pix1 + 2)^; (c_pix1 + 2)^ := tmp;
@@ -137,555 +139,529 @@ Begin
     tmp := (c_pix2 + 2)^; (c_pix2 + 2)^ := (c_pix3 + 0)^; (c_pix3 + 0)^ := tmp;
     tmp := (c_pix3 + 1)^; (c_pix3 + 1)^ := (c_pix3 + 3)^; (c_pix3 + 3)^ := tmp;
 
-    Pint32(dest)^ := d_pix1;
-    Pint32(dest + 4)^ := d_pix2;
-    Pint32(dest + 8)^ := d_pix3;
+    PUint32(dest)^ := d_pix1;
+    PUint32(dest + 4)^ := d_pix2;
+    PUint32(dest + 8)^ := d_pix3;
     Inc(dest, 12);
     Inc(source, 12);
     Dec(c);
-  End;
+  end;
 
-  count := count And $3;
-  While count > 0 Do
-  Begin
+  count := count and $3;
+  while count > 0 do
+  begin
     (dest + 0)^ := (source + 2)^;
     (dest + 1)^ := (source + 1)^;
     (dest + 2)^ := (source + 0)^;
     Dec(count);
     Inc(dest, 3);
     Inc(source, 3);
-  End;
-End;
-
-Procedure ConvertP_24rgb888_16rgb565(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_block : int32;
-  i : DWord;
-
-Begin
-  For i := 0 To (count Shr 1) - 1 Do
-  Begin
-    d_block := (((source + R_24)^ Shl 8) And $f800) Or
-               (((source + G_24)^ Shl 3) And $7e0) Or
-               (((source + B_24)^ Shr 3) And $1f);
-
-    d_block := d_block Or
-             (((((source + R_24 + 3)^ Shl 8) And $f800) Or
-               (((source + G_24 + 3)^ Shl 3) And $7e0) Or
-               (((source + B_24 + 3)^ Shr 3) And $1f)) Shl 16);
-
-    Pint32(dest)^ := d_block;
+  end;
+end;
+
+procedure ConvertP_24rgb888_16rgb565(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_block: Uint32;
+  i: DWord;
+begin
+  for i := 0 to (count shr 1) - 1 do
+  begin
+    d_block := ((((source + R_24)^ shl 8) and $f800) or
+                (((source + G_24)^ shl 3) and $7e0) or
+                (((source + B_24)^ shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
+
+    d_block := d_block or
+             (((((source + R_24 + 3)^ shl 8) and $f800) or
+               (((source + G_24 + 3)^ shl 3) and $7e0) or
+               (((source + B_24 + 3)^ shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
+
+    PUint32(dest)^ := d_block;
     Inc(source, 6);
     Inc(dest, 4);
-  End;
-
-  If (count And 1) <> 0 Then
-  Begin
-    d_block := (((source + R_24)^ Shl 8) And $f800) Or
-               (((source + G_24)^ Shl 3) And $7e0) Or
-               (((source + B_24)^ Shr 3) And $1f);
-
-    Pshort16(dest)^ := d_block;
-  End;
-End;
-
-Procedure ConvertP_24rgb888_16bgr565(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_block : int32;
-  i : DWord;
-
-Begin
-  For i := 0 To (count Shr 1) - 1 Do
-  Begin
-    d_block := (((source + R_24)^ Shr 3) And $1f) Or
-               (((source + G_24)^ Shl 3) And $7e0) Or
-               (((source + B_24)^ Shl 8) And $f800);
-
-    d_block := d_block Or
-             (((((source + R_24 + 3)^ Shr 3) And $1f) Or
-               (((source + G_24 + 3)^ Shl 3) And $7e0) Or
-               (((source + B_24 + 3)^ Shl 8) And $f800)) Shl 16);
-
-    Pint32(dest)^ := d_block;
+  end;
+
+  if (count and 1) <> 0 then
+  begin
+    d_block := (((source + R_24)^ shl 8) and $f800) or
+               (((source + G_24)^ shl 3) and $7e0) or
+               (((source + B_24)^ shr 3) and $1f);
+
+    PUint16(dest)^ := d_block;
+  end;
+end;
+
+procedure ConvertP_24rgb888_16bgr565(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_block: Uint32;
+  i: DWord;
+begin
+  for i := 0 to (count shr 1) - 1 do
+  begin
+    d_block := ((((source + R_24)^ shr 3) and $1f) or
+                (((source + G_24)^ shl 3) and $7e0) or
+                (((source + B_24)^ shl 8) and $f800)) shl DWORD_SMALLINT0_SHL;
+
+    d_block := d_block or
+             (((((source + R_24 + 3)^ shr 3) and $1f) or
+               (((source + G_24 + 3)^ shl 3) and $7e0) or
+               (((source + B_24 + 3)^ shl 8) and $f800)) shl DWORD_SMALLINT1_SHL);
+
+    PUint32(dest)^ := d_block;
     Inc(source, 6);
     Inc(dest, 4);
-  End;
-
-  If (count And 1) <> 0 Then
-  Begin
-    d_block := (((source + R_24)^ Shr 3) And $1f) Or
-               (((source + G_24)^ Shl 3) And $7e0) Or
-               (((source + B_24)^ Shl 8) And $f800);
-
-    Pshort16(dest)^ := d_block;
-  End;
-End;
-
-Procedure ConvertP_24rgb888_16rgb555(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_block : int32;
-  i : DWord;
-
-Begin
-  For i := 0 To (count Shr 1) - 1 Do
-  Begin
-    d_block := (((source + R_24)^ Shl 7) And $7c00) Or
-               (((source + G_24)^ Shl 2) And $3e0) Or
-               (((source + B_24)^ Shr 3) And $1f);
-
-    d_block := d_block Or
-             (((((source + R_24 + 3)^ Shl 7) And $7c00) Or
-               (((source + G_24 + 3)^ Shl 2) And $3e0) Or
-               (((source + B_24 + 3)^ Shr 3) And $1f)) Shl 16);
-
-    Pint32(dest)^ := d_block;
+  end;
+
+  if (count and 1) <> 0 then
+  begin
+    d_block := (((source + R_24)^ shr 3) and $1f) or
+               (((source + G_24)^ shl 3) and $7e0) or
+               (((source + B_24)^ shl 8) and $f800);
+
+    PUint16(dest)^ := d_block;
+  end;
+end;
+
+procedure ConvertP_24rgb888_16rgb555(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_block: Uint32;
+  i: DWord;
+begin
+  for i := 0 to (count shr 1) - 1 do
+  begin
+    d_block := ((((source + R_24)^ shl 7) and $7c00) or
+                (((source + G_24)^ shl 2) and $3e0) or
+                (((source + B_24)^ shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
+
+    d_block := d_block or
+             (((((source + R_24 + 3)^ shl 7) and $7c00) or
+               (((source + G_24 + 3)^ shl 2) and $3e0) or
+               (((source + B_24 + 3)^ shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
+
+    PUint32(dest)^ := d_block;
     Inc(source, 6);
     Inc(dest, 4);
-  End;
-
-  If (count And 1) <> 0 Then
-  Begin
-    d_block := (((source + R_24)^ Shl 7) And $7c00) Or
-               (((source + G_24)^ Shl 2) And $3e0) Or
-               (((source + B_24)^ Shr 3) And $1f);
-
-    Pshort16(dest)^ := d_block;
-  End;
-End;
-
-Procedure ConvertP_24rgb888_16bgr555(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_block : int32;
-  i : DWord;
-
-Begin
-  For i := 0 To (count Shr 1) - 1 Do
-  Begin
-    d_block := (((source + R_24)^ Shr 3) And $1f) Or
-               (((source + G_24)^ Shl 2) And $3e0) Or
-               (((source + B_24)^ Shl 7) And $7c00);
-
-    d_block := d_block Or
-             (((((source + R_24 + 3)^ Shr 3) And $1f) Or
-               (((source + G_24 + 3)^ Shl 2) And $3e0) Or
-               (((source + B_24 + 3)^ Shl 7) And $7c00)) Shl 16);
-
-    Pint32(dest)^ := d_block;
+  end;
+
+  if (count and 1) <> 0 then
+  begin
+    d_block := (((source + R_24)^ shl 7) and $7c00) or
+               (((source + G_24)^ shl 2) and $3e0) or
+               (((source + B_24)^ shr 3) and $1f);
+
+    PUint16(dest)^ := d_block;
+  end;
+end;
+
+procedure ConvertP_24rgb888_16bgr555(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_block: Uint32;
+  i: DWord;
+begin
+  for i := 0 to (count shr 1) - 1 do
+  begin
+    d_block := ((((source + R_24)^ shr 3) and $1f) or
+                (((source + G_24)^ shl 2) and $3e0) or
+                (((source + B_24)^ shl 7) and $7c00)) shl DWORD_SMALLINT0_SHL;
+
+    d_block := d_block or
+             (((((source + R_24 + 3)^ shr 3) and $1f) or
+               (((source + G_24 + 3)^ shl 2) and $3e0) or
+               (((source + B_24 + 3)^ shl 7) and $7c00)) shl DWORD_SMALLINT1_SHL);
+
+    PUint32(dest)^ := d_block;
     Inc(source, 6);
     Inc(dest, 4);
-  End;
+  end;
 
-  If (count And 1) <> 0 Then
-  Begin
-    d_block := (((source + R_24)^ Shr 3) And $1f) Or
-               (((source + G_24)^ Shl 2) And $3e0) Or
-               (((source + B_24)^ Shl 7) And $7c00);
+  if (count and 1) <> 0 then
+  begin
+    d_block := (((source + R_24)^ shr 3) and $1f) or
+               (((source + G_24)^ shl 2) and $3e0) or
+               (((source + B_24)^ shl 7) and $7c00);
 
-    Pshort16(dest)^ := d_block;
-  End;
-End;
+    PUint16(dest)^ := d_block;
+  end;
+end;
 
 { optimise me !! }
 
-Procedure ConvertP_24rgb888_8rgb332(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  r, g, b : int32;
-  i : DWord;
-
-Begin
-  For i := 0 To count - 1 Do
-  Begin
-    r := (source + R_24)^ And $e0;
-    g := ((source + G_24)^ Shr 3) And $1c;
-    b := ((source + B_24)^ Shr 6) And $3;
-
-    dest^ := r Or g Or b;
+procedure ConvertP_24rgb888_8rgb332(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  r, g, b: Uint32;
+  i: DWord;
+begin
+  for i := 0 to count - 1 do
+  begin
+    r := (source + R_24)^ and $e0;
+    g := ((source + G_24)^ shr 3) and $1c;
+    b := ((source + B_24)^ shr 6) and $3;
+
+    dest^ := r or g or b;
     Inc(source, 3);
     Inc(dest);
-  End;
-End;
+  end;
+end;
 
 { -------------------------------------------------------------------------
 
                              STRETCH CONVERTERS
 
   ------------------------------------------------------------------------- }
-Procedure ConvertP_24rgb888_32rgb888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x : DWord;
-
-Begin
+procedure ConvertP_24rgb888_32rgb888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+begin
   x := 0;
-  Repeat
-    Pint32(dest)^ := ((source + R_24)^ Shl 16) Or
-                     ((source + G_24)^ Shl 8) Or
+  repeat
+    PUint32(dest)^ := ((source + R_24)^ shl 16) or
+                     ((source + G_24)^ shl 8) or
                       (source + B_24)^;
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
     Inc(dest, 4);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
-Procedure ConvertP_24rgb888_32bgr888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x : DWord;
-
-Begin
+procedure ConvertP_24rgb888_32bgr888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+begin
   x := 0;
-  Repeat
-    Pint32(dest)^ :=  (source + R_24)^ Or
-                     ((source + G_24)^ Shl 8) Or
-                     ((source + B_24)^ Shl 16);
+  repeat
+    PUint32(dest)^ :=  (source + R_24)^ or
+                     ((source + G_24)^ shl 8) or
+                     ((source + B_24)^ shl 16);
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
     Inc(dest, 4);
     Dec(count);
-  Until count = 0;
-End;
-
-Procedure ConvertP_24rgb888_32rgba888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
+  until count = 0;
+end;
 
-Var
-  x : DWord;
-
-Begin
+procedure ConvertP_24rgb888_32rgba888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+begin
   x := 0;
-  Repeat
-    Pint32(dest)^ := ((((source + R_24)^ Shl 16) Or
-                       ((source + G_24)^ Shl 8) Or
-                        (source + B_24)^) Shl 8) Or $FF;
+  repeat
+    PUint32(dest)^ := ((((source + R_24)^ shl 16) or
+                       ((source + G_24)^ shl 8) or
+                        (source + B_24)^) shl 8) or $FF;
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
     Inc(dest, 4);
     Dec(count);
-  Until count = 0;
-End;
-
-Procedure ConvertP_24rgb888_32bgra888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
+  until count = 0;
+end;
 
-Var
-  x : DWord;
-
-Begin
+procedure ConvertP_24rgb888_32bgra888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+begin
   x := 0;
-  Repeat
-    Pint32(dest)^ :=  (((source + R_24)^ Or
-                       ((source + G_24)^ Shl 8) Or
-                       ((source + B_24)^ Shl 16)) Shl 8) Or $FF;
+  repeat
+    PUint32(dest)^ :=  (((source + R_24)^ or
+                       ((source + G_24)^ shl 8) or
+                       ((source + B_24)^ shl 16)) shl 8) or $FF;
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
     Inc(dest, 4);
     Dec(count);
-  Until count = 0;
-End;
-
-Procedure ConvertP_24rgb888_24bgr888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x : int32;
+  until count = 0;
+end;
 
-Begin
+procedure ConvertP_24rgb888_24bgr888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: Uint32;
+begin
   x := 0;
-  Repeat
+  repeat
     (dest + 0)^ := (source + 2)^;
     (dest + 1)^ := (source + 1)^;
     (dest + 2)^ := (source + 0)^;
 
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
     Inc(dest, 3);
     Dec(count);
-  Until count = 0;
-End;
-
-Procedure ConvertP_24rgb888_16rgb565_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_block : int32;
-  x : DWord;
-  c : DWord;
-
-Begin
+  until count = 0;
+end;
+
+procedure ConvertP_24rgb888_16rgb565_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_block: Uint32;
+  x: DWord;
+  c: DWord;
+begin
   x := 0;
-  If (PtrUInt(dest) And 3) <> 0 Then
-  Begin
-    d_block := (((source + R_24)^ Shl 8) And $f800) Or
-               (((source + G_24)^ Shl 3) And $7e0) Or
-               (((source + B_24)^ Shr 3) And $1f);
+  if (PtrUInt(dest) and 3) <> 0 then
+  begin
+    d_block := (((source + R_24)^ shl 8) and $f800) or
+               (((source + G_24)^ shl 3) and $7e0) or
+               (((source + B_24)^ shr 3) and $1f);
 
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
 
-    Pshort16(dest)^ := d_block;
+    PUint16(dest)^ := d_block;
     Inc(dest, 2);
-  End;
-  c := count Shr 1;
-  While c > 0 Do
-  Begin
-    d_block := (((source + R_24)^ Shl 8) And $f800) Or
-               (((source + G_24)^ Shl 3) And $7e0) Or
-               (((source + B_24)^ Shr 3) And $1f);
+    Dec(count);
+  end;
+  c := count shr 1;
+  while c > 0 do
+  begin
+    d_block := ((((source + R_24)^ shl 8) and $f800) or
+                (((source + G_24)^ shl 3) and $7e0) or
+                (((source + B_24)^ shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
-
-    d_block := d_block Or
-             (((((source + R_24)^ Shl 8) And $f800) Or
-               (((source + G_24)^ Shl 3) And $7e0) Or
-               (((source + B_24)^ Shr 3) And $1f)) Shl 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
+
+    d_block := d_block or
+             (((((source + R_24)^ shl 8) and $f800) or
+               (((source + G_24)^ shl 3) and $7e0) or
+               (((source + B_24)^ shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
 
-    Pint32(dest)^ := d_block;
+    PUint32(dest)^ := d_block;
     Inc(dest, 4);
     Dec(c);
-  End;
-
-  If (count And 1) <> 0 Then
-  Begin
-    d_block := (((source + R_24)^ Shl 8) And $f800) Or
-               (((source + G_24)^ Shl 3) And $7e0) Or
-               (((source + B_24)^ Shr 3) And $1f);
-
-    Pshort16(dest)^ := d_block;
-  End;
-End;
-
-Procedure ConvertP_24rgb888_16bgr565_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_block : int32;
-  x : DWord;
-  c : DWord;
-
-Begin
+  end;
+
+  if (count and 1) <> 0 then
+  begin
+    d_block := (((source + R_24)^ shl 8) and $f800) or
+               (((source + G_24)^ shl 3) and $7e0) or
+               (((source + B_24)^ shr 3) and $1f);
+
+    PUint16(dest)^ := d_block;
+  end;
+end;
+
+procedure ConvertP_24rgb888_16bgr565_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_block: Uint32;
+  x: DWord;
+  c: DWord;
+begin
   x := 0;
-  If (PtrUInt(dest) And 3) <> 0 Then
-  Begin
-    d_block := (((source + R_24)^ Shr 3) And $1f) Or
-               (((source + G_24)^ Shl 3) And $7e0) Or
-               (((source + B_24)^ Shl 8) And $f800);
+  if (PtrUInt(dest) and 3) <> 0 then
+  begin
+    d_block := (((source + R_24)^ shr 3) and $1f) or
+               (((source + G_24)^ shl 3) and $7e0) or
+               (((source + B_24)^ shl 8) and $f800);
 
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
 
-    Pshort16(dest)^ := d_block;
+    PUint16(dest)^ := d_block;
     Inc(dest, 2);
-  End;
-  c := count Shr 1;
-  While c > 0 Do
-  Begin
-    d_block := (((source + R_24)^ Shr 3) And $1f) Or
-               (((source + G_24)^ Shl 3) And $7e0) Or
-               (((source + B_24)^ Shl 8) And $f800);
+    Dec(count);
+  end;
+  c := count shr 1;
+  while c > 0 do
+  begin
+    d_block := ((((source + R_24)^ shr 3) and $1f) or
+                (((source + G_24)^ shl 3) and $7e0) or
+                (((source + B_24)^ shl 8) and $f800)) shl DWORD_SMALLINT0_SHL;
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
-
-    d_block := d_block Or
-              (((((source + R_24)^ Shr 3) And $1f) Or
-                (((source + G_24)^ Shl 3) And $7e0) Or
-                (((source + B_24)^ Shl 8) And $f800)) Shl 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
+
+    d_block := d_block or
+              (((((source + R_24)^ shr 3) and $1f) or
+                (((source + G_24)^ shl 3) and $7e0) or
+                (((source + B_24)^ shl 8) and $f800)) shl DWORD_SMALLINT1_SHL);
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
 
-    Pint32(dest)^ := d_block;
+    PUint32(dest)^ := d_block;
     Inc(dest, 4);
     Dec(c);
-  End;
-
-  If (count And 1) <> 0 Then
-  Begin
-    d_block := (((source + R_24)^ Shr 3) And $1f) Or
-               (((source + G_24)^ Shl 3) And $7e0) Or
-               (((source + B_24)^ Shl 8) And $f800);
-
-    Pshort16(dest)^ := d_block;
-  End;
-End;
-
-Procedure ConvertP_24rgb888_16rgb555_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_block : int32;
-  x : DWord;
-  c : DWord;
-
-Begin
+  end;
+
+  if (count and 1) <> 0 then
+  begin
+    d_block := (((source + R_24)^ shr 3) and $1f) or
+               (((source + G_24)^ shl 3) and $7e0) or
+               (((source + B_24)^ shl 8) and $f800);
+
+    PUint16(dest)^ := d_block;
+  end;
+end;
+
+procedure ConvertP_24rgb888_16rgb555_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_block: Uint32;
+  x: DWord;
+  c: DWord;
+begin
   x := 0;
-  If (PtrUInt(dest) And 3) <> 0 Then
-  Begin
-    d_block := (((source + R_24)^ Shl 7) And $7c00) Or
-               (((source + G_24)^ Shl 2) And $3e0) Or
-               (((source + B_24)^ Shr 3) And $1f);
+  if (PtrUInt(dest) and 3) <> 0 then
+  begin
+    d_block := (((source + R_24)^ shl 7) and $7c00) or
+               (((source + G_24)^ shl 2) and $3e0) or
+               (((source + B_24)^ shr 3) and $1f);
 
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
 
-    Pshort16(dest)^ := d_block;
+    PUint16(dest)^ := d_block;
     Inc(dest, 2);
-  End;
-  c := count Shr 1;
-  While c > 0 Do
-  Begin
-    d_block := (((source + R_24)^ Shl 7) And $7c00) Or
-               (((source + G_24)^ Shl 2) And $3e0) Or
-               (((source + B_24)^ Shr 3) And $1f);
+    Dec(count);
+  end;
+  c := count shr 1;
+  while c > 0 do
+  begin
+    d_block := ((((source + R_24)^ shl 7) and $7c00) or
+                (((source + G_24)^ shl 2) and $3e0) or
+                (((source + B_24)^ shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
-
-    d_block := d_block Or
-               (((((source + R_24)^ Shl 7) And $7c00) Or
-                (((source + G_24)^ Shl 2) And $3e0) Or
-                (((source + B_24)^ Shr 3) And $1f)) Shl 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
+
+    d_block := d_block or
+               (((((source + R_24)^ shl 7) and $7c00) or
+                (((source + G_24)^ shl 2) and $3e0) or
+                (((source + B_24)^ shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
 
-    Pint32(dest)^ := d_block;
+    PUint32(dest)^ := d_block;
     Inc(dest, 4);
     Dec(c);
-  End;
-
-  If (count And 1) <> 0 Then
-  Begin
-    d_block := (((source + R_24)^ Shl 7) And $7c00) Or
-               (((source + G_24)^ Shl 2) And $3e0) Or
-               (((source + B_24)^ Shr 3) And $1f);
-
-    Pshort16(dest)^ := d_block;
-  End;
-End;
-
-Procedure ConvertP_24rgb888_16bgr555_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  d_block : int32;
-  x : DWord;
-  c : DWord;
-
-Begin
+  end;
+
+  if (count and 1) <> 0 then
+  begin
+    d_block := (((source + R_24)^ shl 7) and $7c00) or
+               (((source + G_24)^ shl 2) and $3e0) or
+               (((source + B_24)^ shr 3) and $1f);
+
+    PUint16(dest)^ := d_block;
+  end;
+end;
+
+procedure ConvertP_24rgb888_16bgr555_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  d_block: Uint32;
+  x: DWord;
+  c: DWord;
+begin
   x := 0;
-  If (PtrUInt(dest) And 3) <> 0 Then
-  Begin
-    d_block := (((source + R_24)^ Shr 3) And $1f) Or
-               (((source + G_24)^ Shl 2) And $3e0) Or
-               (((source + B_24)^ Shl 7) And $7c00);
+  if (PtrUInt(dest) and 3) <> 0 then
+  begin
+    d_block := (((source + R_24)^ shr 3) and $1f) or
+               (((source + G_24)^ shl 2) and $3e0) or
+               (((source + B_24)^ shl 7) and $7c00);
 
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
 
-    Pshort16(dest)^ := d_block;
+    PUint16(dest)^ := d_block;
     Inc(dest, 2);
-  End;
-  c := count Shr 1;
-  While c > 0 Do
-  Begin
-    d_block := (((source + R_24)^ Shr 3) And $1f) Or
-               (((source + G_24)^ Shl 2) And $3e0) Or
-               (((source + B_24)^ Shl 7) And $7c00);
+    Dec(count);
+  end;
+  c := count shr 1;
+  while c > 0 do
+  begin
+    d_block := ((((source + R_24)^ shr 3) and $1f) or
+                (((source + G_24)^ shl 2) and $3e0) or
+                (((source + B_24)^ shl 7) and $7c00)) shl DWORD_SMALLINT0_SHL;
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
-
-    d_block := d_block Or
-             (((((source + R_24)^ Shr 3) And $1f) Or
-               (((source + G_24)^ Shl 2) And $3e0) Or
-               (((source + B_24)^ Shl 7) And $7c00)) Shl 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
+
+    d_block := d_block or
+             (((((source + R_24)^ shr 3) and $1f) or
+               (((source + G_24)^ shl 2) and $3e0) or
+               (((source + B_24)^ shl 7) and $7c00)) shl DWORD_SMALLINT1_SHL);
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
 
-    Pint32(dest)^ := d_block;
+    PUint32(dest)^ := d_block;
     Inc(dest, 4);
     Dec(c);
-  End;
-
-  If (count And 1) <> 0 Then
-  Begin
-    d_block := (((source + R_24)^ Shr 3) And $1f) Or
-               (((source + G_24)^ Shl 2) And $3e0) Or
-               (((source + B_24)^ Shl 7) And $7c00);
-
-    Pshort16(dest)^ := d_block;
-  End;
-End;
-
-Procedure ConvertP_24rgb888_8rgb332_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  r, g, b : int32;
-  i : DWord;
-  x : DWord;
-
-Begin
+  end;
+
+  if (count and 1) <> 0 then
+  begin
+    d_block := (((source + R_24)^ shr 3) and $1f) or
+               (((source + G_24)^ shl 2) and $3e0) or
+               (((source + B_24)^ shl 7) and $7c00);
+
+    PUint16(dest)^ := d_block;
+  end;
+end;
+
+procedure ConvertP_24rgb888_8rgb332_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  r, g, b: Uint32;
+  i: DWord;
+  x: DWord;
+begin
   x := 0;
-  For i := 0 To count - 1 Do
-  Begin
-    r := (source + R_24)^ And $e0;
-    g := ((source + G_24)^ Shr 3) And $1c;
-    b := ((source + B_24)^ Shr 6) And $3;
+  for i := 0 to count - 1 do
+  begin
+    r := (source + R_24)^ and $e0;
+    g := ((source + G_24)^ shr 3) and $1c;
+    b := ((source + B_24)^ shr 6) and $3;
 
-    dest^ := r Or g Or b;
+    dest^ := r or g or b;
     Inc(x, inc_source);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    Inc(source, x Shr 16);
-    x := x And $FFFF;
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    Inc(source, x shr 16);
+    x := x and $FFFF;
     Inc(dest);
-  End;
-End;
+  end;
+end;

+ 625 - 610
packages/hermes/src/p_32.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -35,470 +47,472 @@
 
 
 { TO 32 BGR }
-Procedure ConvertP_32rgb888_32bgr888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  s_pixel : int32;
-  s_ptr : Pchar8;
-  tmp : char8;
-
-Begin
+procedure ConvertP_32rgb888_32bgr888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  s_pixel: Uint32;
+  s_ptr: PUint8;
+  tmp: Uint8;
+begin
   s_ptr := @s_pixel;
-  Repeat
-    s_pixel := Pint32(source)^;
+  repeat
+    s_pixel := PUint32(source)^;
 
     tmp := (s_ptr + R_32)^;
     (s_ptr + R_32)^ := (s_ptr + B_32)^;
     (s_ptr + B_32)^ := tmp;
 
-    Pint32(dest)^ := s_pixel;
+    PUint32(dest)^ := s_pixel;
 
     Inc(dest, 4);
     Inc(source, 4);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
 { 32 RGBA }
-Procedure ConvertP_32rgb888_32rgba888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Begin
-  Repeat
-    Pint32(dest)^ := (Pint32(source)^ Shl 8) Or $ff;
+procedure ConvertP_32rgb888_32rgba888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+begin
+  repeat
+    PUint32(dest)^ := (PUint32(source)^ shl 8) or $ff;
 
     Inc(dest, 4);
     Inc(source, 4);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
 { 32 BGRA }
-Procedure ConvertP_32rgb888_32bgra888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  s_pixel : int32;
-  s_ptr : Pchar8;
-  tmp : char8;
-
-Begin
+procedure ConvertP_32rgb888_32bgra888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  s_pixel: Uint32;
+  s_ptr: PUint8;
+  tmp: Uint8;
+begin
   s_ptr := @s_pixel;
-  Repeat
-    s_pixel := Pint32(source)^;
+  repeat
+    s_pixel := PUint32(source)^;
 
     tmp := (s_ptr + R_32)^;
     (s_ptr + R_32)^ := (s_ptr + B_32)^;
     (s_ptr + B_32)^ := tmp;
 
-    Pint32(dest)^ := (s_pixel Shl 8) Or $ff;
+    PUint32(dest)^ := (s_pixel shl 8) or $ff;
 
     Inc(dest, 4);
     Inc(source, 4);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
 { TO 24 RGB }
-Procedure ConvertP_32rgb888_24rgb888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  s_pixel, s_pixel2 : int32;
-  s_point : Pchar8;
-  c : DWord;
-
-Begin
-  s_point := @s_pixel;
+procedure ConvertP_32rgb888_24rgb888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  s_pixel, s_pixel2: Uint32;
+  s_point: PUint8;
+  c: DWord;
+begin
+  s_point := PUint8(@s_pixel) + (R_32 - R_24);
 
   { Align mod 4 (quite important in this case.. ) }
 
-  While (PtrUInt(dest) And $3) <> 0 Do
-  Begin
-    s_pixel := Pint32(source)^;
+  while (PtrUInt(dest) and $3) <> 0 do
+  begin
+    s_pixel := PUint32(source)^;
 
-    (dest + R_24)^ := (s_point + R_32)^;
-    (dest + G_24)^ := (s_point + G_32)^;
-    (dest + B_24)^ := (s_point + B_32)^;
+    (dest + 0)^ := (s_point + 0)^;
+    (dest + 1)^ := (s_point + 1)^;
+    (dest + 2)^ := (s_point + 2)^;
 
     Inc(source, 4);
     Inc(dest, 3);
 
     Dec(count);
-    If count = 0 Then
-      Exit;
-  End;
+    if count = 0 then
+      exit;
+  end;
 
-  { Main loop. TODO: Big endian check! }
+  { Main loop. }
 
-  c := count Shr 2;
-  While c <> 0 Do
-  Begin
+  c := count shr 2;
+  while c <> 0 do
+  begin
     Dec(c);
-    s_pixel := Pint32(source)^;
-    s_pixel2 := (Pint32(source) + 1)^;
-
-    s_pixel := (s_pixel And $ffffff) Or (s_pixel2 Shl 24);
-    Pint32(dest)^ := s_pixel;
-
-    s_pixel := (Pint32(source) + 2)^;
-    s_pixel2 := ((s_pixel2 Shr 8) And $ffff) Or (s_pixel Shl 16);
-    (Pint32(dest) + 1)^ := s_pixel2;
-
-    s_pixel2 := (Pint32(source) + 3)^;
-    s_pixel := ((s_pixel Shr 16) And $ff) Or (s_pixel2 Shl 8);
-    (Pint32(dest) + 2)^ := s_pixel;
+    s_pixel := PUint32(source)^;
+    s_pixel2 := (PUint32(source) + 1)^;
+
+    {$IFDEF FPC_LITTLE_ENDIAN}
+    s_pixel := (s_pixel and $ffffff) or (s_pixel2 shl 24);
+    {$ELSE FPC_LITTLE_ENDIAN}
+    s_pixel := (s_pixel shl 8) or ((s_pixel2 shr 16) and $FF);
+    {$ENDIF FPC_LITTLE_ENDIAN}
+    PUint32(dest)^ := s_pixel;
+
+    s_pixel := (PUint32(source) + 2)^;
+    {$IFDEF FPC_LITTLE_ENDIAN}
+    s_pixel2 := ((s_pixel2 shr 8) and $ffff) or (s_pixel shl 16);
+    {$ELSE FPC_LITTLE_ENDIAN}
+    s_pixel2 := (s_pixel2 shl 16) or ((s_pixel shr 8) and $FFFF);
+    {$ENDIF FPC_LITTLE_ENDIAN}
+    (PUint32(dest) + 1)^ := s_pixel2;
+
+    s_pixel2 := (PUint32(source) + 3)^;
+    {$IFDEF FPC_LITTLE_ENDIAN}
+    s_pixel := ((s_pixel shr 16) and $ff) or (s_pixel2 shl 8);
+    {$ELSE FPC_LITTLE_ENDIAN}
+    s_pixel := (s_pixel shl 24) or (s_pixel2 and $FFFFFF);
+    {$ENDIF FPC_LITTLE_ENDIAN}
+    (PUint32(dest) + 2)^ := s_pixel;
 
     Inc(source, 16);
     Inc(dest, 12);
-  End;
+  end;
 
   { Convert trailing pixels }
 
-  count := count And $3;
-  While count <> 0 Do
-  Begin
+  count := count and $3;
+  while count <> 0 do
+  begin
     Dec(count);
-    s_pixel := Pint32(source)^;
+    s_pixel := PUint32(source)^;
 
-    (dest + R_24)^ := (s_point + R_32)^;
-    (dest + G_24)^ := (s_point + G_32)^;
-    (dest + B_24)^ := (s_point + B_32)^;
+    (dest + 0)^ := (s_point + 0)^;
+    (dest + 1)^ := (s_point + 1)^;
+    (dest + 2)^ := (s_point + 2)^;
 
     Inc(source, 4);
     Inc(dest, 3);
-  End;
-End;
+  end;
+end;
 
 { TO 24 BGR }
-Procedure ConvertP_32rgb888_24bgr888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  s_pixel : int32;
-  s_point : Pchar8;
-
-Begin
-  s_point := @s_pixel;
-  Repeat
-    s_pixel := Pint32(source)^;
+procedure ConvertP_32rgb888_24bgr888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  s_pixel: Uint32;
+  s_point: PUint8;
+begin
+  s_point := PUint8(@s_pixel) + (R_32 - R_24);
+  repeat
+    s_pixel := PUint32(source)^;
 
     { Note that R and B are swapped }
-    (dest + B_24)^ := (s_point + R_32)^;
-    (dest + G_24)^ := (s_point + G_32)^;
-    (dest + R_24)^ := (s_point + B_32)^;
+    (dest + 0)^ := (s_point + 2)^;
+    (dest + 1)^ := (s_point + 1)^;
+    (dest + 2)^ := (s_point + 0)^;
 
     Inc(source, 4);
     Inc(dest, 3);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
 { TO 16 RGB 565 }
-Procedure ConvertP_32rgb888_16rgb565(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  i : DWord;
-  s_pixel : int32;
-  source_32, dest_32 : Pint32;
-
-Begin
-  dest_32 := Pint32(dest);
-  source_32 := Pint32(source);
-
-  { If the current pixel isn't dword aligned, try write one pixel first }
-  If (PtrUInt(dest_32) And $3) <> 0 Then
-  Begin
-    s_pixel := ((source_32^ Shr 8) And $f800) Or
-               ((source_32^ Shr 5) And $7e0) Or
-               ((source_32^ Shr 3) And $1f);
-
-    Pshort16(dest_32)^ := s_pixel;
-
-    dest_32 := Pint32(dest + 2);
+procedure ConvertP_32rgb888_16rgb565(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  i: DWord;
+  s_pixel: Uint32;
+  source_32, dest_32: PUint32;
+begin
+  dest_32 := PUint32(dest);
+  source_32 := PUint32(source);
+
+  { if the current pixel isn't dword aligned, try write one pixel first }
+  if (PtrUInt(dest_32) and $3) <> 0 then
+  begin
+    s_pixel := ((source_32^ shr 8) and $f800) or
+               ((source_32^ shr 5) and $7e0) or
+               ((source_32^ shr 3) and $1f);
+
+    PUint16(dest_32)^ := s_pixel;
+
+    dest_32 := PUint32(dest + 2);
     Inc(source_32);
 
     Dec(count);
-  End;
+  end;
 
   { Write blocks of two pixels }
 
-  For i := 1 To count Shr 1 Do
-  Begin
+  for i := 1 to count shr 1 do
+  begin
     {This horrible construct is actually faster than loading into a variable}
-    dest_32^ := ((source_32^ Shr 8) And $f800) Or
-                ((source_32^ Shr 5) And $7e0) Or
-                ((source_32^ Shr 3) And $1f) Or
-                (((source_32 + 1)^ Shl 8) And $f8000000) Or
-                (((source_32 + 1)^ Shl 11) And $7e00000) Or
-                (((source_32 + 1)^ Shl 13) And $1f0000);
+    {$IFDEF FPC_LITTLE_ENDIAN}
+    dest_32^ := ((source_32^ shr 8) and $f800) or
+                ((source_32^ shr 5) and $7e0) or
+                ((source_32^ shr 3) and $1f) or
+                (((source_32 + 1)^ shl 8) and $f8000000) or
+                (((source_32 + 1)^ shl 11) and $7e00000) or
+                (((source_32 + 1)^ shl 13) and $1f0000);
+    {$ELSE FPC_LITTLE_ENDIAN}
+    dest_32^ := ((source_32^ shl 8) and $f8000000) or
+                ((source_32^ shl 11) and $7e00000) or
+                ((source_32^ shl 13) and $1f0000) or
+                (((source_32 + 1)^ shr 8) and $f800) or
+                (((source_32 + 1)^ shr 5) and $7e0) or
+                (((source_32 + 1)^ shr 3) and $1f);
+    {$ENDIF FPC_LITTLE_ENDIAN}
 
     Inc(dest_32);
     Inc(source_32, 2);
-  End;
+  end;
 
   { Eventually, write a single odd pixel that might be left }
-  If (count And 1) <> 0 Then
-  Begin
+  if (count and 1) <> 0 then
+  begin
     s_pixel := source_32^;
-    Pshort16(dest_32)^ := ((s_pixel Shr 8) And $f800) Or
-                          ((s_pixel Shr 5) And $7e0) Or
-                          ((s_pixel Shr 3) And $1f);
-  End;
-End;
+    PUint16(dest_32)^ := ((s_pixel shr 8) and $f800) or
+                          ((s_pixel shr 5) and $7e0) or
+                          ((s_pixel shr 3) and $1f);
+  end;
+end;
 
 { TO 16 BGR 565 }
-Procedure ConvertP_32rgb888_16bgr565(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  i : DWord;
-  r, g, b : int32;
-  s_pixel, d_pixelblock : int32;
-  d_pixel : short16;
-
-Begin
-  { If the current pixel isn't dword aligned, try write one pixel first }
-  If (PtrUInt(dest) And $3) <> 0 Then
-  Begin
-    s_pixel := Pint32(source)^;
-
-    r := (s_pixel Shr 19) And $1f;
-    g := (s_pixel Shr 5) And $7e0;
-    b := (s_pixel Shl 8) And $f800;
-
-    d_pixel := r Or g Or b;
-
-    Pshort16(dest)^ := d_pixel;
+procedure ConvertP_32rgb888_16bgr565(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  i: DWord;
+  r, g, b: Uint32;
+  s_pixel, d_pixelblock: Uint32;
+  d_pixel: Uint16;
+begin
+  { if the current pixel isn't dword aligned, try write one pixel first }
+  if (PtrUInt(dest) and $3) <> 0 then
+  begin
+    s_pixel := PUint32(source)^;
+
+    r := (s_pixel shr 19) and $1f;
+    g := (s_pixel shr 5) and $7e0;
+    b := (s_pixel shl 8) and $f800;
+
+    d_pixel := r or g or b;
+
+    PUint16(dest)^ := d_pixel;
 
     Inc(source, 4);
     Inc(dest, 2);
     Dec(count);
-  End;
+  end;
 
   { Write blocks of two pixels }
-  For i := 1 To count Shr 1 Do
-  Begin
-    s_pixel := Pint32(source)^;
+  for i := 1 to count shr 1 do
+  begin
+    s_pixel := PUint32(source)^;
 
-    d_pixelblock := ((s_pixel Shr 19) And $1f) Or
-                    ((s_pixel Shr 5) And $7e0) Or
-                    ((s_pixel Shl 8) And $f800);
+    d_pixelblock := (((s_pixel shr 19) and $1f) or
+                     ((s_pixel shr 5) and $7e0) or
+                     ((s_pixel shl 8) and $f800)) shl DWORD_SMALLINT0_SHL;
 
-    s_pixel := (Pint32(source) + 1)^;
+    s_pixel := (PUint32(source) + 1)^;
 
-    d_pixelblock := d_pixelblock Or
-                  ((((s_pixel Shr 19) And $1f) Or
-                    ((s_pixel Shr 5) And $7e0) Or
-                    ((s_pixel Shl 8) And $f800)) Shl 16);
+    d_pixelblock := d_pixelblock or
+                  ((((s_pixel shr 19) and $1f) or
+                    ((s_pixel shr 5) and $7e0) or
+                    ((s_pixel shl 8) and $f800)) shl DWORD_SMALLINT1_SHL);
 
-    Pint32(dest)^ := d_pixelblock;
+    PUint32(dest)^ := d_pixelblock;
     Inc(source, 8);
     Inc(dest, 4);
-  End;
+  end;
 
   { Eventually, write a single odd pixel that might be left }
-  If (count And 1) <> 0 Then
-  Begin
-    s_pixel := Pint32(source)^;
+  if (count and 1) <> 0 then
+  begin
+    s_pixel := PUint32(source)^;
 
-    r := (s_pixel Shr 19) And $1f;
-    g := (s_pixel Shr 5) And $7e0;
-    b := (s_pixel Shl 8) And $f800;
+    r := (s_pixel shr 19) and $1f;
+    g := (s_pixel shr 5) and $7e0;
+    b := (s_pixel shl 8) and $f800;
 
-    d_pixel := r Or g Or b;
+    d_pixel := r or g or b;
 
-    Pshort16(dest)^ := d_pixel;
-  End;
-End;
+    PUint16(dest)^ := d_pixel;
+  end;
+end;
 
 { TO 16 RGB 555 }
-Procedure ConvertP_32rgb888_16rgb555(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  r, g, b : int32;
-  s_pixel, d_pixelblock : int32;
-  d_pixel : short16;
-  i : DWord;
+procedure ConvertP_32rgb888_16rgb555(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  r, g, b: Uint32;
+  s_pixel, d_pixelblock: Uint32;
+  d_pixel: Uint16;
+  i: DWord;
+begin
+  if (PtrUInt(dest) and $3) <> 0 then
+  begin
+    s_pixel := PUint32(source)^;
 
-Begin
-  If (PtrUInt(dest) And $3) <> 0 Then
-  Begin
-    s_pixel := Pint32(source)^;
+    r := (s_pixel shr 9) and $7c00;
+    g := (s_pixel shr 6) and $3e0;
+    b := (s_pixel shr 3) and $1f;
 
-    r := (s_pixel Shr 9) And $7c00;
-    g := (s_pixel Shr 6) And $3e0;
-    b := (s_pixel Shr 3) And $1f;
+    d_pixel := r or g or b;
 
-    d_pixel := r Or g Or b;
-
-    Pshort16(dest)^ := d_pixel;
+    PUint16(dest)^ := d_pixel;
 
     Inc(source, 4);
     Inc(dest, 2);
     Dec(count);
-  End;
+  end;
 
-  For i := 1 To count Shr 1 Do
-  Begin
-    s_pixel := Pint32(source)^;
+  for i := 1 to count shr 1 do
+  begin
+    s_pixel := PUint32(source)^;
 
-    d_pixelblock := ((s_pixel Shr 9) And $7c00) Or
-                    ((s_pixel Shr 6) And $3e0) Or
-                    ((s_pixel Shr 3) And $1f);
+    d_pixelblock := (((s_pixel shr 9) and $7c00) or
+                     ((s_pixel shr 6) and $3e0) or
+                     ((s_pixel shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
 
-    s_pixel := (Pint32(source) + 1)^;
+    s_pixel := (PUint32(source) + 1)^;
 
-    d_pixelblock := d_pixelblock Or
-                  ((((s_pixel Shr 9) And $7c00) Or
-                    ((s_pixel Shr 6) And $3e0) Or
-                    ((s_pixel Shr 3) And $1f)) Shl 16);
+    d_pixelblock := d_pixelblock or
+                  ((((s_pixel shr 9) and $7c00) or
+                    ((s_pixel shr 6) and $3e0) or
+                    ((s_pixel shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
 
-    Pint32(dest)^ := d_pixelblock;
+    PUint32(dest)^ := d_pixelblock;
     Inc(source, 8);
     Inc(dest, 4);
-  End;
+  end;
 
-  If (count And 1) <> 0 Then
-  Begin
-    s_pixel := Pint32(source)^;
+  if (count and 1) <> 0 then
+  begin
+    s_pixel := PUint32(source)^;
 
-    r := (s_pixel Shr 9) And $7c00;
-    g := (s_pixel Shr 6) And $3e0;
-    b := (s_pixel Shr 3) And $1f;
+    r := (s_pixel shr 9) and $7c00;
+    g := (s_pixel shr 6) and $3e0;
+    b := (s_pixel shr 3) and $1f;
 
-    d_pixel := r Or g Or b;
+    d_pixel := r or g or b;
 
-    Pshort16(dest)^ := d_pixel;
-  End;
-End;
+    PUint16(dest)^ := d_pixel;
+  end;
+end;
 
 { TO 16 BGR 555 }
-Procedure ConvertP_32rgb888_16bgr555(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  r, g, b : int32;
-  s_pixel, d_pixelblock : int32;
-  d_pixel : short16;
-  i : DWord;
+procedure ConvertP_32rgb888_16bgr555(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  r, g, b: Uint32;
+  s_pixel, d_pixelblock: Uint32;
+  d_pixel: Uint16;
+  i: DWord;
+begin
+  if (PtrUInt(dest) and $3) <> 0 then
+  begin
+    s_pixel := PUint32(source)^;
 
-Begin
-  If (PtrUInt(dest) And $3) <> 0 Then
-  Begin
-    s_pixel := Pint32(source)^;
+    r := (s_pixel shr 19) and $1f;
+    g := (s_pixel shr 6) and $3e0;
+    b := (s_pixel shl 7) and $7c00;
 
-    r := (s_pixel Shr 19) And $1f;
-    g := (s_pixel Shr 6) And $3e0;
-    b := (s_pixel Shl 7) And $7c00;
+    d_pixel := r or g or b;
 
-    d_pixel := r Or g Or b;
-
-    Pshort16(dest)^ := d_pixel;
+    PUint16(dest)^ := d_pixel;
 
     Inc(source, 4);
     Inc(dest, 2);
     Dec(count);
-  End;
+  end;
 
-  For i := 1 To count Shr 1 Do
-  Begin
-    s_pixel := Pint32(source)^;
+  for i := 1 to count shr 1 do
+  begin
+    s_pixel := PUint32(source)^;
 
-    d_pixelblock := ((s_pixel Shr 19) And $1f) Or
-                    ((s_pixel Shr 6) And $3e0) Or
-                    ((s_pixel Shl 7) And $7c00);
+    d_pixelblock := (((s_pixel shr 19) and $1f) or
+                     ((s_pixel shr 6) and $3e0) or
+                     ((s_pixel shl 7) and $7c00)) shl DWORD_SMALLINT0_SHL;
 
-    s_pixel := (Pint32(source) + 1)^;
+    s_pixel := (PUint32(source) + 1)^;
 
-    d_pixelblock := d_pixelblock Or
-                  ((((s_pixel Shr 19) And $1f) Or
-                    ((s_pixel Shr 6) And $3e0) Or
-                    ((s_pixel Shl 7) And $7c00)) Shl 16);
+    d_pixelblock := d_pixelblock or
+                  ((((s_pixel shr 19) and $1f) or
+                    ((s_pixel shr 6) and $3e0) or
+                    ((s_pixel shl 7) and $7c00)) shl DWORD_SMALLINT1_SHL);
 
-    Pint32(dest)^ := d_pixelblock;
+    PUint32(dest)^ := d_pixelblock;
     Inc(source, 8);
     Inc(dest, 4);
-  End;
+  end;
 
-  If (count And 1) <> 0 Then
-  Begin
-    s_pixel := Pint32(source)^;
+  if (count and 1) <> 0 then
+  begin
+    s_pixel := PUint32(source)^;
 
-    r := (s_pixel Shr 19) And $1f;
-    g := (s_pixel Shr 6) And $3e0;
-    b := (s_pixel Shl 7) And $7c00;
+    r := (s_pixel shr 19) and $1f;
+    g := (s_pixel shr 6) and $3e0;
+    b := (s_pixel shl 7) and $7c00;
 
-    d_pixel := r Or g Or b;
+    d_pixel := r or g or b;
 
-    Pshort16(dest)^ := d_pixel;
-  End;
-End;
+    PUint16(dest)^ := d_pixel;
+  end;
+end;
 
 { TO 8 RGB 332 }
-Procedure ConvertP_32rgb888_8rgb332(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  i : DWord;
-  s_pixel, d_block : int32;
-  d_pixel : char8;
-
-Begin
+procedure ConvertP_32rgb888_8rgb332(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  i: DWord;
+  s_pixel, d_block: Uint32;
+  d_pixel: Uint8;
+begin
   { Process single pixels until we are dword aligned }
-  While (PtrUInt(dest) And $3) <> 0 Do
-  Begin
-    s_pixel := Pint32(source)^;
+  while (PtrUInt(dest) and $3) <> 0 do
+  begin
+    s_pixel := PUint32(source)^;
 
-    d_pixel := ((s_pixel Shr 16) And $e0) Or
-               ((s_pixel Shr 11) And $1c) Or
-               ((s_pixel Shr 6) And $3);
+    d_pixel := ((s_pixel shr 16) and $e0) or
+               ((s_pixel shr 11) and $1c) or
+               ((s_pixel shr 6) and $3);
 
     dest^ := d_pixel;
 
     Dec(count);
-    If count = 0 Then
-      Exit;
+    if count = 0 then
+      exit;
     Inc(dest);
     Inc(source, 4);
-  End;
+  end;
 
   { Now process blocks of four pixels }
-  For i := 1 To count Shr 2 Do
-  Begin
-    s_pixel := Pint32(source)^;
-    d_block := ((s_pixel Shr 16) And $e0) Or
-               ((s_pixel Shr 11) And $1c) Or
-               ((s_pixel Shr 6) And $3);
-
-    s_pixel := (Pint32(source) + 1)^;
-    d_block := ((((s_pixel Shr 16) And $e0) Or
-                 ((s_pixel Shr 11) And $1c) Or
-                 ((s_pixel Shr 6) And $3)) Shl 8) Or d_block;
-
-    s_pixel := (Pint32(source) + 2)^;
-    d_block := ((((s_pixel Shr 16) And $e0) Or
-                 ((s_pixel Shr 11) And $1c) Or
-                 ((s_pixel Shr 6) And $3)) Shl 16) Or d_block;
-
-    s_pixel := (Pint32(source) + 3)^;
-    d_block := ((((s_pixel Shr 16) And $e0) Or
-                 ((s_pixel Shr 11) And $1c) Or
-                 ((s_pixel Shr 6) And $3)) Shl 24) Or d_block;
-
-    Pint32(dest)^ := d_block;
+  for i := 1 to count shr 2 do
+  begin
+    s_pixel := PUint32(source)^;
+    d_block := (((s_pixel shr 16) and $e0) or
+                ((s_pixel shr 11) and $1c) or
+                ((s_pixel shr 6) and $3)) shl DWORD_BYTE0_SHL;
+
+    s_pixel := (PUint32(source) + 1)^;
+    d_block := ((((s_pixel shr 16) and $e0) or
+                 ((s_pixel shr 11) and $1c) or
+                 ((s_pixel shr 6) and $3)) shl DWORD_BYTE1_SHL) or d_block;
+
+    s_pixel := (PUint32(source) + 2)^;
+    d_block := ((((s_pixel shr 16) and $e0) or
+                 ((s_pixel shr 11) and $1c) or
+                 ((s_pixel shr 6) and $3)) shl DWORD_BYTE2_SHL) or d_block;
+
+    s_pixel := (PUint32(source) + 3)^;
+    d_block := ((((s_pixel shr 16) and $e0) or
+                 ((s_pixel shr 11) and $1c) or
+                 ((s_pixel shr 6) and $3)) shl DWORD_BYTE3_SHL) or d_block;
+
+    PUint32(dest)^ := d_block;
     Inc(source, 16);
     Inc(dest, 4);
-  End;
+  end;
 
   { Write all possibly remaining pixel }
-  count := count And $3;
-  While count <> 0 Do
-  Begin
+  count := count and $3;
+  while count <> 0 do
+  begin
     Dec(count);
-    s_pixel := Pint32(source)^;
+    s_pixel := PUint32(source)^;
 
-    dest^ := ((s_pixel Shr 16) And $e0) Or
-             ((s_pixel Shr 11) And $1c) Or
-             ((s_pixel Shr 6) And $3);
+    dest^ := ((s_pixel shr 16) and $e0) or
+             ((s_pixel shr 11) and $1c) or
+             ((s_pixel shr 6) and $3);
 
     Inc(dest);
     Inc(source, 4);
-  End;
-End;
+  end;
+end;
 
 { -------------------------------------------------------------------------
 
@@ -506,438 +520,439 @@ End;
 
   ------------------------------------------------------------------------- }
 
-Procedure ConvertP_32rgb888_32bgr888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x : DWord;
-  s_pixel : int32;
-  s_ptr : Pchar8;
-  tmp : char8;
-
-Begin
+procedure ConvertP_32rgb888_32bgr888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+  s_pixel: Uint32;
+  s_ptr: PUint8;
+  tmp: Uint8;
+begin
   x := 0;
   s_ptr := @s_pixel;
-  Repeat
-    s_pixel := (Pint32(source)+(x Shr 16))^;
+  repeat
+    s_pixel := (PUint32(source)+(x shr 16))^;
 
     tmp := (s_ptr + R_32)^;
     (s_ptr + R_32)^ := (s_ptr + B_32)^;
     (s_ptr + B_32)^ := tmp;
 
-    Pint32(dest)^ := s_pixel;
+    PUint32(dest)^ := s_pixel;
 
     Inc(dest, 4);
     Inc(x, inc_source);
     Dec(count);
-  Until count = 0;
-End;
-
-Procedure ConvertP_32rgb888_32rgba888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
+  until count = 0;
+end;
 
-Var
-  x : DWord;
-
-Begin
+procedure ConvertP_32rgb888_32rgba888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+begin
   x := 0;
-  Repeat
-    Pint32(dest)^ := ((Pint32(source) + (x Shr 16))^ Shl 8) Or $ff;
+  repeat
+    PUint32(dest)^ := ((PUint32(source) + (x shr 16))^ shl 8) or $ff;
 
     Inc(dest, 4);
     Inc(x, inc_source);
     Dec(count);
-  Until count = 0;
-End;
-
-Procedure ConvertP_32rgb888_32bgra888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x : DWord;
-  s_pixel : int32;
-  s_ptr : Pchar8;
-  tmp : char8;
-
-Begin
+  until count = 0;
+end;
+
+procedure ConvertP_32rgb888_32bgra888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+  s_pixel: Uint32;
+  s_ptr: PUint8;
+  tmp: Uint8;
+begin
   x := 0;
   s_ptr := @s_pixel;
-  Repeat
-    s_pixel := (Pint32(source)+(x Shr 16))^;
+  repeat
+    s_pixel := (PUint32(source)+(x shr 16))^;
 
     tmp := (s_ptr + R_32)^;
     (s_ptr + R_32)^ := (s_ptr + B_32)^;
     (s_ptr + B_32)^ := tmp;
 
-    Pint32(dest)^ := (s_pixel Shl 8) Or $ff;
+    PUint32(dest)^ := (s_pixel shl 8) or $ff;
 
     Inc(dest, 4);
     Inc(x, inc_source);
     Dec(count);
-  Until count = 0;
-End;
-
-Procedure ConvertP_32rgb888_24rgb888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x, c : DWord;
-  s1, s2 : DWord;
-
-Begin
+  until count = 0;
+end;
+
+procedure ConvertP_32rgb888_24rgb888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+const
+  endian_fixup = R_32 - R_24;
+var
+  x, c: DWord;
+  s1, s2: DWord;
+begin
   x := 0;
-  While (PtrUInt(dest) And 3) <> 0 Do
-  Begin
-    Pshort16(dest)^ := Pshort16(source)^;
-    (dest + 2)^ := (source + 2)^;
-    
+  while (PtrUInt(dest) and 3) <> 0 do
+  begin
+    (dest + 0)^ := (source + 0 + endian_fixup)^;
+    (dest + 1)^ := (source + 1 + endian_fixup)^;
+    (dest + 2)^ := (source + 2 + endian_fixup)^;
+
     Inc(x, inc_source);
-    Inc(source, (x Shr 16)*4);
-    x := x And $FFFF;
-    
+    Inc(source, (x shr 16)*4);
+    x := x and $FFFF;
+
     Inc(dest, 3);
     Dec(count);
-    If count = 0 Then
-      Exit;
-  End;
-  
-  c := count Shr 2;
-  While c > 0 Do
-  Begin
-    s1 := (Pint32(source) + ((x + inc_source) Shr 16))^ And $FFFFFF;
-    Pint32(dest)^ := ((Pint32(source) + (x Shr 16))^ And $FFFFFF) Or (s1 Shl 24);
-    s2 := (Pint32(source) + ((x + 2*inc_source) Shr 16))^ And $FFFFFF;
-    Pint32(dest + 4)^ := (s1 Shr 8) Or (s2 Shl 16);
-    Pint32(dest + 8)^ := (s2 Shr 16) Or ((Pint32(source) + ((x + 3*inc_source) Shr 16))^ Shl 8);
+    if count = 0 then
+      exit;
+  end;
+
+  c := count shr 2;
+  while c > 0 do
+  begin
+    {$IFDEF FPC_LITTLE_ENDIAN}
+    s1 := (PUint32(source) + ((x + inc_source) shr 16))^ and $FFFFFF;
+    PUint32(dest)^ := ((PUint32(source) + (x shr 16))^ and $FFFFFF) or (s1 shl 24);
+    s2 := (PUint32(source) + ((x + 2*inc_source) shr 16))^ and $FFFFFF;
+    PUint32(dest + 4)^ := (s1 shr 8) or (s2 shl 16);
+    PUint32(dest + 8)^ := (s2 shr 16) or ((PUint32(source) + ((x + 3*inc_source) shr 16))^ shl 8);
+    {$ELSE FPC_LITTLE_ENDIAN}
+    s1 := (PUint32(source) + ((x + inc_source) shr 16))^ and $FFFFFF;
+    PUint32(dest)^ := ((PUint32(source) + (x shr 16))^ shl 8) or (s1 shr 16);
+    s2 := (PUint32(source) + ((x + 2*inc_source) shr 16))^ and $FFFFFF;
+    PUint32(dest + 4)^ := (s1 shl 16) or (s2 shr 8);
+    PUint32(dest + 8)^ := (s2 shl 24) or ((PUint32(source) + ((x + 3*inc_source) shr 16))^ and $FFFFFF);
+    {$ENDIF FPC_LITTLE_ENDIAN}
+
     Inc(x, 4*inc_source);
-    
+
     Inc(dest, 12);
     Dec(c);
-  End;
-  Inc(source, (x Shr 16) * 4);
-  x := x And $FFFF;
-  
-  count := count And $3;
-  While count > 0 Do
-  Begin
-    Pshort16(dest)^ := Pshort16(source)^;
-    (dest + 2)^ := (source + 2)^;
-    
-    Inc(x, inc_source);
-    Inc(source, (x Shr 16)*4);
-    x := x And $FFFF;
-    
-    Inc(dest, 3);
-    Dec(count);
-  End;
-End;
+  end;
+  Inc(source, (x shr 16) * 4);
+  x := x and $FFFF;
 
-Procedure ConvertP_32rgb888_24bgr888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
+  count := count and $3;
+  while count > 0 do
+  begin
+    (dest + 0)^ := (source + 0 + endian_fixup)^;
+    (dest + 1)^ := (source + 1 + endian_fixup)^;
+    (dest + 2)^ := (source + 2 + endian_fixup)^;
 
-Var
-  x, c : DWord;
-  s1, s2, s3, s4 : DWord;
+    Inc(x, inc_source);
+    Inc(source, (x shr 16)*4);
+    x := x and $FFFF;
 
-Begin
+    Inc(dest, 3);
+    Dec(count);
+  end;
+end;
+
+procedure ConvertP_32rgb888_24bgr888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+const
+  endian_fixup = R_32 - R_24;
+var
+  x, c: DWord;
+  s1, s2, s3, s4: DWord;
+begin
   x := 0;
-  While (PtrUInt(dest) And 3) <> 0 Do
-  Begin
-    (dest)^ := (source + 2)^;
-    (dest + 1)^ := (source + 1)^;
-    (dest + 2)^ := (source)^;
-    
+  while (PtrUInt(dest) and 3) <> 0 do
+  begin
+    (dest + 0)^ := (source + 2 + endian_fixup)^;
+    (dest + 1)^ := (source + 1 + endian_fixup)^;
+    (dest + 2)^ := (source + 0 + endian_fixup)^;
+
     Inc(x, inc_source);
-    Inc(source, (x Shr 16)*4);
-    x := x And $FFFF;
-    
+    Inc(source, (x shr 16)*4);
+    x := x and $FFFF;
+
     Inc(dest, 3);
     Dec(count);
-    If count = 0 Then
-      Exit;
-  End;
-  
-  c := count Shr 2;
-  While c > 0 Do
-  Begin
-    s1 := (Pint32(source) + (x Shr 16))^;
-    s2 := (Pint32(source) + ((x + inc_source) Shr 16))^;
-    s3 := (Pint32(source) + ((x + 2*inc_source) Shr 16))^;
-    s4 := (Pint32(source) + ((x + 3*inc_source) Shr 16))^;
-    
-    Pint32(dest + 0)^ := ((s2 And $FF0000) Shl 8) Or ((s1 And $FF) Shl 16) Or (s1 And $FF00) Or ((s1 Shr 16) And $FF);
-    Pint32(dest + 4)^ := ((s3 And $FF00) Shl 16) Or (s3 And $FF0000) Or ((s2 And $FF) Shl 8) Or ((s2 Shr 8) And $FF);
-    Pint32(dest + 8)^ := ((s4 And $FF) Shl 24) Or ((s4 And $FF00) Shl 8) Or ((s4 Shr 8) And $FF00) Or (s3 And $FF);
-    
+    if count = 0 then
+      exit;
+  end;
+
+  c := count shr 2;
+  while c > 0 do
+  begin
+    s1 := (PUint32(source) + (x shr 16))^;
+    s2 := (PUint32(source) + ((x + inc_source) shr 16))^;
+    s3 := (PUint32(source) + ((x + 2*inc_source) shr 16))^;
+    s4 := (PUint32(source) + ((x + 3*inc_source) shr 16))^;
+
+    {$IFDEF FPC_LITTLE_ENDIAN}
+    PUint32(dest + 0)^ := ((s2 and $FF0000) shl 8) or ((s1 and $FF) shl 16) or (s1 and $FF00) or ((s1 shr 16) and $FF);
+    PUint32(dest + 4)^ := ((s3 and $FF00) shl 16) or (s3 and $FF0000) or ((s2 and $FF) shl 8) or ((s2 shr 8) and $FF);
+    PUint32(dest + 8)^ := ((s4 and $FF) shl 24) or ((s4 and $FF00) shl 8) or ((s4 shr 8) and $FF00) or (s3 and $FF);
+    {$ELSE FPC_LITTLE_ENDIAN}
+    PUint32(dest + 0)^ := ((s1 and $FF) shl 24) or ((s1 and $FF00) shl 8) or ((s1 and $FF0000) shr 8) or (s2 and $FF);
+    PUint32(dest + 4)^ := ((s2 and $FF00) shl 16) or (s2 and $FF0000) or ((s3 and $FF) shl 8) or ((s3 and $FF00) shr 8);
+    PUint32(dest + 8)^ := ((s3 and $FF0000) shl 8) or ((s4 and $FF) shl 16) or (s4 and $FF00) or ((s4 and $FF0000) shr 16);
+    {$ENDIF FPC_LITTLE_ENDIAN}
+
     Inc(x, 4*inc_source);
-    
+
     Inc(dest, 12);
     Dec(c);
-  End;
-  Inc(source, (x Shr 16) * 4);
-  x := x And $FFFF;
-  
-  count := count And $3;
-  While count > 0 Do
-  Begin
-    (dest)^ := (source + 2)^;
-    (dest + 1)^ := (source + 1)^;
-    (dest + 2)^ := (source)^;
-    
-    Inc(x, inc_source);
-    Inc(source, (x Shr 16)*4);
-    x := x And $FFFF;
-    
-    Inc(dest, 3);
-    Dec(count);
-  End;
-End;
+  end;
+  Inc(source, (x shr 16) * 4);
+  x := x and $FFFF;
 
-Procedure ConvertP_32rgb888_16rgb565_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
+  count := count and $3;
+  while count > 0 do
+  begin
+    (dest + 0)^ := (source + 2 + endian_fixup)^;
+    (dest + 1)^ := (source + 1 + endian_fixup)^;
+    (dest + 2)^ := (source + 0 + endian_fixup)^;
 
-Var
-  x, c : DWord;
-  p : int32;
+    Inc(x, inc_source);
+    Inc(source, (x shr 16)*4);
+    x := x and $FFFF;
 
-Begin
+    Inc(dest, 3);
+    Dec(count);
+  end;
+end;
+
+procedure ConvertP_32rgb888_16rgb565_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x, c: DWord;
+  p: Uint32;
+begin
   x := 0;
   { Align mod 4 }
-  If (PtrUInt(dest) And 3) <> 0 Then
-  Begin
-    Pshort16(dest)^ := (((Pint32(source) + (x Shr 16))^ Shr 8) And $f800) Or
-                       (((Pint32(source) + (x Shr 16))^ Shr 5) And $7e0) Or
-                       (((Pint32(source) + (x Shr 16))^ Shr 3) And $1f);
+  if (PtrUInt(dest) and 3) <> 0 then
+  begin
+    PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 8) and $f800) or
+                       (((PUint32(source) + (x shr 16))^ shr 5) and $7e0) or
+                       (((PUint32(source) + (x shr 16))^ shr 3) and $1f);
     Inc(x, inc_source);
     Inc(dest, 2);
     Dec(count);
-  End;
+  end;
 
   { Try to write 2 pixel blocks }
-  c := count Shr 1;
-  While c <> 0 Do
-  Begin
+  c := count shr 1;
+  while c <> 0 do
+  begin
     Dec(c);
-    p := (((Pint32(source) + (x Shr 16))^ Shr 8) And $f800) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 5) And $7e0) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 3) And $1f);
+    p := ((((PUint32(source) + (x shr 16))^ shr 8) and $f800) or
+          (((PUint32(source) + (x shr 16))^ shr 5) and $7e0) or
+          (((PUint32(source) + (x shr 16))^ shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
     Inc(x, inc_source);
 
-    p := p Or
-       (((((Pint32(source) + (x Shr 16))^ Shr 8) And $f800) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 5) And $7e0) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 3) And $1f)) Shl 16);
+    p := p or
+       (((((PUint32(source) + (x shr 16))^ shr 8) and $f800) or
+         (((PUint32(source) + (x shr 16))^ shr 5) and $7e0) or
+         (((PUint32(source) + (x shr 16))^ shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
     Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
 
     Inc(dest, 4);
-  End;
+  end;
 
   { Write trailing pixel }
-  If (count And 1) <> 0 Then
-    Pshort16(dest)^ := (((Pint32(source) + (x Shr 16))^ Shr 8) And $f800) Or
-                       (((Pint32(source) + (x Shr 16))^ Shr 5) And $7e0) Or
-                       (((Pint32(source) + (x Shr 16))^ Shr 3) And $1f);
-End;
-
-Procedure ConvertP_32rgb888_16bgr565_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x, c : DWord;
-  p : int32;
-
-Begin
+  if (count and 1) <> 0 then
+    PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 8) and $f800) or
+                       (((PUint32(source) + (x shr 16))^ shr 5) and $7e0) or
+                       (((PUint32(source) + (x shr 16))^ shr 3) and $1f);
+end;
+
+procedure ConvertP_32rgb888_16bgr565_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x, c: DWord;
+  p: Uint32;
+begin
   x := 0;
   { Align mod 4 }
-  If (PtrUInt(dest) And 3) <> 0 Then
-  Begin
-    Pshort16(dest)^ := (((Pint32(source) + (x Shr 16))^ Shr 19) And $1f) Or
-                       (((Pint32(source) + (x Shr 16))^ Shr 5) And $7e0) Or
-                       (((Pint32(source) + (x Shr 16))^ Shl 8) And $f800);
+  if (PtrUInt(dest) and 3) <> 0 then
+  begin
+    PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 19) and $1f) or
+                       (((PUint32(source) + (x shr 16))^ shr 5) and $7e0) or
+                       (((PUint32(source) + (x shr 16))^ shl 8) and $f800);
     Inc(x, inc_source);
     Inc(dest, 2);
     Dec(count);
-  End;
+  end;
 
   { Try to write 2 pixel blocks }
-  c := count Shr 1;
-  While c <> 0 Do
-  Begin
+  c := count shr 1;
+  while c <> 0 do
+  begin
     Dec(c);
-    p := (((Pint32(source) + (x Shr 16))^ Shr 19) And $1f) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 5) And $7e0) Or
-         (((Pint32(source) + (x Shr 16))^ Shl 8) And $f800);
+    p := ((((PUint32(source) + (x shr 16))^ shr 19) and $1f) or
+          (((PUint32(source) + (x shr 16))^ shr 5) and $7e0) or
+          (((PUint32(source) + (x shr 16))^ shl 8) and $f800)) shl DWORD_SMALLINT0_SHL;
     Inc(x, inc_source);
 
-    p := p Or
-       (((((Pint32(source) + (x Shr 16))^ Shr 19) And $1f) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 5) And $7e0) Or
-         (((Pint32(source) + (x Shr 16))^ Shl 8) And $f800)) Shl 16);
+    p := p or
+       (((((PUint32(source) + (x shr 16))^ shr 19) and $1f) or
+         (((PUint32(source) + (x shr 16))^ shr 5) and $7e0) or
+         (((PUint32(source) + (x shr 16))^ shl 8) and $f800)) shl DWORD_SMALLINT1_SHL);
     Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
 
     Inc(dest, 4);
-  End;
+  end;
 
   { Write trailing pixel }
-  If (count And 1) <> 0 Then
-    Pshort16(dest)^ := (((Pint32(source) + (x Shr 16))^ Shr 19) And $1f) Or
-                       (((Pint32(source) + (x Shr 16))^ Shr 5) And $7e0) Or
-                       (((Pint32(source) + (x Shr 16))^ Shl 8) And $f800);
-End;
-
-Procedure ConvertP_32rgb888_16rgb555_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x, c : DWord;
-  p : int32;
-
-Begin
+  if (count and 1) <> 0 then
+    PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 19) and $1f) or
+                       (((PUint32(source) + (x shr 16))^ shr 5) and $7e0) or
+                       (((PUint32(source) + (x shr 16))^ shl 8) and $f800);
+end;
+
+procedure ConvertP_32rgb888_16rgb555_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x, c: DWord;
+  p: Uint32;
+begin
   x := 0;
   { Align mod 4 }
-  If (PtrUInt(dest) And 3) <> 0 Then
-  Begin
-    Pshort16(dest)^ := (((Pint32(source) + (x Shr 16))^ Shr 9) And $7c00) Or
-                       (((Pint32(source) + (x Shr 16))^ Shr 6) And $3e0) Or
-                       (((Pint32(source) + (x Shr 16))^ Shr 3) And $1f);
+  if (PtrUInt(dest) and 3) <> 0 then
+  begin
+    PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 9) and $7c00) or
+                       (((PUint32(source) + (x shr 16))^ shr 6) and $3e0) or
+                       (((PUint32(source) + (x shr 16))^ shr 3) and $1f);
     Inc(x, inc_source);
     Inc(dest, 2);
     Dec(count);
-  End;
+  end;
 
   { Try to write 2 pixel blocks }
-  c := count Shr 1;
-  While c <> 0 Do
-  Begin
+  c := count shr 1;
+  while c <> 0 do
+  begin
     Dec(c);
-    p := (((Pint32(source) + (x Shr 16))^ Shr 9) And $7c00) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 6) And $3e0) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 3) And $1f);
+    p := ((((PUint32(source) + (x shr 16))^ shr 9) and $7c00) or
+          (((PUint32(source) + (x shr 16))^ shr 6) and $3e0) or
+          (((PUint32(source) + (x shr 16))^ shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
     Inc(x, inc_source);
 
-    p := p Or
-       (((((Pint32(source) + (x Shr 16))^ Shr 9) And $7c00) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 6) And $3e0) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 3) And $1f)) Shl 16);
+    p := p or
+       (((((PUint32(source) + (x shr 16))^ shr 9) and $7c00) or
+         (((PUint32(source) + (x shr 16))^ shr 6) and $3e0) or
+         (((PUint32(source) + (x shr 16))^ shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
     Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
 
     Inc(dest, 4);
-  End;
+  end;
 
   { Write trailing pixel }
-  If (count And 1) <> 0 Then
-    Pshort16(dest)^ := (((Pint32(source) + (x Shr 16))^ Shr 9) And $7c00) Or
-                       (((Pint32(source) + (x Shr 16))^ Shr 6) And $3e0) Or
-                       (((Pint32(source) + (x Shr 16))^ Shr 3) And $1f);
-End;
-
-Procedure ConvertP_32rgb888_16bgr555_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x, c : DWord;
-  p : int32;
-
-Begin
+  if (count and 1) <> 0 then
+    PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 9) and $7c00) or
+                       (((PUint32(source) + (x shr 16))^ shr 6) and $3e0) or
+                       (((PUint32(source) + (x shr 16))^ shr 3) and $1f);
+end;
+
+procedure ConvertP_32rgb888_16bgr555_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x, c: DWord;
+  p: Uint32;
+begin
   x := 0;
   { Align mod 4 }
-  If (PtrUInt(dest) And 3) <> 0 Then
-  Begin
-    Pshort16(dest)^ := (((Pint32(source) + (x Shr 16))^ Shr 19) And $1f) Or
-                       (((Pint32(source) + (x Shr 16))^ Shr 6) And $3e0) Or
-                       (((Pint32(source) + (x Shr 16))^ Shl 7) And $7c00);
+  if (PtrUInt(dest) and 3) <> 0 then
+  begin
+    PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 19) and $1f) or
+                       (((PUint32(source) + (x shr 16))^ shr 6) and $3e0) or
+                       (((PUint32(source) + (x shr 16))^ shl 7) and $7c00);
     Inc(x, inc_source);
     Inc(dest, 2);
     Dec(count);
-  End;
+  end;
 
   { Try to write 2 pixel blocks }
-  c := count Shr 1;
-  While c <> 0 Do
-  Begin
+  c := count shr 1;
+  while c <> 0 do
+  begin
     Dec(c);
-    p := (((Pint32(source) + (x Shr 16))^ Shr 19) And $1f) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 6) And $3e0) Or
-         (((Pint32(source) + (x Shr 16))^ Shl 7) And $7c00);
+    p := ((((PUint32(source) + (x shr 16))^ shr 19) and $1f) or
+          (((PUint32(source) + (x shr 16))^ shr 6) and $3e0) or
+          (((PUint32(source) + (x shr 16))^ shl 7) and $7c00)) shl DWORD_SMALLINT0_SHL;
     Inc(x, inc_source);
 
-    p := p Or
-       (((((Pint32(source) + (x Shr 16))^ Shr 19) And $1f) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 6) And $3e0) Or
-         (((Pint32(source) + (x Shr 16))^ Shl 7) And $7c00)) Shl 16);
+    p := p or
+       (((((PUint32(source) + (x shr 16))^ shr 19) and $1f) or
+         (((PUint32(source) + (x shr 16))^ shr 6) and $3e0) or
+         (((PUint32(source) + (x shr 16))^ shl 7) and $7c00)) shl DWORD_SMALLINT1_SHL);
     Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
 
     Inc(dest, 4);
-  End;
+  end;
 
   { Write trailing pixel }
-  If (count And 1) <> 0 Then
-    Pshort16(dest)^ := (((Pint32(source) + (x Shr 16))^ Shr 19) And $1f) Or
-                       (((Pint32(source) + (x Shr 16))^ Shr 6) And $3e0) Or
-                       (((Pint32(source) + (x Shr 16))^ Shl 7) And $7c00);
-End;
-
-Procedure ConvertP_32rgb888_8rgb332_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x, c : DWord;
-  p : int32;
-
-Begin
+  if (count and 1) <> 0 then
+    PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 19) and $1f) or
+                       (((PUint32(source) + (x shr 16))^ shr 6) and $3e0) or
+                       (((PUint32(source) + (x shr 16))^ shl 7) and $7c00);
+end;
+
+procedure ConvertP_32rgb888_8rgb332_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x, c: DWord;
+  p: Uint32;
+begin
   x := 0;
   { Write single pixels until the destination address is aligned mod 4 }
-  While (PtrUInt(dest) And $3) <> 0 Do
-  Begin
-    dest^ := (((Pint32(source) + (x Shr 16))^ Shr 16) And $e0) Or
-             (((Pint32(source) + (x Shr 16))^ Shr 11) And $1c) Or
-             (((Pint32(source) + (x Shr 16))^ Shr 6) And $3);
+  while (PtrUInt(dest) and $3) <> 0 do
+  begin
+    dest^ := (((PUint32(source) + (x shr 16))^ shr 16) and $e0) or
+             (((PUint32(source) + (x shr 16))^ shr 11) and $1c) or
+             (((PUint32(source) + (x shr 16))^ shr 6) and $3);
     Inc(x, inc_source);
     Inc(dest);
     Dec(count);
-    If count = 0 Then
-      Exit;
-  End;
+    if count = 0 then
+      exit;
+  end;
 
   { Write blocks of four pixels now }
-  c := count Shr 2;
-  While c <> 0 Do
-  Begin
+  c := count shr 2;
+  while c <> 0 do
+  begin
     Dec(c);
-    p := (((Pint32(source) + (x Shr 16))^ Shr 16) And $e0) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 11) And $1c) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 6) And $3);
+    p := ((((PUint32(source) + (x shr 16))^ shr 16) and $e0) or
+          (((PUint32(source) + (x shr 16))^ shr 11) and $1c) or
+          (((PUint32(source) + (x shr 16))^ shr 6) and $3)) shl DWORD_BYTE0_SHL;
     Inc(x, inc_source);
 
-    p := p Or
-       (((((Pint32(source) + (x Shr 16))^ Shr 16) And $e0) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 11) And $1c) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 6) And $3)) Shl 8);
+    p := p or
+       (((((PUint32(source) + (x shr 16))^ shr 16) and $e0) or
+         (((PUint32(source) + (x shr 16))^ shr 11) and $1c) or
+         (((PUint32(source) + (x shr 16))^ shr 6) and $3)) shl DWORD_BYTE1_SHL);
     Inc(x, inc_source);
 
-    p := p Or
-       (((((Pint32(source) + (x Shr 16))^ Shr 16) And $e0) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 11) And $1c) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 6) And $3)) Shl 16);
+    p := p or
+       (((((PUint32(source) + (x shr 16))^ shr 16) and $e0) or
+         (((PUint32(source) + (x shr 16))^ shr 11) and $1c) or
+         (((PUint32(source) + (x shr 16))^ shr 6) and $3)) shl DWORD_BYTE2_SHL);
     Inc(x, inc_source);
 
-    p := p Or
-       (((((Pint32(source) + (x Shr 16))^ Shr 16) And $e0) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 11) And $1c) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 6) And $3)) Shl 24);
+    p := p or
+       (((((PUint32(source) + (x shr 16))^ shr 16) and $e0) or
+         (((PUint32(source) + (x shr 16))^ shr 11) and $1c) or
+         (((PUint32(source) + (x shr 16))^ shr 6) and $3)) shl DWORD_BYTE3_SHL);
     Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
     Inc(dest, 4);
-  End;
+  end;
 
   { Write up to three trailing pixels }
-  c := count And $3;
-  While c <> 0 Do
-  Begin
+  c := count and $3;
+  while c <> 0 do
+  begin
     Dec(c);
-    dest^ := (((Pint32(source) + (x Shr 16))^ Shr 16) And $e0) Or
-             (((Pint32(source) + (x Shr 16))^ Shr 11) And $1c) Or
-             (((Pint32(source) + (x Shr 16))^ Shr 6) And $3);
+    dest^ := (((PUint32(source) + (x shr 16))^ shr 16) and $e0) or
+             (((PUint32(source) + (x shr 16))^ shr 11) and $1c) or
+             (((PUint32(source) + (x shr 16))^ shr 6) and $3);
     Inc(x, inc_source);
     Inc(dest);
-  End;
-End;
+  end;
+end;

+ 92 - 89
packages/hermes/src/p_clr.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -27,145 +39,136 @@
    licensing conditions
 }
 
-Procedure ClearP_32(iface : PHermesClearInterface); CDecl;
-
-Var
-  count : DWord;
-  value : int32;
-  dest : Pchar8;
-
-Begin
+procedure ClearP_32(iface: PHermesClearInterface); cdecl;
+var
+  count: DWord;
+  value: Uint32;
+  dest: PUint8;
+begin
   value := iface^.value;
   dest := iface^.dest;
-  Repeat
+  repeat
     count := iface^.width;
-    Repeat
-      Pint32(dest)^ := value;
+    repeat
+      PUint32(dest)^ := value;
       Inc(dest, 4);
       Dec(count);
-    Until count = 0;
+    until count = 0;
     Inc(dest, iface^.add);
     Dec(iface^.height);
-  Until iface^.height = 0;
-End;
-
-Procedure ClearP_24(iface : PHermesClearInterface); CDecl;
-
-Var
-  p_value : Pchar8;
-  count : DWord;
-  dest : Pchar8;
-
-Begin
-  p_value := @iface^.value;
+  until iface^.height = 0;
+end;
+
+procedure ClearP_24(iface: PHermesClearInterface); cdecl;
+var
+  p_value: PUint8;
+  count: DWord;
+  dest: PUint8;
+begin
+  p_value := PUint8(@iface^.value) + (R_32 - R_24);
   dest := iface^.dest;
-  Repeat
+  repeat
     count := iface^.width;
-    Repeat
-      (dest + R_24)^ := (p_value + B_32)^;
-      (dest + G_24)^ := (p_value + G_32)^;
-      (dest + B_24)^ := (p_value + B_32)^;
+    repeat
+      (dest + 0)^ := (p_value + 0)^;
+      (dest + 1)^ := (p_value + 1)^;
+      (dest + 2)^ := (p_value + 2)^;
 
       Inc(dest, 3);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(dest, iface^.add);
     Dec(iface^.height);
-  Until iface^.height = 0;
-End;
-
-Procedure ClearP_16(iface : PHermesClearInterface); CDecl;
-
-Var
-  value32 : DWord;
-  countshifted, count : DWord;
-  dest : Pchar8;
-
-Begin
-  value32 := (iface^.value Shl 16) Or (iface^.value And $ffff);
+  until iface^.height = 0;
+end;
+
+procedure ClearP_16(iface: PHermesClearInterface); cdecl;
+var
+  value32: DWord;
+  countshifted, count: DWord;
+  dest: PUint8;
+begin
+  value32 := (iface^.value shl 16) or (iface^.value and $ffff);
   dest := iface^.dest;
-  Repeat
+  repeat
     count := iface^.width;
 
     { Align destination }
-    If (PtrUInt(dest) And $3) <> 0 Then
-    Begin
-      Pshort16(dest)^ := iface^.value;
+    if (PtrUInt(dest) and $3) <> 0 then
+    begin
+      PUint16(dest)^ := iface^.value;
       Inc(dest, 2);
       Dec(count);
-    End;
+    end;
 
-    countshifted := count Shr 1;
+    countshifted := count shr 1;
 
-    While countshifted <> 0 Do
-    Begin
+    while countshifted <> 0 do
+    begin
       Dec(countshifted);
-      Pint32(dest)^ := value32;
+      PUint32(dest)^ := value32;
       Inc(dest, 4);
-    End;
+    end;
 
-    If (count And 1) <> 0 Then
-    Begin
-      Pshort16(dest)^ := iface^.value;
+    if (count and 1) <> 0 then
+    begin
+      PUint16(dest)^ := iface^.value;
       Inc(dest, 2);
-    End;
+    end;
 
     Inc(dest, iface^.add);
     Dec(iface^.height);
-  Until iface^.height = 0;
-End;
+  until iface^.height = 0;
+end;
 
 {$GOTO ON}
 
-Procedure ClearP_8(iface : PHermesClearInterface); CDecl;
-
-Label
+procedure ClearP_8(iface: PHermesClearInterface); cdecl;
+label
   yloop;
-
-Var
-  count, shiftcount : DWord;
-  value32 : int32;
-  value : char8;
-  dest : Pchar8;
-
-Begin
+var
+  count, shiftcount: DWord;
+  value32: Uint32;
+  value: Uint8;
+  dest: PUint8;
+begin
   dest := iface^.dest;
 
-  value := iface^.value And $ff;
-  value32 := (value Shl 24) Or (value Shl 16) Or (value Shl 8) Or value;
+  value := iface^.value and $ff;
+  value32 := (value shl 24) or (value shl 16) or (value shl 8) or value;
 
-  Repeat
+  repeat
     count := iface^.width;
 
-    While (PtrUInt(dest) And $3) <> 0 Do    { Align to dword boundary }
-    Begin
+    while (PtrUInt(dest) and $3) <> 0 do    { Align to dword boundary }
+    begin
       dest^ := value;
       Inc(dest);
       Dec(count);
-      If count = 0 Then
-        Goto yloop;                { GOTO's are nice ;) }
-    End;
+      if count = 0 then
+        goto yloop;                { GOTO's are nice ;) }
+    end;
 
-    shiftcount := count Shr 2;
+    shiftcount := count shr 2;
 
-    While shiftcount <> 0 Do
-    Begin
+    while shiftcount <> 0 do
+    begin
       Dec(shiftcount);
-      Pint32(dest)^ := value32;
+      PUint32(dest)^ := value32;
       Inc(dest, 4);
-    End;
+    end;
 
-    count := count And $3;
-    While count <> 0 Do
-    Begin
+    count := count and $3;
+    while count <> 0 do
+    begin
       Dec(count);
       dest^ := value;
       Inc(dest);
-    End;
+    end;
 
 yloop:
     Inc(dest, iface^.add);
     Dec(iface^.height);
-  Until iface^.height = 0;
-End;
+  until iface^.height = 0;
+end;

+ 30 - 21
packages/hermes/src/p_cnv.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -27,32 +39,29 @@
    licensing conditions
 }
 
-Procedure ConvertP(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP(iface: PHermesConverterInterface); cdecl;
+begin
   { Simply loop through all scanlines }
-  Repeat
+  repeat
     iface^.func(iface^.s_pixels, iface^.d_pixels, iface^.d_width, 1);
 
     Inc(iface^.s_pixels, iface^.s_pitch);
     Inc(iface^.d_pixels, iface^.d_pitch);
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
-
-Procedure ConvertPStretch(iface : PHermesConverterInterface); CDecl;
-
-Var
-  dx, dy : DWord;
-  y : DWord;
+  until iface^.d_height = 0;
+end;
 
-Begin
+procedure ConvertPStretch(iface: PHermesConverterInterface); cdecl;
+var
+  dx, dy: DWord;
+  y: DWord;
+begin
   y := 0;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
 
   { We have the increment of y and x on the source surface now let's start }
-  Repeat
+  repeat
     iface^.func(iface^.s_pixels, iface^.d_pixels, iface^.d_width, dx);
 
     Inc(iface^.d_pixels, iface^.d_pitch);
@@ -60,8 +69,8 @@ Begin
     Inc(y, dy);
 
     { Check how many lines we need to step forward }
-    Inc(iface^.s_pixels, (y Shr 16)*DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(iface^.s_pixels, (y shr 16)*DWord(iface^.s_pitch));
+    y := y and $ffff;
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
+  until iface^.d_height = 0;
+end;

+ 93 - 93
packages/hermes/src/p_cpy.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -27,141 +39,129 @@
    licensing conditions
 }
 
-Procedure CopyP_4byte(source, dest : Pchar8; count, inc_source : DWord); CDecl;
+procedure CopyP_4byte(source, dest: PUint8; count, inc_source: DWord); cdecl;
+begin
+  Move(source^, dest^, count shl 2);
+end;
 
-Begin
-  Move(source^, dest^, count Shl 2);
-End;
-
-Procedure CopyP_3byte(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Begin
+procedure CopyP_3byte(source, dest: PUint8; count, inc_source: DWord); cdecl;
+begin
   Move(source^, dest^, count * 3);
-End;
-
-Procedure CopyP_2byte(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Begin
-  Move(source^, dest^, count Shl 1);
-End;
+end;
 
-Procedure CopyP_1byte(source, dest : Pchar8; count, inc_source : DWord); CDecl;
+procedure CopyP_2byte(source, dest: PUint8; count, inc_source: DWord); cdecl;
+begin
+  Move(source^, dest^, count shl 1);
+end;
 
-Begin
+procedure CopyP_1byte(source, dest: PUint8; count, inc_source: DWord); cdecl;
+begin
   Move(source^, dest^, count);
-End;
+end;
 
-Procedure CopyP_4byte_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x : DWord;
-
-Begin
+procedure CopyP_4byte_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+begin
   x := 0;
-  Repeat
-    Pint32(dest)^ := (Pint32(source)+(x Shr 16))^;
+  repeat
+    PUint32(dest)^ := (PUint32(source)+(x shr 16))^;
 
     Inc(x, inc_source);
     Inc(dest, 4);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
 { TODO: Optimise }
-Procedure CopyP_3byte_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x : DWord;
-
-Begin
+procedure CopyP_3byte_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+begin
   x := 0;
-  Repeat
-    dest[R_24] := source[R_24];
-    dest[G_24] := source[G_24];
-    dest[B_24] := source[B_24];
+  repeat
+    dest[0] := source[0];
+    dest[1] := source[1];
+    dest[2] := source[2];
 
     Inc(x, inc_source);
-    Inc(source, 3*(x Shr 16));
-    x := x And $FFFF;
+    Inc(source, 3*(x shr 16));
+    x := x and $FFFF;
     Inc(dest, 3);
     Dec(count);
-  Until count = 0;
-End;
-
-Procedure CopyP_2byte_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x, c : DWord;
-  p : int32;
-
-Begin
+  until count = 0;
+end;
+
+procedure CopyP_2byte_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x, c: DWord;
+  p: Uint32;
+begin
   x := 0;
   { Alignment mod 4 }
-  If (PtrUInt(dest) And 3) <> 0 Then
-  Begin
-    Pshort16(dest)^ := (Pshort16(source) + (x Shr 16))^;
+  if (PtrUInt(dest) and 3) <> 0 then
+  begin
+    PUint16(dest)^ := (PUint16(source) + (x shr 16))^;
     Inc(x, inc_source);
     Inc(dest, 2);
     Dec(count);
-  End;
+  end;
 
-  c := count Shr 1;
+  c := count shr 1;
 
-  While c <> 0 Do
-  Begin
+  while c <> 0 do
+  begin
     Dec(c);
     { TODO: make fast :) }
-    p := (Pshort16(source) + (x Shr 16))^; Inc(x, inc_source);
-    p := p Or ((Pshort16(source) + (x Shr 16))^ Shl 16);
+    p := (PUint16(source) + (x shr 16))^ shl DWORD_SMALLINT0_SHL; Inc(x, inc_source);
+    p := p or ((PUint16(source) + (x shr 16))^ shl DWORD_SMALLINT1_SHL);
     Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
     Inc(dest, 4);
-  End;
-
-  If (count And 1) <> 0 Then
-    Pshort16(dest)^ := (Pshort16(source) + (x Shr 16))^;
-End;
-
-Procedure CopyP_1byte_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
+  end;
 
-Var
-  x, c : DWord;
-  p : int32;
+  if (count and 1) <> 0 then
+    PUint16(dest)^ := (PUint16(source) + (x shr 16))^;
+end;
 
-Begin
+procedure CopyP_1byte_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x, c: DWord;
+  p: Uint32;
+begin
   x := 0;
   { Alignment mod 4 }
-  While (PtrUInt(dest) And 3) <> 0 Do
-  Begin
-    dest^ := (source + (x Shr 16))^;
+  while (PtrUInt(dest) and 3) <> 0 do
+  begin
+    dest^ := (source + (x shr 16))^;
     Inc(x, inc_source);
     Inc(dest); Dec(count);
-    If count = 0 Then
-      Exit;
-  End;
+    if count = 0 then
+      exit;
+  end;
 
   { Write blocks of four pixels }
-  c := count Shr 2;
-  While c <> 0 Do
-  Begin
+  c := count shr 2;
+  while c <> 0 do
+  begin
     Dec(c);
-    p := (source + (x Shr 16))^; Inc(x, inc_source);
-    p := p Or ((source + (x Shr 16))^ Shl 8); Inc(x, inc_source);
-    p := p Or ((source + (x Shr 16))^ Shl 16); Inc(x, inc_source);
-    p := p Or ((source + (x Shr 16))^ Shl 24); Inc(x, inc_source);
+    p := (source + (x shr 16))^ shl DWORD_BYTE0_SHL; Inc(x, inc_source);
+    p := p or ((source + (x shr 16))^ shl DWORD_BYTE1_SHL); Inc(x, inc_source);
+    p := p or ((source + (x shr 16))^ shl DWORD_BYTE2_SHL); Inc(x, inc_source);
+    p := p or ((source + (x shr 16))^ shl DWORD_BYTE3_SHL); Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
     Inc(dest, 4);
-  End;
+  end;
 
   { Write up to three trailing pixels }
-  c := count And $3;
-  While c <> 0 Do
-  Begin
+  c := count and $3;
+  while c <> 0 do
+  begin
     Dec(c);
-    dest^ := (source + (x Shr 16))^;
+    dest^ := (source + (x shr 16))^;
     Inc(x, inc_source);
     Inc(dest);
-  End;
-End;
+  end;
+end;

+ 570 - 614
packages/hermes/src/p_g.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -27,491 +39,463 @@
    licensing conditions
 }
 
-Procedure ConvertP_Generic32_Generic32(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+procedure ConvertP_Generic32_Generic32(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := Pint32(source)^;
+    repeat
+      s_pixel := PUint32(source)^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      Pint32(dest)^ := r Or g Or b;
+      PUint32(dest)^ := r or g or b;
 
       Inc(source, 4);
       Inc(dest, 4);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic32_Generic24(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  d_ptr : Pchar8;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
-  d_ptr := @s_pixel;
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic32_Generic24(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  d_ptr: PUint8;
+  count: DWord;
+  source, dest: PUint8;
+begin
+  d_ptr := PUint8(@s_pixel) + (R_32 - R_24);
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := Pint32(source)^;
+    repeat
+      s_pixel := PUint32(source)^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      s_pixel := r Or g Or b;
+      s_pixel := r or g or b;
 
-      (dest+R_24)^ := (d_ptr+R_32)^;
-      (dest+G_24)^ := (d_ptr+G_32)^;
-      (dest+B_24)^ := (d_ptr+B_32)^;
+      (dest+0)^ := (d_ptr+0)^;
+      (dest+1)^ := (d_ptr+1)^;
+      (dest+2)^ := (d_ptr+2)^;
 
       Inc(source, 4);
       Inc(dest, 3);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic32_Generic16(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic32_Generic16(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
-    count := iface^.s_width Shr 1;
+  repeat
+    count := iface^.s_width shr 1;
 
-    If count <> 0 Then
-      Repeat
-        r := (((Pint32(source)^) Shr iface^.info.r_right) Shl iface^.info.r_left) And
+    if count <> 0 then
+      repeat
+        r := (((PUint32(source)^) shr iface^.info.r_right) shl iface^.info.r_left) and
               iface^.mask_r;
-        g := (((Pint32(source)^) Shr iface^.info.g_right) Shl iface^.info.g_left) And
+        g := (((PUint32(source)^) shr iface^.info.g_right) shl iface^.info.g_left) and
               iface^.mask_g;
-        b := (((Pint32(source)^) Shr iface^.info.b_right) Shl iface^.info.b_left) And
+        b := (((PUint32(source)^) shr iface^.info.b_right) shl iface^.info.b_left) and
               iface^.mask_b;
 
-        s_pixel := (r Or g Or b) And $FFFF;
+        s_pixel := (r or g or b) shl DWORD_SMALLINT0_SHL;
 
-        r := ((((Pint32(source)+1)^) Shr iface^.info.r_right) Shl iface^.info.r_left) And
+        r := ((((PUint32(source)+1)^) shr iface^.info.r_right) shl iface^.info.r_left) and
               iface^.mask_r;
-        g := ((((Pint32(source)+1)^) Shr iface^.info.g_right) Shl iface^.info.g_left) And
+        g := ((((PUint32(source)+1)^) shr iface^.info.g_right) shl iface^.info.g_left) and
               iface^.mask_g;
-        b := ((((Pint32(source)+1)^) Shr iface^.info.b_right) Shl iface^.info.b_left) And
+        b := ((((PUint32(source)+1)^) shr iface^.info.b_right) shl iface^.info.b_left) and
               iface^.mask_b;
 
-        s_pixel := s_pixel Or ((r Or g Or b) Shl 16);
+        s_pixel := s_pixel or ((r or g or b) shl DWORD_SMALLINT1_SHL);
 
-        Pint32(dest)^ := s_pixel;
+        PUint32(dest)^ := s_pixel;
 
         Inc(source, 8);
         Inc(dest, 4);
         Dec(count);
-      Until count = 0;
+      until count = 0;
 
 
     { Trailing pixel }
 
-    If (iface^.s_width And 1) <> 0 Then
-    Begin
-      r := (((Pint32(source)^) Shr iface^.info.r_right) Shl iface^.info.r_left) And
+    if (iface^.s_width and 1) <> 0 then
+    begin
+      r := (((PUint32(source)^) shr iface^.info.r_right) shl iface^.info.r_left) and
             iface^.mask_r;
-      g := (((Pint32(source)^) Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := (((PUint32(source)^) shr iface^.info.g_right) shl iface^.info.g_left) and
             iface^.mask_g;
-      b := (((Pint32(source)^) Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := (((PUint32(source)^) shr iface^.info.b_right) shl iface^.info.b_left) and
             iface^.mask_b;
 
-      Pshort16(dest)^ := r Or g Or b;
+      PUint16(dest)^ := r or g or b;
       Inc(dest, 2);
       Inc(source, 4);
-    End;
+    end;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic32_Generic8(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic32_Generic8(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := Pint32(source)^;
+    repeat
+      s_pixel := PUint32(source)^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      dest^ := r Or g Or b;
+      dest^ := r or g or b;
 
       Inc(source, 4);
       Inc(dest);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic24_Generic32(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic24_Generic32(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := (((source+R_24)^) Shl 16) Or
-                 (((source+G_24)^) Shl 8) Or
+    repeat
+      s_pixel := (((source+R_24)^) shl 16) or
+                 (((source+G_24)^) shl 8) or
                  ((source+B_24)^);
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      Pint32(dest)^ := r Or g Or b;
+      PUint32(dest)^ := r or g or b;
 
       Inc(source, 3);
       Inc(dest, 4);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic24_Generic24(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  d_ptr : Pchar8;
-  count : DWord;
-  source, dest : PChar8;
-
-Begin
-  d_ptr := @s_pixel;
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic24_Generic24(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  d_ptr: PUint8;
+  count: DWord;
+  source, dest: PUint8;
+begin
+  d_ptr := PUint8(@s_pixel) + (R_32 - R_24);
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := (((source+R_24)^) Shl 16) Or
-                 (((source+G_24)^) Shl 8) Or
+    repeat
+      s_pixel := (((source+R_24)^) shl 16) or
+                 (((source+G_24)^) shl 8) or
                  ((source+B_24)^);
 
-      r := ((s_pixel Shl iface^.info.r_left) Shr iface^.info.r_right) And
+      r := ((s_pixel shl iface^.info.r_left) shr iface^.info.r_right) and
         iface^.mask_r;
-      g := ((s_pixel Shl iface^.info.g_left) Shr iface^.info.g_right) And
+      g := ((s_pixel shl iface^.info.g_left) shr iface^.info.g_right) and
         iface^.mask_g;
-      b := ((s_pixel Shl iface^.info.b_left) Shr iface^.info.b_right) And
+      b := ((s_pixel shl iface^.info.b_left) shr iface^.info.b_right) and
         iface^.mask_b;
 
-      s_pixel := r Or g Or b;
+      s_pixel := r or g or b;
 
-      (dest + R_24)^ := (d_ptr + R_32)^;
-      (dest + G_24)^ := (d_ptr + G_32)^;
-      (dest + B_24)^ := (d_ptr + B_32)^;
+      (dest + 0)^ := (d_ptr + 0)^;
+      (dest + 1)^ := (d_ptr + 1)^;
+      (dest + 2)^ := (d_ptr + 2)^;
 
       Inc(source, 3);
       Inc(dest, 3);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic24_Generic16(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic24_Generic16(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := (((source+R_24)^) Shl 16) Or
-                 (((source+G_24)^) Shl 8) Or
+    repeat
+      s_pixel := (((source+R_24)^) shl 16) or
+                 (((source+G_24)^) shl 8) or
                  ((source+B_24)^);
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      Pshort16(dest)^ := r Or g Or b;
+      PUint16(dest)^ := r or g or b;
 
       Inc(source, 3);
       Inc(dest, 2);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic24_Generic8(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic24_Generic8(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := (((source+R_24)^) Shl 16) Or
-                 (((source+G_24)^) Shl 8) Or
+    repeat
+      s_pixel := (((source+R_24)^) shl 16) or
+                 (((source+G_24)^) shl 8) or
                  ((source+B_24)^);
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      dest^ := r Or g Or b;
+      dest^ := r or g or b;
 
       Inc(source, 3);
       Inc(dest);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic16_Generic32(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic16_Generic32(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := Pshort16(source)^;
+    repeat
+      s_pixel := PUint16(source)^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      Pint32(dest)^ := r Or g Or b;
+      PUint32(dest)^ := r or g or b;
 
       Inc(source, 2);
       Inc(dest, 4);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic16_Generic24(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  d_ptr : Pchar8;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
-  d_ptr := @s_pixel;
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic16_Generic24(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  d_ptr: PUint8;
+  count: DWord;
+  source, dest: PUint8;
+begin
+  d_ptr := PUint8(@s_pixel) + (R_32 - R_24);
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := Pshort16(source)^;
+    repeat
+      s_pixel := PUint16(source)^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      s_pixel := r Or g Or b;
+      s_pixel := r or g or b;
 
-      (dest + R_24)^ := (d_ptr + R_32)^;
-      (dest + G_24)^ := (d_ptr + G_32)^;
-      (dest + B_24)^ := (d_ptr + B_32)^;
+      (dest + 0)^ := (d_ptr + 0)^;
+      (dest + 1)^ := (d_ptr + 1)^;
+      (dest + 2)^ := (d_ptr + 2)^;
 
       Inc(source, 2);
       Inc(dest, 3);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic16_Generic16(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic16_Generic16(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := Pshort16(source)^;
+    repeat
+      s_pixel := PUint16(source)^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      Pshort16(dest)^ := r Or g Or b;
+      PUint16(dest)^ := r or g or b;
 
       Inc(source, 2);
       Inc(dest, 2);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic16_Generic8(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic16_Generic8(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := Pshort16(source)^;
+    repeat
+      s_pixel := PUint16(source)^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      dest^ := r Or g Or b;
+      dest^ := r or g or b;
 
       Inc(source, 2);
       Inc(dest);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
+  until iface^.s_height = 0;
+end;
 
-Procedure ConvertP_Generic8_Generic32(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic8_Generic32(iface: PHermesConverterInterface); cdecl;
+begin
   {todo}
-End;
-
-Procedure ConvertP_Generic8_Generic24(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic8_Generic24(iface: PHermesConverterInterface); cdecl;
+begin
   {todo}
-End;
+end;
 
-Procedure ConvertP_Generic8_Generic16(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic8_Generic16(iface: PHermesConverterInterface); cdecl;
+begin
   {todo}
-End;
-
-Procedure ConvertP_Generic8_Generic8(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic8_Generic8(iface: PHermesConverterInterface); cdecl;
+begin
   {todo}
-End;
+end;
 
 { -------------------------------------------------------------------------
 
@@ -519,600 +503,572 @@ End;
 
   ------------------------------------------------------------------------- }
 
-Procedure ConvertP_Generic32_Generic32_S(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, dest : Pchar8;
-  dx, dy, x, y : DWord;
-
-Begin
+procedure ConvertP_Generic32_Generic32_S(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+  dx, dy, x, y: DWord;
+begin
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   y := 0;
-  Repeat
+  repeat
     count := iface^.d_width;
     x := 0;
-    Repeat
-      s_pixel := (Pint32(source)+(x Shr 16))^;
+    repeat
+      s_pixel := (PUint32(source)+(x shr 16))^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      Pint32(dest)^ := r Or g Or b;
+      PUint32(dest)^ := r or g or b;
 
       Inc(x, dx);
       Inc(dest, 4);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(dest, iface^.d_add);
 
     Inc(y, dy);
-    Inc(source, (y Shr 16)*DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16)*DWord(iface^.s_pitch));
+    y := y and $ffff;
 
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
-
-Procedure ConvertP_Generic32_Generic24_S(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  d_ptr : Pchar8;
-  count : DWord;
-  source, dest : Pchar8;
-  dx, dy, x, y : DWord;
-
-Begin
-  d_ptr := @s_pixel;
+  until iface^.d_height = 0;
+end;
+
+procedure ConvertP_Generic32_Generic24_S(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  d_ptr: PUint8;
+  count: DWord;
+  source, dest: PUint8;
+  dx, dy, x, y: DWord;
+begin
+  d_ptr := PUint8(@s_pixel) + (R_32 - R_24);
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   y := 0;
-  Repeat
+  repeat
     count := iface^.d_width;
     x := 0;
-    Repeat
-      s_pixel := (Pint32(source)+(x Shr 16))^;
+    repeat
+      s_pixel := (PUint32(source)+(x shr 16))^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      s_pixel := r Or g Or b;
+      s_pixel := r or g or b;
 
-      (dest + R_24)^ := (d_ptr + R_32)^;
-      (dest + G_24)^ := (d_ptr + G_32)^;
-      (dest + B_24)^ := (d_ptr + B_32)^;
+      (dest + 0)^ := (d_ptr + 0)^;
+      (dest + 1)^ := (d_ptr + 1)^;
+      (dest + 2)^ := (d_ptr + 2)^;
 
       Inc(x, dx);
       Inc(dest, 3);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(dest, iface^.d_add);
 
     Inc(y, dy);
-    Inc(source, (y Shr 16)*DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16)*DWord(iface^.s_pitch));
+    y := y and $ffff;
 
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
-
-Procedure ConvertP_Generic32_Generic16_S(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, dest : Pchar8;
-  dx, dy, x, y : DWord;
-
-Begin
+  until iface^.d_height = 0;
+end;
+
+procedure ConvertP_Generic32_Generic16_S(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+  dx, dy, x, y: DWord;
+begin
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   y := 0;
-  Repeat
+  repeat
     count := iface^.d_width;
     x := 0;
-    Repeat
-      s_pixel := (Pint32(source)+(x Shr 16))^;
+    repeat
+      s_pixel := (PUint32(source)+(x shr 16))^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      Pshort16(dest)^ := r Or g Or b;
+      PUint16(dest)^ := r or g or b;
 
       Inc(x, dx);
       Inc(dest, 2);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(dest, iface^.d_add);
 
     Inc(y, dy);
-    Inc(source, (y Shr 16)*DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16)*DWord(iface^.s_pitch));
+    y := y and $ffff;
 
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
-
-Procedure ConvertP_Generic32_Generic8_S(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, dest : Pchar8;
-  dx, dy, x, y : DWord;
-
-Begin
+  until iface^.d_height = 0;
+end;
+
+procedure ConvertP_Generic32_Generic8_S(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+  dx, dy, x, y: DWord;
+begin
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   y := 0;
-  Repeat
+  repeat
     count := iface^.d_width;
     x := 0;
-    Repeat
-      s_pixel := (Pint32(source)+(x Shr 16))^;
+    repeat
+      s_pixel := (PUint32(source)+(x shr 16))^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      dest^ := r Or g Or b;
+      dest^ := r or g or b;
 
       Inc(x, dx);
       Inc(dest);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(dest, iface^.d_add);
 
     Inc(y, dy);
-    Inc(source, (y Shr 16)*DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16)*DWord(iface^.s_pitch));
+    y := y and $ffff;
 
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
-
-Procedure ConvertP_Generic24_Generic32_S(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, src, dest : Pchar8;
-  dx, dy, x, y : DWord;
-
-Begin
+  until iface^.d_height = 0;
+end;
+
+procedure ConvertP_Generic24_Generic32_S(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, src, dest: PUint8;
+  dx, dy, x, y: DWord;
+begin
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   y := 0;
-  Repeat
+  repeat
     count := iface^.d_width;
     x := 0;
     src := source;
-    Repeat
-      s_pixel := (((src+R_24)^) Shl 16) Or
-                 (((src+G_24)^) Shl 8) Or
+    repeat
+      s_pixel := (((src+R_24)^) shl 16) or
+                 (((src+G_24)^) shl 8) or
                  ((src+B_24)^);
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      Pint32(dest)^ := r Or g Or b;
+      PUint32(dest)^ := r or g or b;
 
       Inc(x, dx);
-      Inc(src, x Shr 16);
-      Inc(src, x Shr 16);
-      Inc(src, x Shr 16);
-      x := x And $FFFF;
+      Inc(src, x shr 16);
+      Inc(src, x shr 16);
+      Inc(src, x shr 16);
+      x := x and $FFFF;
       Inc(dest, 4);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(dest, iface^.d_add);
 
     Inc(y, dy);
-    Inc(source, (y Shr 16)*DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16)*DWord(iface^.s_pitch));
+    y := y and $ffff;
 
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
-
-Procedure ConvertP_Generic24_Generic24_S(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  d_ptr : Pchar8;
-  count : DWord;
-  source, src, dest : Pchar8;
-  dx, dy, x, y : DWord;
-
-Begin
-  d_ptr := @s_pixel;
+  until iface^.d_height = 0;
+end;
+
+procedure ConvertP_Generic24_Generic24_S(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  d_ptr: PUint8;
+  count: DWord;
+  source, src, dest: PUint8;
+  dx, dy, x, y: DWord;
+begin
+  d_ptr := PUint8(@s_pixel) + (R_32 - R_24);
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   y := 0;
-  Repeat
+  repeat
     count := iface^.d_width;
     x := 0;
     src := source;
-    Repeat
-      s_pixel := (((src+R_24)^) Shl 16) Or
-                 (((src+G_24)^) Shl 8) Or
+    repeat
+      s_pixel := (((src+R_24)^) shl 16) or
+                 (((src+G_24)^) shl 8) or
                  ((src+B_24)^);
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      s_pixel := r Or g Or b;
+      s_pixel := r or g or b;
 
-      (dest + R_24)^ := (d_ptr + R_32)^;
-      (dest + G_24)^ := (d_ptr + G_32)^;
-      (dest + B_24)^ := (d_ptr + B_32)^;
+      (dest + 0)^ := (d_ptr + 0)^;
+      (dest + 1)^ := (d_ptr + 1)^;
+      (dest + 2)^ := (d_ptr + 2)^;
 
       Inc(x, dx);
-      Inc(src, x Shr 16);
-      Inc(src, x Shr 16);
-      Inc(src, x Shr 16);
-      x := x And $FFFF;
+      Inc(src, x shr 16);
+      Inc(src, x shr 16);
+      Inc(src, x shr 16);
+      x := x and $FFFF;
       Inc(dest, 3);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(dest, iface^.d_add);
 
     Inc(y, dy);
-    Inc(source, (y Shr 16)*DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16)*DWord(iface^.s_pitch));
+    y := y and $ffff;
 
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
-
-Procedure ConvertP_Generic24_Generic16_S(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, src, dest : Pchar8;
-  dx, dy, x, y : DWord;
-
-Begin
+  until iface^.d_height = 0;
+end;
+
+procedure ConvertP_Generic24_Generic16_S(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, src, dest: PUint8;
+  dx, dy, x, y: DWord;
+begin
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   y := 0;
-  Repeat
+  repeat
     count := iface^.d_width;
     x := 0;
     src := source;
-    Repeat
-      s_pixel := (((src+R_24)^) Shl 16) Or
-                 (((src+G_24)^) Shl 8) Or
+    repeat
+      s_pixel := (((src+R_24)^) shl 16) or
+                 (((src+G_24)^) shl 8) or
                  ((src+B_24)^);
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      Pshort16(dest)^ := r Or g Or b;
+      PUint16(dest)^ := r or g or b;
 
       Inc(x, dx);
-      Inc(src, x Shr 16);
-      Inc(src, x Shr 16);
-      Inc(src, x Shr 16);
-      x := x And $FFFF;
+      Inc(src, x shr 16);
+      Inc(src, x shr 16);
+      Inc(src, x shr 16);
+      x := x and $FFFF;
       Inc(dest, 2);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(dest, iface^.d_add);
 
     Inc(y, dy);
-    Inc(source, (y Shr 16)*DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16)*DWord(iface^.s_pitch));
+    y := y and $ffff;
 
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
-
-Procedure ConvertP_Generic24_Generic8_S(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, src, dest : Pchar8;
-  dx, dy, x, y : DWord;
-
-Begin
+  until iface^.d_height = 0;
+end;
+
+procedure ConvertP_Generic24_Generic8_S(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, src, dest: PUint8;
+  dx, dy, x, y: DWord;
+begin
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   y := 0;
-  Repeat
+  repeat
     count := iface^.d_width;
     x := 0;
     src := source;
-    Repeat
-      s_pixel := (((src+R_24)^) Shl 16) Or
-                 (((src+G_24)^) Shl 8) Or
+    repeat
+      s_pixel := (((src+R_24)^) shl 16) or
+                 (((src+G_24)^) shl 8) or
                  ((src+B_24)^);
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      dest^ := r Or g Or b;
+      dest^ := r or g or b;
 
       Inc(x, dx);
-      Inc(src, x Shr 16);
-      Inc(src, x Shr 16);
-      Inc(src, x Shr 16);
-      x := x And $FFFF;
+      Inc(src, x shr 16);
+      Inc(src, x shr 16);
+      Inc(src, x shr 16);
+      x := x and $FFFF;
       Inc(dest);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(dest, iface^.d_add);
 
     Inc(y, dy);
-    Inc(source, (y Shr 16)*DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16)*DWord(iface^.s_pitch));
+    y := y and $ffff;
 
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
-
-Procedure ConvertP_Generic16_Generic32_S(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, dest : Pchar8;
-  dx, dy, x, y : DWord;
-
-Begin
+  until iface^.d_height = 0;
+end;
+
+procedure ConvertP_Generic16_Generic32_S(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+  dx, dy, x, y: DWord;
+begin
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   y := 0;
-  Repeat
+  repeat
     count := iface^.d_width;
     x := 0;
-    Repeat
-      s_pixel := (Pshort16(source)+(x Shr 16))^;
+    repeat
+      s_pixel := (PUint16(source)+(x shr 16))^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      Pint32(dest)^ := r Or g Or b;
+      PUint32(dest)^ := r or g or b;
 
       Inc(x, dx);
       Inc(dest, 4);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(dest, iface^.d_add);
 
     Inc(y, dy);
-    Inc(source, (y Shr 16)*DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16)*DWord(iface^.s_pitch));
+    y := y and $ffff;
 
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
-
-Procedure ConvertP_Generic16_Generic24_S(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  d_ptr : Pchar8;
-  count : DWord;
-  source, dest : Pchar8;
-  dx, dy, x, y : DWord;
-
-Begin
-  d_ptr := @s_pixel;
+  until iface^.d_height = 0;
+end;
+
+procedure ConvertP_Generic16_Generic24_S(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  d_ptr: PUint8;
+  count: DWord;
+  source, dest: PUint8;
+  dx, dy, x, y: DWord;
+begin
+  d_ptr := PUint8(@s_pixel) + (R_32 - R_24);
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   y := 0;
-  Repeat
+  repeat
     count := iface^.d_width;
     x := 0;
-    Repeat
-      s_pixel := (Pshort16(source)+(x Shr 16))^;
+    repeat
+      s_pixel := (PUint16(source)+(x shr 16))^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      s_pixel := r Or g Or b;
+      s_pixel := r or g or b;
 
-      (dest + R_24)^ := (d_ptr + R_32)^;
-      (dest + G_24)^ := (d_ptr + G_32)^;
-      (dest + B_24)^ := (d_ptr + B_32)^;
+      (dest + 0)^ := (d_ptr + 0)^;
+      (dest + 1)^ := (d_ptr + 1)^;
+      (dest + 2)^ := (d_ptr + 2)^;
 
       Inc(x, dx);
       Inc(dest, 3);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(dest, iface^.d_add);
 
     Inc(y, dy);
-    Inc(source, (y Shr 16)*DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16)*DWord(iface^.s_pitch));
+    y := y and $ffff;
 
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
-
-Procedure ConvertP_Generic16_Generic16_S(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, dest : Pchar8;
-  dx, dy, x, y : DWord;
-
-Begin
+  until iface^.d_height = 0;
+end;
+
+procedure ConvertP_Generic16_Generic16_S(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+  dx, dy, x, y: DWord;
+begin
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   y := 0;
-  Repeat
+  repeat
     count := iface^.d_width;
     x := 0;
-    Repeat
-      s_pixel := (Pshort16(source)+(x Shr 16))^;
+    repeat
+      s_pixel := (PUint16(source)+(x shr 16))^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      Pshort16(dest)^ := r Or g Or b;
+      PUint16(dest)^ := r or g or b;
 
       Inc(x, dx);
       Inc(dest, 2);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(dest, iface^.d_add);
 
     Inc(y, dy);
-    Inc(source, (y Shr 16)*DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16)*DWord(iface^.s_pitch));
+    y := y and $ffff;
 
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
-
-Procedure ConvertP_Generic16_Generic8_S(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b : int32;
-  count : DWord;
-  source, dest : Pchar8;
-  dx, dy, x, y : DWord;
-
-Begin
+  until iface^.d_height = 0;
+end;
+
+procedure ConvertP_Generic16_Generic8_S(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+  dx, dy, x, y: DWord;
+begin
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   y := 0;
-  Repeat
+  repeat
     count := iface^.d_width;
     x := 0;
-    Repeat
-      s_pixel := (Pshort16(source)+(x Shr 16))^;
+    repeat
+      s_pixel := (PUint16(source)+(x shr 16))^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
 
-      dest^ := r Or g Or b;
+      dest^ := r or g or b;
 
       Inc(x, dx);
       Inc(dest);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(dest, iface^.d_add);
 
     Inc(y, dy);
-    Inc(source, (y Shr 16)*DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16)*DWord(iface^.s_pitch));
+    y := y and $ffff;
 
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
+  until iface^.d_height = 0;
+end;
 
-Procedure ConvertP_Generic8_Generic32_S(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic8_Generic32_S(iface: PHermesConverterInterface); cdecl;
+begin
   {todo}
-End;
-
-Procedure ConvertP_Generic8_Generic24_S(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic8_Generic24_S(iface: PHermesConverterInterface); cdecl;
+begin
   {todo}
-End;
+end;
 
-Procedure ConvertP_Generic8_Generic16_S(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic8_Generic16_S(iface: PHermesConverterInterface); cdecl;
+begin
   {todo}
-End;
-
-Procedure ConvertP_Generic8_Generic8_S(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic8_Generic8_S(iface: PHermesConverterInterface); cdecl;
+begin
   {todo}
-End;
+end;

+ 348 - 364
packages/hermes/src/p_ga.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,596 +34,568 @@
    Generic format conversion routines for the HERMES library
    Copyright (c) 1998 Christian Nentwich ([email protected])
    This source code is licensed under the GNU LGPL
-  
+
    Please refer to the file COPYING.LIB contained in the distribution for
    licensing conditions
 }
 
-Procedure ConvertP_Generic32_A_Generic32_A(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b, a : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+procedure ConvertP_Generic32_A_Generic32_A(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b, a: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := Pint32(source)^;
+    repeat
+      s_pixel := PUint32(source)^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
-      a := ((s_pixel Shr iface^.info.a_right) Shl iface^.info.a_left) And
+      a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
         iface^.mask_a;
 
-      Pint32(dest)^ := r Or g Or b Or a;
+      PUint32(dest)^ := r or g or b or a;
 
       Inc(source, 4);
       Inc(dest, 4);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic32_A_Generic24_A(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b, a : int32;
-  d_ptr : Pchar8;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
-  d_ptr := @s_pixel;
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic32_A_Generic24_A(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b, a: Uint32;
+  d_ptr: PUint8;
+  count: DWord;
+  source, dest: PUint8;
+begin
+  d_ptr := PUint8(@s_pixel) + (R_32 - R_24);
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := Pint32(source)^;
+    repeat
+      s_pixel := PUint32(source)^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
-      a := ((s_pixel Shr iface^.info.a_right) Shl iface^.info.a_left) And
+      a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
         iface^.mask_a;
 
-      s_pixel := r Or g Or b Or a;
+      s_pixel := r or g or b or a;
 
-      (dest+R_24)^ := (d_ptr+R_32)^;
-      (dest+G_24)^ := (d_ptr+G_32)^;
-      (dest+B_24)^ := (d_ptr+B_32)^;
+      (dest+0)^ := (d_ptr+0)^;
+      (dest+1)^ := (d_ptr+1)^;
+      (dest+2)^ := (d_ptr+2)^;
 
       Inc(source, 4);
       Inc(dest, 3);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic32_A_Generic16_A(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b, a : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic32_A_Generic16_A(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b, a: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
-    count := iface^.s_width Shr 1;
-
-    If count <> 0 Then
-      Repeat
-        r := (((Pint32(source)^) Shr iface^.info.r_right) Shl iface^.info.r_left) And
-	      iface^.mask_r;
-        g := (((Pint32(source)^) Shr iface^.info.g_right) Shl iface^.info.g_left) And
-	      iface^.mask_g;
-        b := (((Pint32(source)^) Shr iface^.info.b_right) Shl iface^.info.b_left) And
-	      iface^.mask_b;
-        a := (((Pint32(source)^) Shr iface^.info.a_right) Shl iface^.info.a_left) And
-	      iface^.mask_a;
-
-        s_pixel := (r Or g Or b Or a) And $FFFF;
-      
-        r := ((((Pint32(source)+1)^) Shr iface^.info.r_right) Shl iface^.info.r_left) And
-	      iface^.mask_r;
-        g := ((((Pint32(source)+1)^) Shr iface^.info.g_right) Shl iface^.info.g_left) And
-	      iface^.mask_g;
-        b := ((((Pint32(source)+1)^) Shr iface^.info.b_right) Shl iface^.info.b_left) And
-	      iface^.mask_b;
-        a := ((((Pint32(source)+1)^) Shr iface^.info.a_right) Shl iface^.info.a_left) And
-	      iface^.mask_a;
-
-        s_pixel := s_pixel Or ((r Or g Or b Or a) Shl 16);
-
-        Pint32(dest)^ := s_pixel;
+  repeat
+    count := iface^.s_width shr 1;
+
+    if count <> 0 then
+      repeat
+        r := (((PUint32(source)^) shr iface^.info.r_right) shl iface^.info.r_left) and
+              iface^.mask_r;
+        g := (((PUint32(source)^) shr iface^.info.g_right) shl iface^.info.g_left) and
+              iface^.mask_g;
+        b := (((PUint32(source)^) shr iface^.info.b_right) shl iface^.info.b_left) and
+              iface^.mask_b;
+        a := (((PUint32(source)^) shr iface^.info.a_right) shl iface^.info.a_left) and
+              iface^.mask_a;
+
+        s_pixel := (r or g or b or a) shl DWORD_SMALLINT0_SHL;
+
+        r := ((((PUint32(source)+1)^) shr iface^.info.r_right) shl iface^.info.r_left) and
+              iface^.mask_r;
+        g := ((((PUint32(source)+1)^) shr iface^.info.g_right) shl iface^.info.g_left) and
+              iface^.mask_g;
+        b := ((((PUint32(source)+1)^) shr iface^.info.b_right) shl iface^.info.b_left) and
+              iface^.mask_b;
+        a := ((((PUint32(source)+1)^) shr iface^.info.a_right) shl iface^.info.a_left) and
+              iface^.mask_a;
+
+        s_pixel := s_pixel or ((r or g or b or a) shl DWORD_SMALLINT1_SHL);
+
+        PUint32(dest)^ := s_pixel;
 
         Inc(source, 8);
         Inc(dest, 4);
         Dec(count);
-      Until count = 0;
+      until count = 0;
 
 
     { Trailing pixel }
-    
-    If (iface^.s_width And 1) <> 0 Then
-    Begin
-      r := (((Pint32(source)^) Shr iface^.info.r_right) Shl iface^.info.r_left) And
-	    iface^.mask_r;
-      g := (((Pint32(source)^) Shr iface^.info.g_right) Shl iface^.info.g_left) And
-	    iface^.mask_g;
-      b := (((Pint32(source)^) Shr iface^.info.b_right) Shl iface^.info.b_left) And
-	    iface^.mask_b;
-      a := (((Pint32(source)^) Shr iface^.info.a_right) Shl iface^.info.a_left) And
-	    iface^.mask_a;
-
-      Pshort16(dest)^ := r Or g Or b Or a;
+
+    if (iface^.s_width and 1) <> 0 then
+    begin
+      r := (((PUint32(source)^) shr iface^.info.r_right) shl iface^.info.r_left) and
+            iface^.mask_r;
+      g := (((PUint32(source)^) shr iface^.info.g_right) shl iface^.info.g_left) and
+            iface^.mask_g;
+      b := (((PUint32(source)^) shr iface^.info.b_right) shl iface^.info.b_left) and
+            iface^.mask_b;
+      a := (((PUint32(source)^) shr iface^.info.a_right) shl iface^.info.a_left) and
+            iface^.mask_a;
+
+      PUint16(dest)^ := r or g or b or a;
       Inc(dest, 2);
       Inc(source, 4);
-    End;
+    end;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic32_A_Generic8_A(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b, a : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic32_A_Generic8_A(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b, a: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := Pint32(source)^;
+    repeat
+      s_pixel := PUint32(source)^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
-      a := ((s_pixel Shr iface^.info.a_right) Shl iface^.info.a_left) And
+      a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
         iface^.mask_a;
 
-      dest^ := r Or g Or b Or a;
+      dest^ := r or g or b or a;
 
       Inc(source, 4);
       Inc(dest);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic24_A_Generic32_A(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b, a : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic24_A_Generic32_A(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b, a: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := ((Pint32(source+R_24)^) Shl 16) Or
-                 ((Pint32(source+G_24)^) Shl 8) Or
-                 (PInt32(source+B_24)^);
+    repeat
+      s_pixel := ((PUint32(source+R_24)^) shl 16) or
+                 ((PUint32(source+G_24)^) shl 8) or
+                 (PUint32(source+B_24)^);
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
-      a := ((s_pixel Shr iface^.info.a_right) Shl iface^.info.a_left) And
+      a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
         iface^.mask_a;
 
-      Pint32(dest)^ := r Or g Or b Or a;
+      PUint32(dest)^ := r or g or b or a;
 
       Inc(source, 3);
       Inc(dest, 4);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic24_A_Generic24_A(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b, a : int32;
-  d_ptr : Pchar8;
-  count : DWord;
-  source, dest : PChar8;
-
-Begin
-  d_ptr := @s_pixel;
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic24_A_Generic24_A(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b, a: Uint32;
+  d_ptr: PUint8;
+  count: DWord;
+  source, dest: PUint8;
+begin
+  d_ptr := PUint8(@s_pixel) + (R_32 - R_24);
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := ((Pint32(source+R_24)^) Shl 16) Or
-                 ((Pint32(source+G_24)^) Shl 8) Or
-                 (PInt32(source+B_24)^);
-    
-      r := ((s_pixel Shl iface^.info.r_left) Shr iface^.info.r_right) And
+    repeat
+      s_pixel := ((PUint32(source+R_24)^) shl 16) or
+                 ((PUint32(source+G_24)^) shl 8) or
+                 (PUint32(source+B_24)^);
+
+      r := ((s_pixel shl iface^.info.r_left) shr iface^.info.r_right) and
         iface^.mask_r;
-      g := ((s_pixel Shl iface^.info.g_left) Shr iface^.info.g_right) And
+      g := ((s_pixel shl iface^.info.g_left) shr iface^.info.g_right) and
         iface^.mask_g;
-      b := ((s_pixel Shl iface^.info.b_left) Shr iface^.info.b_right) And
+      b := ((s_pixel shl iface^.info.b_left) shr iface^.info.b_right) and
         iface^.mask_b;
-      a := ((s_pixel Shl iface^.info.a_left) Shr iface^.info.a_right) And
+      a := ((s_pixel shl iface^.info.a_left) shr iface^.info.a_right) and
         iface^.mask_a;
 
-      s_pixel := r Or g Or b Or a;
+      s_pixel := r or g or b or a;
+
+      (dest + 0)^ := (d_ptr + 0)^;
+      (dest + 1)^ := (d_ptr + 1)^;
+      (dest + 2)^ := (d_ptr + 2)^;
 
-      (dest + R_24)^ := (d_ptr + R_32)^;
-      (dest + G_24)^ := (d_ptr + G_32)^;
-      (dest + B_24)^ := (d_ptr + B_32)^;
-    
       Inc(source, 3);
       Inc(dest, 3);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic24_A_Generic16_A(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b, a : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic24_A_Generic16_A(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b, a: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := ((Pint32(source+R_24)^) Shl 16) Or
-                 ((Pint32(source+G_24)^) Shl 8) Or
-                 (PInt32(source+B_24)^);
-    
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+    repeat
+      s_pixel := ((PUint32(source+R_24)^) shl 16) or
+                 ((PUint32(source+G_24)^) shl 8) or
+                 (PUint32(source+B_24)^);
+
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
-      a := ((s_pixel Shr iface^.info.a_right) Shl iface^.info.a_left) And
+      a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
         iface^.mask_a;
 
-      Pshort16(dest)^ := r Or g Or b Or a;
+      PUint16(dest)^ := r or g or b or a;
 
       Inc(source, 3);
       Inc(dest, 2);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic24_A_Generic8_A(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b, a : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic24_A_Generic8_A(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b, a: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := ((Pint32(source+R_24)^) Shl 16) Or
-                 ((Pint32(source+G_24)^) Shl 8) Or
-                 (PInt32(source+B_24)^);
-    
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+    repeat
+      s_pixel := ((PUint32(source+R_24)^) shl 16) or
+                 ((PUint32(source+G_24)^) shl 8) or
+                 (PUint32(source+B_24)^);
+
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
-      a := ((s_pixel Shr iface^.info.a_right) Shl iface^.info.a_left) And
+      a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
         iface^.mask_a;
-    
-      dest^ := r Or g Or b Or a;
-    
+
+      dest^ := r or g or b or a;
+
       Inc(source, 3);
       Inc(dest);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic16_A_Generic32_A(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b, a : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic16_A_Generic32_A(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b, a: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := Pshort16(source)^;
+    repeat
+      s_pixel := PUint16(source)^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
-      a := ((s_pixel Shr iface^.info.a_right) Shl iface^.info.a_left) And
+      a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
         iface^.mask_a;
 
-      Pint32(dest)^ := r Or g Or b Or a;
+      PUint32(dest)^ := r or g or b or a;
 
       Inc(source, 2);
       Inc(dest, 4);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic16_A_Generic24_A(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b, a : int32;
-  d_ptr : Pchar8;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
-  d_ptr := @s_pixel;
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic16_A_Generic24_A(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b, a: Uint32;
+  d_ptr: PUint8;
+  count: DWord;
+  source, dest: PUint8;
+begin
+  d_ptr := PUint8(@s_pixel) + (R_32 - R_24);
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := Pshort16(source)^;
+    repeat
+      s_pixel := PUint16(source)^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
-      a := ((s_pixel Shr iface^.info.a_right) Shl iface^.info.a_left) And
+      a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
         iface^.mask_a;
-    
-      s_pixel := r Or g Or b Or a;
 
-      (dest + R_24)^ := (d_ptr + R_32)^;
-      (dest + G_24)^ := (d_ptr + G_32)^;
-      (dest + B_24)^ := (d_ptr + B_32)^;
-    
+      s_pixel := r or g or b or a;
+
+      (dest + 0)^ := (d_ptr + 0)^;
+      (dest + 1)^ := (d_ptr + 1)^;
+      (dest + 2)^ := (d_ptr + 2)^;
+
       Inc(source, 2);
       Inc(dest, 3);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic16_A_Generic16_A(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b, a : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic16_A_Generic16_A(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b, a: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := Pshort16(source)^;
+    repeat
+      s_pixel := PUint16(source)^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
-      a := ((s_pixel Shr iface^.info.a_right) Shl iface^.info.a_left) And
+      a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
         iface^.mask_a;
 
-      Pshort16(dest)^ := r Or g Or b Or a;
+      PUint16(dest)^ := r or g or b or a;
 
       Inc(source, 2);
       Inc(dest, 2);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_Generic16_A_Generic8_A(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b, a : int32;
-  count : DWord;
-  source, dest : Pchar8;
-
-Begin
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_Generic16_A_Generic8_A(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b, a: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels; dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    Repeat
-      s_pixel := Pshort16(source)^;
+    repeat
+      s_pixel := PUint16(source)^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
-      a := ((s_pixel Shr iface^.info.a_right) Shl iface^.info.a_left) And
+      a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
         iface^.mask_a;
 
-      dest^ := r Or g Or b Or a;
+      dest^ := r or g or b or a;
 
       Inc(source, 2);
       Inc(dest);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
+  until iface^.s_height = 0;
+end;
 
 { -------------------------------------------------------------------------
 
                              STRETCH CONVERTERS
-   
-  ------------------------------------------------------------------------- }
-
 
-Procedure ConvertP_Generic32_A_Generic32_A_S(iface : PHermesConverterInterface); CDecl;
+  ------------------------------------------------------------------------- }
 
-Var
-  s_pixel, r, g, b, a : int32;
-  count : DWord;
-  source, dest : Pchar8;
-  dx, dy, x, y : DWord;
 
-Begin
+procedure ConvertP_Generic32_A_Generic32_A_S(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b, a: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+  dx, dy, x, y: DWord;
+begin
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   y := 0;
-  Repeat
+  repeat
     count := iface^.d_width;
     x := 0;
-    Repeat
-      s_pixel := (Pint32(source)+(x Shr 16))^;
+    repeat
+      s_pixel := (PUint32(source)+(x shr 16))^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
-      a := ((s_pixel Shr iface^.info.a_right) Shl iface^.info.a_left) And
+      a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
         iface^.mask_a;
-    
-      Pint32(dest)^ := r Or g Or b Or a;
-    
+
+      PUint32(dest)^ := r or g or b or a;
+
       Inc(x, dx);
       Inc(dest, 4);
       Dec(count);
-    Until count = 0;
-    
+    until count = 0;
+
     Inc(dest, iface^.d_add);
-    
+
     Inc(y, dy);
-    Inc(source, (y Shr 16)*DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16)*DWord(iface^.s_pitch));
+    y := y and $ffff;
 
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
-
-Procedure ConvertP_Generic32_A_Generic16_A_S(iface : PHermesConverterInterface); CDecl;
-
-Var
-  s_pixel, r, g, b, a : int32;
-  count : DWord;
-  source, dest : Pchar8;
-  dx, dy, x, y : DWord;
-
-Begin
+  until iface^.d_height = 0;
+end;
+
+procedure ConvertP_Generic32_A_Generic16_A_S(iface: PHermesConverterInterface); cdecl;
+var
+  s_pixel, r, g, b, a: Uint32;
+  count: DWord;
+  source, dest: PUint8;
+  dx, dy, x, y: DWord;
+begin
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   y := 0;
-  Repeat
+  repeat
     count := iface^.d_width;
     x := 0;
-    Repeat
-      s_pixel := (Pint32(source)+(x Shr 16))^;
+    repeat
+      s_pixel := (PUint32(source)+(x shr 16))^;
 
-      r := ((s_pixel Shr iface^.info.r_right) Shl iface^.info.r_left) And
+      r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
         iface^.mask_r;
-      g := ((s_pixel Shr iface^.info.g_right) Shl iface^.info.g_left) And
+      g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
         iface^.mask_g;
-      b := ((s_pixel Shr iface^.info.b_right) Shl iface^.info.b_left) And
+      b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
         iface^.mask_b;
-      a := ((s_pixel Shr iface^.info.a_right) Shl iface^.info.a_left) And
+      a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
         iface^.mask_a;
-    
-      Pshort16(dest)^ := r Or g Or b Or a;
-    
+
+      PUint16(dest)^ := r or g or b or a;
+
       Inc(x, dx);
       Inc(dest, 2);
       Dec(count);
-    Until count = 0;
-    
+    until count = 0;
+
     Inc(dest, iface^.d_add);
-    
+
     Inc(y, dy);
-    Inc(source, (y Shr 16)*DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16)*DWord(iface^.s_pitch));
+    y := y and $ffff;
 
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
+  until iface^.d_height = 0;
+end;

+ 57 - 59
packages/hermes/src/p_gac.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,98 +34,84 @@
    Generic format conversion routines for the HERMES library
    Copyright (c) 1998 Christian Nentwich ([email protected])
    This source code is licensed under the GNU LGPL
-  
+
    Please refer to the file COPYING.LIB contained in the distribution for
    licensing conditions
 }
 
-Procedure ConvertP_Generic32_A_Generic32_C(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic32_A_Generic32_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic32_A_Generic24_C(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic32_A_Generic24_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic32_A_Generic16_C(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic32_A_Generic16_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic32_A_Generic8_C(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic32_A_Generic8_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic24_A_Generic32_C(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic24_A_Generic32_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic24_A_Generic24_C(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic24_A_Generic24_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic24_A_Generic16_C(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic24_A_Generic16_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic24_A_Generic8_C(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic24_A_Generic8_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic16_A_Generic32_C(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic16_A_Generic32_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic16_A_Generic24_C(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic16_A_Generic24_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic16_A_Generic16_C(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic16_A_Generic16_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic16_A_Generic8_C(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic16_A_Generic8_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
 { -------------------------------------------------------------------------
 
                              STRETCH CONVERTERS
-   
-  ------------------------------------------------------------------------- }
 
+  ------------------------------------------------------------------------- }
 
-Procedure ConvertP_Generic32_A_Generic32_C_S(iface : PHermesConverterInterface); CDecl;
 
-Begin
+procedure ConvertP_Generic32_A_Generic32_C_S(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic32_A_Generic16_C_S(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic32_A_Generic16_C_S(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;

+ 57 - 59
packages/hermes/src/p_gca.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,97 +34,83 @@
    Generic format conversion routines for the HERMES library
    Copyright (c) 1998 Christian Nentwich ([email protected])
    This source code is licensed under the GNU LGPL
-  
+
    Please refer to the file COPYING.LIB contained in the distribution for
    licensing conditions
 }
 
-Procedure ConvertP_Generic32_C_Generic32_A(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic32_C_Generic32_A(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic32_C_Generic24_A(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic32_C_Generic24_A(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic32_C_Generic16_A(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic32_C_Generic16_A(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic32_C_Generic8_A(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic32_C_Generic8_A(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic24_C_Generic32_A(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic24_C_Generic32_A(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic24_C_Generic24_A(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic24_C_Generic24_A(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic24_C_Generic16_A(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic24_C_Generic16_A(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic24_C_Generic8_A(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic24_C_Generic8_A(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic16_C_Generic32_A(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic16_C_Generic32_A(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic16_C_Generic24_A(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic16_C_Generic24_A(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic16_C_Generic16_A(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic16_C_Generic16_A(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic16_C_Generic8_A(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic16_C_Generic8_A(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
 { -------------------------------------------------------------------------
 
                              STRETCH CONVERTERS
-   
-  ------------------------------------------------------------------------- }
 
-Procedure ConvertP_Generic32_C_Generic32_A_S(iface : PHermesConverterInterface); CDecl;
+  ------------------------------------------------------------------------- }
 
-Begin
+procedure ConvertP_Generic32_C_Generic32_A_S(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic32_C_Generic16_A_S(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic32_C_Generic16_A_S(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;

+ 57 - 59
packages/hermes/src/p_gcc.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,98 +34,84 @@
    Generic format conversion routines for the HERMES library
    Copyright (c) 1998 Christian Nentwich ([email protected])
    This source code is licensed under the GNU LGPL
-  
+
    Please refer to the file COPYING.LIB contained in the distribution for
    licensing conditions
 }
 
-Procedure ConvertP_Generic32_C_Generic32_C(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic32_C_Generic32_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic32_C_Generic24_C(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic32_C_Generic24_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic32_C_Generic16_C(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic32_C_Generic16_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic32_C_Generic8_C(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic32_C_Generic8_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic24_C_Generic32_C(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic24_C_Generic32_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic24_C_Generic24_C(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic24_C_Generic24_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic24_C_Generic16_C(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic24_C_Generic16_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic24_C_Generic8_C(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic24_C_Generic8_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic16_C_Generic32_C(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic16_C_Generic32_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic16_C_Generic24_C(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic16_C_Generic24_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic16_C_Generic16_C(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic16_C_Generic16_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
-Procedure ConvertP_Generic16_C_Generic8_C(iface : PHermesConverterInterface); CDecl;
-
-Begin
+procedure ConvertP_Generic16_C_Generic8_C(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;
 
 { -------------------------------------------------------------------------
 
                              STRETCH CONVERTERS
-   
-  ------------------------------------------------------------------------- }
 
+  ------------------------------------------------------------------------- }
 
-Procedure ConvertP_Generic32_C_Generic32_C_S(iface : PHermesConverterInterface); CDecl;
 
-Begin
+procedure ConvertP_Generic32_C_Generic32_C_S(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
-
-Procedure ConvertP_Generic32_C_Generic16_C_S(iface : PHermesConverterInterface); CDecl;
+end;
 
-Begin
+procedure ConvertP_Generic32_C_Generic16_C_S(iface: PHermesConverterInterface); cdecl;
+begin
   {NOT YET IMPLEMENTED!}
-End;
+end;

+ 240 - 219
packages/hermes/src/p_i8.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -34,162 +46,166 @@
 
   ------------------------------------------------------------------------- }
 
-Procedure ConvertP_index8_32(iface : PHermesConverterInterface); CDecl;
-
-Var
-  i : Integer;
-  s_pixel : char8;
-  d_pixel : int32;
-  source, dest : Pchar8;
-
-Begin
+procedure ConvertP_index8_32(iface: PHermesConverterInterface); cdecl;
+var
+  i: Integer;
+  s_pixel: Uint8;
+  d_pixel: Uint32;
+  source, dest: PUint8;
+begin
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  Repeat
-    For i := 0 To iface^.s_width - 1 Do
-    Begin
+  repeat
+    for i := 0 to iface^.s_width - 1 do
+    begin
       s_pixel := source^;
       d_pixel := iface^.lookup[s_pixel];
-      Pint32(dest)^ := d_pixel;
+      PUint32(dest)^ := d_pixel;
       Inc(source);
       Inc(dest, 4);
-    End;
+    end;
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_index8_24(iface : PHermesConverterInterface); CDecl;
-
-Var
-  count : Integer;
-  s_pixel, s_pixel2, d_pixel : int32;
-  d_ptr, source, dest : Pchar8;
-
-Begin
-  d_ptr := @d_pixel;
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_index8_24(iface: PHermesConverterInterface); cdecl;
+var
+  count: Integer;
+  s_pixel, s_pixel2, d_pixel: Uint32;
+  d_ptr, source, dest: PUint8;
+begin
+  d_ptr := PUint8(@d_pixel) + (R_32 - R_24);
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  Repeat
-    count := iface^.d_width Shr 2;
-    While count <> 0 Do
-    Begin
+  repeat
+    count := iface^.d_width shr 2;
+    while count <> 0 do
+    begin
       Dec(count);
 
       s_pixel := iface^.lookup[source^]; Inc(source);
       s_pixel2 := iface^.lookup[source^]; Inc(source);
 
-      s_pixel := (s_pixel And $ffffff) Or (s_pixel2 Shl 24);
-      Pint32(dest)^ := s_pixel;
+      {$IFDEF FPC_LITTLE_ENDIAN}
+      s_pixel := s_pixel or (s_pixel2 shl 24);
+      {$ELSE FPC_LITTLE_ENDIAN}
+      s_pixel := (s_pixel shl 8) or (s_pixel2 shr 16);
+      {$ENDIF FPC_LITTLE_ENDIAN}
+      PUint32(dest)^ := s_pixel;
 
       s_pixel := iface^.lookup[source^]; Inc(source);
-      s_pixel2 := ((s_pixel2 Shr 8) And $ffff) Or (s_pixel Shl 16);
-      Pint32(dest + 4)^ := s_pixel2;
+      {$IFDEF FPC_LITTLE_ENDIAN}
+      s_pixel2 := (s_pixel2 shr 8) or (s_pixel shl 16);
+      {$ELSE FPC_LITTLE_ENDIAN}
+      s_pixel2 := (s_pixel2 shl 16) or (s_pixel shr 8);
+      {$ENDIF FPC_LITTLE_ENDIAN}
+      PUint32(dest + 4)^ := s_pixel2;
 
       s_pixel2 := iface^.lookup[source^]; Inc(source);
-      s_pixel := ((s_pixel Shr 16) And $ff) Or (s_pixel2 Shl 8);
-      Pint32(dest + 8)^ := s_pixel;
+      {$IFDEF FPC_LITTLE_ENDIAN}
+      s_pixel := (s_pixel shr 16) or (s_pixel2 shl 8);
+      {$ELSE FPC_LITTLE_ENDIAN}
+      s_pixel := (s_pixel shl 24) or s_pixel2;
+      {$ENDIF FPC_LITTLE_ENDIAN}
+      PUint32(dest + 8)^ := s_pixel;
 
       Inc(dest, 12);
-    End;
+    end;
 
-    count := iface^.d_width And $3;
-    While count <> 0 Do
-    Begin
+    count := iface^.d_width and $3;
+    while count <> 0 do
+    begin
       Dec(count);
       d_pixel := iface^.lookup[source^]; Inc(source);
 
-      (dest + R_24)^ := (d_ptr + R_32)^;
-      (dest + G_24)^ := (d_ptr + G_32)^;
-      (dest + B_24)^ := (d_ptr + B_32)^;
+      (dest + 0)^ := (d_ptr + 0)^;
+      (dest + 1)^ := (d_ptr + 1)^;
+      (dest + 2)^ := (d_ptr + 2)^;
 
       Inc(dest, 3);
-    End;
+    end;
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
-
-Procedure ConvertP_index8_16(iface : PHermesConverterInterface); CDecl;
-
-Var
-  source, dest : Pchar8;
-  count, c : DWord;
-
-Begin
+  until iface^.d_height = 0;
+end;
+
+procedure ConvertP_index8_16(iface: PHermesConverterInterface); cdecl;
+var
+  source, dest: PUint8;
+  count, c: DWord;
+begin
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    If (PtrUInt(dest) And $3) <> 0 Then
-    Begin
-      Pshort16(dest)^ := iface^.lookup[source^]; Inc(source);
+    if (PtrUInt(dest) and $3) <> 0 then
+    begin
+      PUint16(dest)^ := iface^.lookup[source^]; Inc(source);
       Inc(dest, 2);
       Dec(count);
-    End;
-    c := count Shr 1;
-    If c <> 0 Then
-      Repeat
-        Pint32(dest)^ := iface^.lookup[source^] Or
-                        (iface^.lookup[(source + 1)^] Shl 16);
+    end;
+    c := count shr 1;
+    if c <> 0 then
+      repeat
+        PUint32(dest)^ := (iface^.lookup[source^] shl DWORD_SMALLINT0_SHL) or
+                        (iface^.lookup[(source + 1)^] shl DWORD_SMALLINT1_SHL);
         Inc(dest, 4);
         Inc(source, 2);
         Dec(c);
-      Until c = 0;
-    If (count And 1) <> 0 Then
-    Begin
-      Pshort16(dest)^ := iface^.lookup[source^];
+      until c = 0;
+    if (count and 1) <> 0 then
+    begin
+      PUint16(dest)^ := iface^.lookup[source^];
       Inc(source);
       Inc(dest, 2);
-    End;
+    end;
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
-
-Procedure ConvertP_index8_8(iface : PHermesConverterInterface); CDecl;
-
-Var
-  source, dest : Pchar8;
-  count, c : DWord;
-
-Begin
+  until iface^.s_height = 0;
+end;
+
+procedure ConvertP_index8_8(iface: PHermesConverterInterface); cdecl;
+var
+  source, dest: PUint8;
+  count, c: DWord;
+begin
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  Repeat
+  repeat
     count := iface^.s_width;
-    If (PtrUInt(dest) And $3) <> 0 Then
-    Begin
+    if (PtrUInt(dest) and $3) <> 0 then
+    begin
       dest^ := iface^.lookup[source^]; Inc(source);
       Inc(dest);
       Dec(count);
-    End;
-    c := count Shr 2;
-    If c <> 0 Then
-      Repeat
-        Pint32(dest)^ := iface^.lookup[source^] Or
-                        (iface^.lookup[(source + 1)^] Shl 8) Or
-                        (iface^.lookup[(source + 2)^] Shl 16) Or
-                        (iface^.lookup[(source + 3)^] Shl 24);
+    end;
+    c := count shr 2;
+    if c <> 0 then
+      repeat
+        PUint32(dest)^ := (iface^.lookup[source^] shl DWORD_BYTE0_SHL) or
+                        (iface^.lookup[(source + 1)^] shl DWORD_BYTE1_SHL) or
+                        (iface^.lookup[(source + 2)^] shl DWORD_BYTE2_SHL) or
+                        (iface^.lookup[(source + 3)^] shl DWORD_BYTE3_SHL);
         Inc(dest, 4);
         Inc(source, 4);
         Dec(c);
-      Until c = 0;
-    count := count And $03;
-    While count > 0 Do
-    Begin
+      until c = 0;
+    count := count and $03;
+    while count > 0 do
+    begin
       dest^ := iface^.lookup[source^]; Inc(source);
       Inc(dest);
       Dec(count);
-    End;
+    end;
     Inc(source, iface^.s_add);
     Inc(dest, iface^.d_add);
     Dec(iface^.s_height);
-  Until iface^.s_height = 0;
-End;
+  until iface^.s_height = 0;
+end;
 
 { -------------------------------------------------------------------------
 
@@ -197,28 +213,26 @@ End;
 
   ------------------------------------------------------------------------- }
 
-Procedure ConvertP_index8_32_S(iface : PHermesConverterInterface); CDecl;
-
-Var
-  x, y, count : DWord;
-  dx, dy : DWord;
-  source : Pchar8;
-
-Begin
+procedure ConvertP_index8_32_S(iface: PHermesConverterInterface); cdecl;
+var
+  x, y, count: DWord;
+  dx, dy: DWord;
+  source: PUint8;
+begin
   y := 0;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   source := iface^.s_pixels;
-  Repeat
+  repeat
     count := iface^.d_width;
     x := 0;
 
-    Repeat
-      Pint32(iface^.d_pixels)^ := iface^.lookup[(source + (x Shr 16))^];
+    repeat
+      PUint32(iface^.d_pixels)^ := iface^.lookup[(source + (x shr 16))^];
       Inc(x, dx);
       Inc(iface^.d_pixels, 4);
       Dec(count);
-    Until count = 0;
+    until count = 0;
 
     { Go to next destination row }
     Inc(iface^.d_pixels, iface^.d_add);
@@ -226,62 +240,73 @@ Begin
     { Calculate amount of rows to move in source surface }
     Inc(y, dy);
 
-    Inc(source, (y Shr 16) * DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16) * DWord(iface^.s_pitch));
+    y := y and $ffff;
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
-
-{by me!}
-Procedure ConvertP_index8_24_S(iface : PHermesConverterInterface); CDecl;
-
-Var
-  x, y, count : DWord;
-  dx, dy : DWord;
-  source, dest : Pchar8;
-  s_pixel, s_pixel2, d_pixel : int32;
-
-Begin
+  until iface^.d_height = 0;
+end;
+
+procedure ConvertP_index8_24_S(iface: PHermesConverterInterface); cdecl;
+var
+  x, y, count: DWord;
+  dx, dy: DWord;
+  d_ptr, source, dest: PUint8;
+  s_pixel, s_pixel2, d_pixel: Uint32;
+begin
+  d_ptr := PUint8(@d_pixel) + (R_32 - R_24);
   y := 0;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  Repeat
+  repeat
     x := 0;
-    count := iface^.d_width Shr 2;
-    While count <> 0 Do
-    Begin
+    count := iface^.d_width shr 2;
+    while count <> 0 do
+    begin
       Dec(count);
 
-      s_pixel := iface^.lookup[(source + (x Shr 16))^]; Inc(x, dx);
-      s_pixel2 := iface^.lookup[(source + (x Shr 16))^]; Inc(x, dx);
-
-      s_pixel := (s_pixel And $ffffff) Or (s_pixel2 Shl 24);
-      Pint32(dest)^ := s_pixel;
-
-      s_pixel := iface^.lookup[(source + (x Shr 16))^]; Inc(x, dx);
-      s_pixel2 := ((s_pixel2 Shr 8) And $ffff) Or (s_pixel Shl 16);
-      Pint32(dest + 4)^ := s_pixel2;
-
-      s_pixel2 := iface^.lookup[(source + (x Shr 16))^]; Inc(x, dx);
-      s_pixel := ((s_pixel Shr 16) And $ff) Or (s_pixel2 Shl 8);
-      Pint32(dest + 8)^ := s_pixel;
+      s_pixel := iface^.lookup[(source + (x shr 16))^]; Inc(x, dx);
+      s_pixel2 := iface^.lookup[(source + (x shr 16))^]; Inc(x, dx);
+
+      {$IFDEF FPC_LITTLE_ENDIAN}
+      s_pixel := s_pixel or (s_pixel2 shl 24);
+      {$ELSE FPC_LITTLE_ENDIAN}
+      s_pixel := (s_pixel shl 8) or (s_pixel2 shr 16);
+      {$ENDIF FPC_LITTLE_ENDIAN}
+      PUint32(dest)^ := s_pixel;
+
+      s_pixel := iface^.lookup[(source + (x shr 16))^]; Inc(x, dx);
+      {$IFDEF FPC_LITTLE_ENDIAN}
+      s_pixel2 := (s_pixel2 shr 8) or (s_pixel shl 16);
+      {$ELSE FPC_LITTLE_ENDIAN}
+      s_pixel2 := (s_pixel2 shl 16) or (s_pixel shr 8);
+      {$ENDIF FPC_LITTLE_ENDIAN}
+      PUint32(dest + 4)^ := s_pixel2;
+
+      s_pixel2 := iface^.lookup[(source + (x shr 16))^]; Inc(x, dx);
+      {$IFDEF FPC_LITTLE_ENDIAN}
+      s_pixel := (s_pixel shr 16) or (s_pixel2 shl 8);
+      {$ELSE FPC_LITTLE_ENDIAN}
+      s_pixel := (s_pixel shl 24) or s_pixel2;
+      {$ENDIF FPC_LITTLE_ENDIAN}
+      PUint32(dest + 8)^ := s_pixel;
 
       Inc(dest, 12);
-    End;
+    end;
 
-    count := iface^.d_width And $3;
-    While count <> 0 Do
-    Begin
+    count := iface^.d_width and $3;
+    while count <> 0 do
+    begin
       Dec(count);
-      d_pixel := iface^.lookup[(source + (x Shr 16))^]; Inc(x, dx);
+      d_pixel := iface^.lookup[(source + (x shr 16))^]; Inc(x, dx);
 
-      Pshort16(dest)^ := d_pixel;
-      Pchar8(dest + 2)^ := d_pixel Shr 16;
+      (dest + 0)^ := (d_ptr + 0)^;
+      (dest + 1)^ := (d_ptr + 1)^;
+      (dest + 2)^ := (d_ptr + 2)^;
 
       Inc(dest, 3);
-    End;
+    end;
 
     { Go to next destination row }
 {    Inc(iface^.d_pixels, iface^.d_add);}
@@ -290,47 +315,45 @@ Begin
     { Calculate amount of rows to move in source surface }
     Inc(y, dy);
 
-    Inc(source, (y Shr 16) * DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16) * DWord(iface^.s_pitch));
+    y := y and $ffff;
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
+  until iface^.d_height = 0;
+end;
 
 { Quick hack of a index 8 to 16 stretch converter }
-Procedure ConvertP_index8_16_S(iface : PHermesConverterInterface); CDecl;
-
-Var
-  x, y, count : DWord;
-  dx, dy : DWord;
-  source, dest : Pchar8;
-
-Begin
+procedure ConvertP_index8_16_S(iface: PHermesConverterInterface); cdecl;
+var
+  x, y, count: DWord;
+  dx, dy: DWord;
+  source, dest: PUint8;
+begin
   y := 0;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  Repeat
-    { Do a two pixel at a time loop }
+  repeat
+    { do a two pixel at a time loop }
 
-    count := iface^.d_width Shr 1;
+    count := iface^.d_width shr 1;
     x := 0;
 
-    While count <> 0 Do
-    Begin
+    while count <> 0 do
+    begin
       Dec(count);
-      Pint32(dest)^ := iface^.lookup[(source + (x Shr 16))^] Or
-                      (iface^.lookup[(source + ((x + dx) Shr 16))^] Shl 16);
+      PUint32(dest)^ := (iface^.lookup[(source + (x shr 16))^] shl DWORD_SMALLINT0_SHL) or
+                      (iface^.lookup[(source + ((x + dx) shr 16))^] shl DWORD_SMALLINT1_SHL);
       Inc(x, dx); Inc(x, dx);
       Inc(dest, 4);
-    End;
+    end;
 
     { Clean up remaining pixel if odd width }
-    If (iface^.d_width And 1) <> 0 Then
-    Begin
-      Pshort16(dest)^ := iface^.lookup[(source + (x Shr 16))^];
+    if (iface^.d_width and 1) <> 0 then
+    begin
+      PUint16(dest)^ := iface^.lookup[(source + (x shr 16))^];
       Inc(dest, 2);
-    End;
+    end;
 
     { Go to next destination row }
     Inc(dest, iface^.d_add);
@@ -338,59 +361,57 @@ Begin
     { Calculate amount of rows to move in source surface }
     Inc(y, dy);
 
-    Inc(source, (y Shr 16) * DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16) * DWord(iface^.s_pitch));
+    y := y and $ffff;
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
-
-Procedure ConvertP_index8_8_S(iface : PHermesConverterInterface); CDecl;
-
-Var
-  x, y, count, c : DWord;
-  dx, dy : DWord;
-  source, dest : Pchar8;
-
-Begin
+  until iface^.d_height = 0;
+end;
+
+procedure ConvertP_index8_8_S(iface: PHermesConverterInterface); cdecl;
+var
+  x, y, count, c: DWord;
+  dx, dy: DWord;
+  source, dest: PUint8;
+begin
   y := 0;
-  dy := (iface^.s_height Shl 16) Div iface^.d_height;
-  dx := (iface^.s_width Shl 16) Div iface^.d_width;
+  dy := (iface^.s_height shl 16) div iface^.d_height;
+  dx := (iface^.s_width shl 16) div iface^.d_width;
   source := iface^.s_pixels;
   dest := iface^.d_pixels;
-  Repeat
-    { Do a four pixel at a time loop }
+  repeat
+    { do a four pixel at a time loop }
 
     count := iface^.d_width;
     x := 0;
 
-    While ((PtrUInt(dest) And 3) <> 0) And (count > 0) Do
-    Begin
+    while ((PtrUInt(dest) and 3) <> 0) and (count > 0) do
+    begin
       Dec(count);
-      dest^ := iface^.lookup[(source + (x Shr 16))^];
+      dest^ := iface^.lookup[(source + (x shr 16))^];
       Inc(x, dx);
       Inc(dest);
-    End;
+    end;
 
-    c := count Shr 2;
-    count := count And 3;
+    c := count shr 2;
+    count := count and 3;
 
-    While c <> 0 Do
-    Begin
+    while c <> 0 do
+    begin
       Dec(c);
-      Pint32(dest)^ := iface^.lookup[(source + (x Shr 16))^] Or
-                      (iface^.lookup[(source + ((x + dx) Shr 16))^] Shl 8) Or
-                      (iface^.lookup[(source + ((x + (dx Shl 1)) Shr 16))^] Shl 16) Or
-                      (iface^.lookup[(source + ((x + dx + (dx Shl 1)) Shr 16))^] Shl 24);
-      Inc(x, dx Shl 2);
+      PUint32(dest)^ := (iface^.lookup[(source + (x shr 16))^] shl DWORD_BYTE0_SHL) or
+                      (iface^.lookup[(source + ((x + dx) shr 16))^] shl DWORD_BYTE1_SHL) or
+                      (iface^.lookup[(source + ((x + (dx shl 1)) shr 16))^] shl DWORD_BYTE2_SHL) or
+                      (iface^.lookup[(source + ((x + dx + (dx shl 1)) shr 16))^] shl DWORD_BYTE3_SHL);
+      Inc(x, dx shl 2);
       Inc(dest, 4);
-    End;
+    end;
 
-    While count > 0 Do
-    Begin
+    while count > 0 do
+    begin
       Dec(count);
-      dest^ := iface^.lookup[(source + (x Shr 16))^];
+      dest^ := iface^.lookup[(source + (x shr 16))^];
       Inc(dest);
-    End;
+    end;
 
     { Go to next destination row }
     Inc(dest, iface^.d_add);
@@ -398,8 +419,8 @@ Begin
     { Calculate amount of rows to move in source surface }
     Inc(y, dy);
 
-    Inc(source, (y Shr 16) * DWord(iface^.s_pitch));
-    y := y And $ffff;
+    Inc(source, (y shr 16) * DWord(iface^.s_pitch));
+    y := y and $ffff;
     Dec(iface^.d_height);
-  Until iface^.d_height = 0;
-End;
+  until iface^.d_height = 0;
+end;

+ 611 - 627
packages/hermes/src/p_muhmu.inc

@@ -6,7 +6,19 @@
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
     License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
+    version 2.1 of the License, or (at your option) any later version
+    with the following modification:
+
+    As a special exception, the copyright holders of this library give you
+    permission to link this library with independent modules to produce an
+    executable, regardless of the license terms of these independent modules,and
+    to copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the terms
+    and conditions of the license of that module. An independent module is a
+    module which is not derived from or based on this library. If you modify
+    this library, you may extend this exception to your version of the library,
+    but you are not obligated to do so. If you do not wish to do so, delete this
+    exception statement from your version.
 
     This library is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,878 +34,850 @@
    muhmuh converters for the HERMES library
    Copyright (c) 1998 Christian Nentwich ([email protected])
    This source code is licensed under the GNU LGPL
- 
+
    Please refer to the file COPYING.LIB contained in the distribution for
    licensing conditions
 }
 
 { TO 32 RGB }
-Procedure ConvertP_muhmu32_32rgb888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  s_pixel : int32;
+procedure ConvertP_muhmu32_32rgb888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  s_pixel: Uint32;
+begin
+  repeat
+    s_pixel := PUint32(source)^;
 
-Begin
-  Repeat
-    s_pixel := Pint32(source)^;
+    PUint32(dest)^ := (s_pixel and $ff) or
+                    ((s_pixel and ($ff shl 10)) shr 2) or
+                    ((s_pixel and ($ff shl 20)) shr 4);
 
-    Pint32(dest)^ := (s_pixel And $ff) Or
-                    ((s_pixel And ($ff Shl 10)) Shr 2) Or
-	            ((s_pixel And ($ff Shl 20)) Shr 4);
-    
     Inc(dest, 4);
     Inc(source, 4);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
 { TO 32 BGR }
-Procedure ConvertP_muhmu32_32bgr888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  s_pixel : int32;
-
-Begin
-  Repeat
-    s_pixel := Pint32(source)^;
+procedure ConvertP_muhmu32_32bgr888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  s_pixel: Uint32;
+begin
+  repeat
+    s_pixel := PUint32(source)^;
 
-    Pint32(dest)^ := ((s_pixel And $ff) Shl 16) Or
-                     ((s_pixel And ($ff Shl 10)) Shr 2) Or
-	             ((s_pixel Shr 20) And $FF);
+    PUint32(dest)^ := ((s_pixel and $ff) shl 16) or
+                     ((s_pixel and ($ff shl 10)) shr 2) or
+                     ((s_pixel shr 20) and $FF);
 
     Inc(dest, 4);
     Inc(source, 4);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
 { TO 32 RGBA }
-Procedure ConvertP_muhmu32_32rgba888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
+procedure ConvertP_muhmu32_32rgba888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  s_pixel: Uint32;
+begin
+  repeat
+    s_pixel := PUint32(source)^;
 
-Var
-  s_pixel : int32;
+    PUint32(dest)^ := (((s_pixel and $ff) or
+                      ((s_pixel and ($ff shl 10)) shr 2) or
+                      ((s_pixel and ($ff shl 20)) shr 4)) shl 8) or $FF;
 
-Begin
-  Repeat
-    s_pixel := Pint32(source)^;
-
-    Pint32(dest)^ := (((s_pixel And $ff) Or
-                      ((s_pixel And ($ff Shl 10)) Shr 2) Or
-	              ((s_pixel And ($ff Shl 20)) Shr 4)) Shl 8) Or $FF;
-    
     Inc(dest, 4);
     Inc(source, 4);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
 { TO 32 BGRA }
-Procedure ConvertP_muhmu32_32bgra888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  s_pixel : int32;
+procedure ConvertP_muhmu32_32bgra888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  s_pixel: Uint32;
+begin
+  repeat
+    s_pixel := PUint32(source)^;
 
-Begin
-  Repeat
-    s_pixel := Pint32(source)^;
-
-    Pint32(dest)^ := (((s_pixel And $ff) Shl 24) Or
-                      ((s_pixel And ($ff Shl 10)) Shl 6) Or
-	              ((s_pixel Shr 12) And $FF00)) Or $FF;
+    PUint32(dest)^ := (((s_pixel and $ff) shl 24) or
+                      ((s_pixel and ($ff shl 10)) shl 6) or
+                      ((s_pixel shr 12) and $FF00)) or $FF;
 
     Inc(dest, 4);
     Inc(source, 4);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
 { TO 24 RGB }
-Procedure ConvertP_muhmu32_24rgb888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  s_pixel : int32;
-  s_point : Pchar8;
-
-Begin
-  s_point := @s_pixel;
-  Repeat
-    s_pixel := Pint32(source)^;
-    s_pixel := (s_pixel And $ff) Or
-               ((s_pixel And ($ff Shl 10)) Shr 2) Or
-	       ((s_pixel And ($ff Shl 20)) Shr 4);
-
-    (dest+R_24)^ := (s_point+R_32)^;
-    (dest+G_24)^ := (s_point+G_32)^;
-    (dest+B_24)^ := (s_point+B_32)^;
+procedure ConvertP_muhmu32_24rgb888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  s_pixel: Uint32;
+  s_point: PUint8;
+begin
+  s_point := PUint8(@s_pixel) + (R_32 - R_24);
+  repeat
+    s_pixel := PUint32(source)^;
+    s_pixel := (s_pixel and $ff) or
+               ((s_pixel and ($ff shl 10)) shr 2) or
+               ((s_pixel and ($ff shl 20)) shr 4);
+
+    (dest+0)^ := (s_point+0)^;
+    (dest+1)^ := (s_point+1)^;
+    (dest+2)^ := (s_point+2)^;
 
     Inc(source, 4);
     Inc(dest, 3);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
 { TO 24 BGR }
-Procedure ConvertP_muhmu32_24bgr888(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  s_pixel : int32;
-  s_point : Pchar8;
-
-Begin
-  s_point := @s_pixel;
-  Repeat
-    s_pixel := Pint32(source)^;
-    s_pixel := (s_pixel And $ff) Or
-               ((s_pixel And ($ff Shl 10)) Shr 2) Or
-	       ((s_pixel And ($ff Shl 20)) Shr 4);
+procedure ConvertP_muhmu32_24bgr888(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  s_pixel: Uint32;
+  s_point: PUint8;
+begin
+  s_point := PUint8(@s_pixel) + (R_32 - R_24);
+  repeat
+    s_pixel := PUint32(source)^;
+    s_pixel := (s_pixel and $ff) or
+               ((s_pixel and ($ff shl 10)) shr 2) or
+               ((s_pixel and ($ff shl 20)) shr 4);
 
     { Note that R and B are swapped }
-    (dest+B_24)^ := (s_point+R_32)^;
-    (dest+G_24)^ := (s_point+G_32)^;
-    (dest+R_24)^ := (s_point+B_32)^;
+    (dest+0)^ := (s_point+2)^;
+    (dest+1)^ := (s_point+1)^;
+    (dest+2)^ := (s_point+0)^;
 
     Inc(source, 4);
     Inc(dest, 3);
     Dec(count);
-  Until count = 0;
-End;
+  until count = 0;
+end;
 
 { TO 16 RGB 565 }
-Procedure ConvertP_muhmu32_16rgb565(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  i : DWord;
-  r, g, b : int32;
-  s_pixel, d_pixelblock : int32;
-  d_pixel : short16;
-
-Begin
-  { If the current pixel isn't dword aligned, try write one pixel first }
-  If (PtrUInt(dest) And $3) <> 0 Then
-  Begin
-    s_pixel := Pint32(source)^;
-  
-    r := (s_pixel Shr 12) And $f800;
-    g := (s_pixel Shr 7) And $7e0;
-    b := (s_pixel Shr 3) And $1f;
-
-    d_pixel := r Or g Or b;
-
-    Pshort16(dest)^ := d_pixel;
+procedure ConvertP_muhmu32_16rgb565(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  i: DWord;
+  r, g, b: Uint32;
+  s_pixel, d_pixelblock: Uint32;
+  d_pixel: Uint16;
+begin
+  { if the current pixel isn't dword aligned, try write one pixel first }
+  if (PtrUInt(dest) and $3) <> 0 then
+  begin
+    s_pixel := PUint32(source)^;
+
+    r := (s_pixel shr 12) and $f800;
+    g := (s_pixel shr 7) and $7e0;
+    b := (s_pixel shr 3) and $1f;
+
+    d_pixel := r or g or b;
+
+    PUint16(dest)^ := d_pixel;
 
     Inc(source, 4);
     Inc(dest, 2);
     Dec(count);
-  End;
+  end;
 
   { Write blocks of two pixels }
-  For i := 1 To count Shr 1 Do
-  Begin
-    s_pixel := Pint32(source)^;
+  for i := 1 to count shr 1 do
+  begin
+    s_pixel := PUint32(source)^;
 
-    d_pixelblock := ((s_pixel Shr 12) And $f800) Or
-                    ((s_pixel Shr 7) And $7e0) Or
-		    ((s_pixel Shr 3) And $1f);
+    d_pixelblock := (((s_pixel shr 12) and $f800) or
+                     ((s_pixel shr 7) and $7e0) or
+                     ((s_pixel shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
 
-    s_pixel := (Pint32(source) + 1)^;
+    s_pixel := (PUint32(source) + 1)^;
 
-    d_pixelblock := d_pixelblock Or
-      ((((s_pixel Shr 12) And $f800) Or
-        ((s_pixel Shr 7) And $7e0) Or
-	((s_pixel Shr 3) And $1f)) Shl 16);
+    d_pixelblock := d_pixelblock or
+      ((((s_pixel shr 12) and $f800) or
+        ((s_pixel shr 7) and $7e0) or
+        ((s_pixel shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
 
-    Pint32(dest)^ := d_pixelblock;
+    PUint32(dest)^ := d_pixelblock;
     Inc(source, 8); Inc(dest, 4);
-  End;
+  end;
 
   { Eventually, write a single odd pixel that might be left }
-  If (count And 1) <> 0 Then
-  Begin
-    s_pixel := Pint32(source)^;
+  if (count and 1) <> 0 then
+  begin
+    s_pixel := PUint32(source)^;
 
-    r := (s_pixel Shr 12) And $f800;
-    g := (s_pixel Shr 7) And $7e0;
-    b := (s_pixel Shr 3) And $1f;
+    r := (s_pixel shr 12) and $f800;
+    g := (s_pixel shr 7) and $7e0;
+    b := (s_pixel shr 3) and $1f;
 
-    d_pixel := r Or g Or b;
+    d_pixel := r or g or b;
 
-    Pshort16(dest)^ := d_pixel;
-  End;
-End;
+    PUint16(dest)^ := d_pixel;
+  end;
+end;
 
 { TO 16 BGR 565 }
-Procedure ConvertP_muhmu32_16bgr565(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  i : DWord;
-  r, g, b : int32;
-  s_pixel, d_pixelblock : int32;
-  d_pixel : short16;
-
-Begin
-  { If the current pixel isn't dword aligned, try write one pixel first }
-  If (PtrUInt(dest) And $3) <> 0 Then
-  Begin
-    s_pixel := Pint32(source)^;
-  
-    r := (s_pixel Shr 23) And $1f;
-    g := (s_pixel Shr 7) And $7e0;
-    b := (s_pixel Shl 8) And $f800;
-
-    d_pixel := r Or g Or b;
-
-    Pshort16(dest)^ := d_pixel;
+procedure ConvertP_muhmu32_16bgr565(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  i: DWord;
+  r, g, b: Uint32;
+  s_pixel, d_pixelblock: Uint32;
+  d_pixel: Uint16;
+begin
+  { if the current pixel isn't dword aligned, try write one pixel first }
+  if (PtrUInt(dest) and $3) <> 0 then
+  begin
+    s_pixel := PUint32(source)^;
+
+    r := (s_pixel shr 23) and $1f;
+    g := (s_pixel shr 7) and $7e0;
+    b := (s_pixel shl 8) and $f800;
+
+    d_pixel := r or g or b;
+
+    PUint16(dest)^ := d_pixel;
 
     Inc(source, 4);
     Inc(dest, 2);
     Dec(count);
-  End;
+  end;
 
   { Write blocks of two pixels }
-  For i := 1 To count Shr 1 Do
-  Begin
-    s_pixel := Pint32(source)^;
+  for i := 1 to count shr 1 do
+  begin
+    s_pixel := PUint32(source)^;
 
-    d_pixelblock := ((s_pixel Shr 23) And $1f) Or
-                    ((s_pixel Shr 7) And $7e0) Or
-		    ((s_pixel Shl 8) And $f800);
+    d_pixelblock := (((s_pixel shr 23) and $1f) or
+                     ((s_pixel shr 7) and $7e0) or
+                     ((s_pixel shl 8) and $f800)) shl DWORD_SMALLINT0_SHL;
 
-    s_pixel := (Pint32(source) + 1)^;
+    s_pixel := (PUint32(source) + 1)^;
 
-    d_pixelblock := d_pixelblock Or
-      ((((s_pixel Shr 23) And $1f) Or
-        ((s_pixel Shr 7) And $7e0) Or
-	((s_pixel Shl 8) And $f800)) Shl 16);
+    d_pixelblock := d_pixelblock or
+      ((((s_pixel shr 23) and $1f) or
+        ((s_pixel shr 7) and $7e0) or
+        ((s_pixel shl 8) and $f800)) shl DWORD_SMALLINT1_SHL);
 
-    Pint32(dest)^ := d_pixelblock;
+    PUint32(dest)^ := d_pixelblock;
     Inc(source, 8); Inc(dest, 4);
-  End;
+  end;
 
   { Eventually, write a single odd pixel that might be left }
-  If (count And 1) <> 0 Then
-  Begin
-    s_pixel := Pint32(source)^;
+  if (count and 1) <> 0 then
+  begin
+    s_pixel := PUint32(source)^;
 
-    r := (s_pixel Shr 23) And $1f;
-    g := (s_pixel Shr 7) And $7e0;
-    b := (s_pixel Shl 8) And $f800;
+    r := (s_pixel shr 23) and $1f;
+    g := (s_pixel shr 7) and $7e0;
+    b := (s_pixel shl 8) and $f800;
 
-    d_pixel := r Or g Or b;
+    d_pixel := r or g or b;
 
-    Pshort16(dest)^ := d_pixel;
-  End;
-End;
+    PUint16(dest)^ := d_pixel;
+  end;
+end;
 
 { TO 16 RGB 555 }
-Procedure ConvertP_muhmu32_16rgb555(source, dest : Pchar8; count, inc_source : DWord); CDecl;
+procedure ConvertP_muhmu32_16rgb555(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  i: DWord;
+  r, g, b: Uint32;
+  s_pixel, d_pixelblock: Uint32;
+  d_pixel: Uint16;
+begin
+  if (PtrUInt(dest) and $3) <> 0 then
+  begin
+    s_pixel := PUint32(source)^;
 
-Var
-  i : DWord;
-  r, g, b : int32;
-  s_pixel, d_pixelblock : int32;
-  d_pixel : short16;
+    r := (s_pixel shr 13) and $7c00;
+    g := (s_pixel shr 8) and $3e0;
+    b := (s_pixel shr 3) and $1f;
 
-Begin
-  If (PtrUInt(dest) And $3) <> 0 Then
-  Begin
-    s_pixel := Pint32(source)^;
-  
-    r := (s_pixel Shr 13) And $7c00;
-    g := (s_pixel Shr 8) And $3e0;
-    b := (s_pixel Shr 3) And $1f;
+    d_pixel := r or g or b;
 
-    d_pixel := r Or g Or b;
-
-    Pshort16(dest)^ := d_pixel;
+    PUint16(dest)^ := d_pixel;
 
     Inc(source, 4);
     Inc(dest, 2);
     Dec(count);
-  End;
+  end;
 
-  For i := 1 To count Shr 1 Do
-  Begin
-    s_pixel := Pint32(source)^;
+  for i := 1 to count shr 1 do
+  begin
+    s_pixel := PUint32(source)^;
 
-    d_pixelblock := ((s_pixel Shr 13) And $7c00) Or
-                    ((s_pixel Shr 8) And $3e0) Or
-		    ((s_pixel Shr 3) And $1f);
+    d_pixelblock := (((s_pixel shr 13) and $7c00) or
+                     ((s_pixel shr 8) and $3e0) or
+                     ((s_pixel shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
 
-    s_pixel := (Pint32(source) + 1)^;
+    s_pixel := (PUint32(source) + 1)^;
 
-    d_pixelblock := d_pixelblock Or
-      ((((s_pixel Shr 13) And $7c00) Or
-        ((s_pixel Shr 8) And $3e0) Or
-	((s_pixel Shr 3) And $1f)) Shl 16);
+    d_pixelblock := d_pixelblock or
+      ((((s_pixel shr 13) and $7c00) or
+        ((s_pixel shr 8) and $3e0) or
+        ((s_pixel shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
 
-    Pint32(dest)^ := d_pixelblock;
+    PUint32(dest)^ := d_pixelblock;
     Inc(source, 8); Inc(dest, 4);
-  End;
+  end;
 
-  If (count And 1) <> 0 Then
-  Begin
-    s_pixel := Pint32(source)^;
+  if (count and 1) <> 0 then
+  begin
+    s_pixel := PUint32(source)^;
 
-    r := (s_pixel Shr 13) And $7c00;
-    g := (s_pixel Shr 8) And $3e0;
-    b := (s_pixel Shr 3) And $1f;
+    r := (s_pixel shr 13) and $7c00;
+    g := (s_pixel shr 8) and $3e0;
+    b := (s_pixel shr 3) and $1f;
 
-    d_pixel := r Or g Or b;
+    d_pixel := r or g or b;
 
-    Pshort16(dest)^ := d_pixel;
-  End;
-End;
+    PUint16(dest)^ := d_pixel;
+  end;
+end;
 
 { TO 16 BGR 555 }
-Procedure ConvertP_muhmu32_16bgr555(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  i : DWord;
-  r, g, b : int32;
-  s_pixel, d_pixelblock : int32;
-  d_pixel : short16;
+procedure ConvertP_muhmu32_16bgr555(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  i: DWord;
+  r, g, b: Uint32;
+  s_pixel, d_pixelblock: Uint32;
+  d_pixel: Uint16;
+begin
+  if (PtrUInt(dest) and $3) <> 0 then
+  begin
+    s_pixel := PUint32(source)^;
 
-Begin
-  If (PtrUInt(dest) And $3) <> 0 Then
-  Begin
-    s_pixel := Pint32(source)^;
-  
-    r := (s_pixel Shr 23) And $1f;
-    g := (s_pixel Shr 8) And $3e0;
-    b := (s_pixel Shl 7) And $7c00;
+    r := (s_pixel shr 23) and $1f;
+    g := (s_pixel shr 8) and $3e0;
+    b := (s_pixel shl 7) and $7c00;
 
-    d_pixel := r Or g Or b;
+    d_pixel := r or g or b;
 
-    Pshort16(dest)^ := d_pixel;
+    PUint16(dest)^ := d_pixel;
 
     Inc(source, 4);
     Inc(dest, 2);
     Dec(count);
-  End;
+  end;
 
-  For i := 1 To count Shr 1 Do
-  Begin
-    s_pixel := Pint32(source)^;
+  for i := 1 to count shr 1 do
+  begin
+    s_pixel := PUint32(source)^;
 
-    d_pixelblock := ((s_pixel Shr 23) And $1f) Or
-                    ((s_pixel Shr 8) And $3e0) Or
-		    ((s_pixel Shl 7) And $7c00);
+    d_pixelblock := (((s_pixel shr 23) and $1f) or
+                     ((s_pixel shr 8) and $3e0) or
+                     ((s_pixel shl 7) and $7c00)) shl DWORD_SMALLINT0_SHL;
 
-    s_pixel := (Pint32(source) + 1)^;
+    s_pixel := (PUint32(source) + 1)^;
 
-    d_pixelblock := d_pixelblock Or
-      ((((s_pixel Shr 23) And $1f) Or
-        ((s_pixel Shr 8) And $3e0) Or
-	((s_pixel Shl 7) And $7c00)) Shl 16);
+    d_pixelblock := d_pixelblock or
+      ((((s_pixel shr 23) and $1f) or
+        ((s_pixel shr 8) and $3e0) or
+        ((s_pixel shl 7) and $7c00)) shl DWORD_SMALLINT1_SHL);
 
-    Pint32(dest)^ := d_pixelblock;
+    PUint32(dest)^ := d_pixelblock;
     Inc(source, 8); Inc(dest, 4);
-  End;
+  end;
 
-  If (count And 1) <> 0 Then
-  Begin
-    s_pixel := Pint32(source)^;
+  if (count and 1) <> 0 then
+  begin
+    s_pixel := PUint32(source)^;
 
-    r := (s_pixel Shr 23) And $1f;
-    g := (s_pixel Shr 8) And $3e0;
-    b := (s_pixel Shl 7) And $7c00;
+    r := (s_pixel shr 23) and $1f;
+    g := (s_pixel shr 8) and $3e0;
+    b := (s_pixel shl 7) and $7c00;
 
-    d_pixel := r Or g Or b;
+    d_pixel := r or g or b;
 
-    Pshort16(dest)^ := d_pixel;
-  End;
-End;
+    PUint16(dest)^ := d_pixel;
+  end;
+end;
 
 { TO 8 RGB 332 }
-Procedure ConvertP_muhmu32_8rgb332(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  i : DWord;
-  s_pixel, d_block : int32;
-  d_pixel : char8;
-
-Begin
+procedure ConvertP_muhmu32_8rgb332(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  i: DWord;
+  s_pixel, d_block: Uint32;
+  d_pixel: Uint8;
+begin
   { Process single pixels until we are dword aligned }
-  While (PtrUInt(dest) And $3) <> 0 Do
-  Begin
-    s_pixel := Pint32(source)^;
+  while (PtrUInt(dest) and $3) <> 0 do
+  begin
+    s_pixel := PUint32(source)^;
 
-    d_pixel := ((s_pixel Shr 20) And $e0) Or
-               ((s_pixel Shr 13) And $1c) Or
-	       ((s_pixel Shr 6) And $3);
+    d_pixel := ((s_pixel shr 20) and $e0) or
+               ((s_pixel shr 13) and $1c) or
+               ((s_pixel shr 6) and $3);
 
     dest^ := d_pixel;
 
     Dec(count);
-    If count = 0 Then
-      Exit;
+    if count = 0 then
+      exit;
     Inc(dest);
     Inc(source, 4);
-  End;
+  end;
 
   { Now process blocks of four pixels }
-  For i := 1 To count Shr 2 Do
-  Begin
-    s_pixel := Pint32(source)^;
-    d_block := ((s_pixel Shr 20) And $e0) Or
-               ((s_pixel Shr 13) And $1c) Or
-	       ((s_pixel Shr 6) And $3);
-
-    s_pixel := (Pint32(source) + 1)^;
-    d_block := d_block Or
-               ((((s_pixel Shr 20) And $e0) Or
-                 ((s_pixel Shr 13) And $1c) Or
-	         ((s_pixel Shr 6) And $3)) Shl 8);
-
-    s_pixel := (Pint32(source) + 2)^;
-    d_block := d_block Or
-               ((((s_pixel Shr 20) And $e0) Or
-                 ((s_pixel Shr 13) And $1c) Or
-	         ((s_pixel Shr 6) And $3)) Shl 16);
-
-    s_pixel := (Pint32(source) + 3)^;
-    d_block := d_block Or
-               ((((s_pixel Shr 20) And $e0) Or
-                 ((s_pixel Shr 13) And $1c) Or
-	         ((s_pixel Shr 6) And $3)) Shl 24);
-
-    Pint32(dest)^ := d_block;
+  for i := 1 to count shr 2 do
+  begin
+    s_pixel := PUint32(source)^;
+    d_block := (((s_pixel shr 20) and $e0) or
+                ((s_pixel shr 13) and $1c) or
+                ((s_pixel shr 6) and $3)) shl DWORD_BYTE0_SHL;
+
+    s_pixel := (PUint32(source) + 1)^;
+    d_block := d_block or
+               ((((s_pixel shr 20) and $e0) or
+                 ((s_pixel shr 13) and $1c) or
+                 ((s_pixel shr 6) and $3)) shl DWORD_BYTE1_SHL);
+
+    s_pixel := (PUint32(source) + 2)^;
+    d_block := d_block or
+               ((((s_pixel shr 20) and $e0) or
+                 ((s_pixel shr 13) and $1c) or
+                 ((s_pixel shr 6) and $3)) shl DWORD_BYTE2_SHL);
+
+    s_pixel := (PUint32(source) + 3)^;
+    d_block := d_block or
+               ((((s_pixel shr 20) and $e0) or
+                 ((s_pixel shr 13) and $1c) or
+                 ((s_pixel shr 6) and $3)) shl DWORD_BYTE3_SHL);
+
+    PUint32(dest)^ := d_block;
     Inc(source, 16);
     Inc(dest, 4);
-  End;
+  end;
 
   { Write all possibly remaining pixel }
-  count := count And 3;
-  While count <> 0 Do
-  Begin
+  count := count and 3;
+  while count <> 0 do
+  begin
     Dec(count);
-    dest^ := ((s_pixel Shr 20) And $e0) Or
-             ((s_pixel Shr 13) And $1c) Or
-	     ((s_pixel Shr 6) And $3);
+    dest^ := ((s_pixel shr 20) and $e0) or
+             ((s_pixel shr 13) and $1c) or
+             ((s_pixel shr 6) and $3);
 
     Inc(dest);
     Inc(source, 4);
-  End;
-End;
+  end;
+end;
 
 { -------------------------------------------------------------------------
 
                              STRETCH CONVERTERS
-   
-  ------------------------------------------------------------------------- }
-
-Procedure ConvertP_muhmu32_32rgb888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
 
-Var
-  x : DWord;
-  s_pixel : DWord;
+  ------------------------------------------------------------------------- }
 
-Begin
+procedure ConvertP_muhmu32_32rgb888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+  s_pixel: DWord;
+begin
   x := 0;
-  While count > 0 Do
-  Begin
-    s_pixel := Pint32(source)^;
-    Pint32(dest)^ := (s_pixel And $ff) Or
-                    ((s_pixel And ($ff Shl 10)) Shr 2) Or
-	            ((s_pixel And ($ff Shl 20)) Shr 4);
+  while count > 0 do
+  begin
+    s_pixel := PUint32(source)^;
+    PUint32(dest)^ := (s_pixel and $ff) or
+                    ((s_pixel and ($ff shl 10)) shr 2) or
+                    ((s_pixel and ($ff shl 20)) shr 4);
     Inc(x, inc_source);
-    Inc(source, (x Shr 16)*4);
-    x := x And $FFFF;
+    Inc(source, (x shr 16)*4);
+    x := x and $FFFF;
     Inc(dest, 4);
     Dec(count);
-  End;
-End;
-
-Procedure ConvertP_muhmu32_32bgr888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x : DWord;
-  s_pixel : DWord;
-
-Begin
+  end;
+end;
+
+procedure ConvertP_muhmu32_32bgr888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+  s_pixel: DWord;
+begin
   x := 0;
-  While count > 0 Do
-  Begin
-    s_pixel := Pint32(source)^;
-    Pint32(dest)^ := ((s_pixel And $ff) Shl 16) Or
-                     ((s_pixel And ($ff Shl 10)) Shr 2) Or
-	             ((s_pixel Shr 20) And $FF);
+  while count > 0 do
+  begin
+    s_pixel := PUint32(source)^;
+    PUint32(dest)^ := ((s_pixel and $ff) shl 16) or
+                     ((s_pixel and ($ff shl 10)) shr 2) or
+                     ((s_pixel shr 20) and $FF);
     Inc(x, inc_source);
-    Inc(source, (x Shr 16)*4);
-    x := x And $FFFF;
+    Inc(source, (x shr 16)*4);
+    x := x and $FFFF;
     Inc(dest, 4);
     Dec(count);
-  End;
-End;
-
-Procedure ConvertP_muhmu32_32rgba888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x : DWord;
-  s_pixel : DWord;
-
-Begin
+  end;
+end;
+
+procedure ConvertP_muhmu32_32rgba888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+  s_pixel: DWord;
+begin
   x := 0;
-  While count > 0 Do
-  Begin
-    s_pixel := Pint32(source)^;
-    Pint32(dest)^ := (((s_pixel And $ff) Or
-                      ((s_pixel And ($ff Shl 10)) Shr 2) Or
-	              ((s_pixel And ($ff Shl 20)) Shr 4)) Shl 8) Or $FF;
+  while count > 0 do
+  begin
+    s_pixel := PUint32(source)^;
+    PUint32(dest)^ := (((s_pixel and $ff) or
+                      ((s_pixel and ($ff shl 10)) shr 2) or
+                      ((s_pixel and ($ff shl 20)) shr 4)) shl 8) or $FF;
     Inc(x, inc_source);
-    Inc(source, (x Shr 16)*4);
-    x := x And $FFFF;
+    Inc(source, (x shr 16)*4);
+    x := x and $FFFF;
     Inc(dest, 4);
     Dec(count);
-  End;
-End;
-
-Procedure ConvertP_muhmu32_32bgra888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x : DWord;
-  s_pixel : DWord;
-
-Begin
+  end;
+end;
+
+procedure ConvertP_muhmu32_32bgra888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+  s_pixel: DWord;
+begin
   x := 0;
-  While count > 0 Do
-  Begin
-    s_pixel := Pint32(source)^;
-    Pint32(dest)^ := (((s_pixel And $ff) Shl 24) Or
-                      ((s_pixel And ($ff Shl 10)) Shl 6) Or
-	              ((s_pixel Shr 12) And $FF00)) Or $FF;
+  while count > 0 do
+  begin
+    s_pixel := PUint32(source)^;
+    PUint32(dest)^ := (((s_pixel and $ff) shl 24) or
+                      ((s_pixel and ($ff shl 10)) shl 6) or
+                      ((s_pixel shr 12) and $FF00)) or $FF;
     Inc(x, inc_source);
-    Inc(source, (x Shr 16)*4);
-    x := x And $FFFF;
+    Inc(source, (x shr 16)*4);
+    x := x and $FFFF;
     Inc(dest, 4);
     Dec(count);
-  End;
-End;
-
-Procedure ConvertP_muhmu32_24rgb888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x : DWord;
-  p1, p2, p3, p4 : DWord;
-  c : DWord;
-
-Begin
+  end;
+end;
+
+procedure ConvertP_muhmu32_24rgb888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+  p1, p2, p3, p4: DWord;
+  c: DWord;
+begin
   x := 0;
-  While (PtrUInt(dest) And 3) <> 0 Do
-  Begin
-    p1 := (Pint32(source) + (x Shr 16))^;
-    p1 := (p1 And $ff) Or
-         ((p1 And ($ff Shl 10)) Shr 2) Or
-         ((p1 And ($ff Shl 20)) Shr 4);
-    Pshort16(dest)^ := p1 And $FFFF;
-    Pchar8(dest + 2)^ := p1 Shr 16;
-    
+  while (PtrUInt(dest) and 3) <> 0 do
+  begin
+    p1 := (PUint32(source) + (x shr 16))^;
+    p1 := (p1 and $ff) or
+         ((p1 and ($ff shl 10)) shr 2) or
+         ((p1 and ($ff shl 20)) shr 4);
+    PUint8(dest + B_24)^ := p1 and $FF;
+    PUint8(dest + G_24)^ := (p1 shr 8) and $FF;
+    PUint8(dest + R_24)^ := p1 shr 16;
+
     Inc(x, inc_source);
     Inc(dest, 3);
     Dec(count);
-    If count = 0 Then
-      Exit;
-  End;
-  
-  c := count Shr 2;
-  While c > 0 Do
-  Begin
-    p1 := (Pint32(source) + (x Shr 16))^;
-    p2 := (Pint32(source) + ((x + inc_source) Shr 16))^;
-    p3 := (Pint32(source) + ((x + 2*inc_source) Shr 16))^;
-    p4 := (Pint32(source) + ((x + 3*inc_source) Shr 16))^;
-    
-    Pint32(dest + 0)^ := ((p2 And $FF) Shl 24) Or ((p1 And $FF00000) Shr 4) Or ((p1 And $3FC00) Shr 2) Or (p1 And $FF);
-    Pint32(dest + 4)^ := ((p3 And $3FC00) Shl 14) Or ((p3 And $FF) Shl 16) Or ((p2 And $FF00000) Shr 12) Or ((p2 And $3FC00) Shr 10);
-    Pint32(dest + 8)^ := ((p4 And $FF00000) Shl 4) Or ((p4 And $3FC00) Shl 6) Or ((p4 And $FF) Shl 8) Or ((p3 And $FF00000) Shr 20);
-    
+    if count = 0 then
+      exit;
+  end;
+
+  c := count shr 2;
+  while c > 0 do
+  begin
+    p1 := (PUint32(source) + (x shr 16))^;
+    p2 := (PUint32(source) + ((x + inc_source) shr 16))^;
+    p3 := (PUint32(source) + ((x + 2*inc_source) shr 16))^;
+    p4 := (PUint32(source) + ((x + 3*inc_source) shr 16))^;
+
+    {$IFDEF FPC_LITTLE_ENDIAN}
+    PUint32(dest + 0)^ := ((p2 and $FF) shl 24) or ((p1 and $FF00000) shr 4) or ((p1 and $3FC00) shr 2) or (p1 and $FF);
+    PUint32(dest + 4)^ := ((p3 and $3FC00) shl 14) or ((p3 and $FF) shl 16) or ((p2 and $FF00000) shr 12) or ((p2 and $3FC00) shr 10);
+    PUint32(dest + 8)^ := ((p4 and $FF00000) shl 4) or ((p4 and $3FC00) shl 6) or ((p4 and $FF) shl 8) or ((p3 and $FF00000) shr 20);
+    {$ELSE FPC_LITTLE_ENDIAN}
+    PUint32(dest + 0)^ := ((p1 and $FF00000) shl 4) or ((p1 and $3FC00) shl 6) or ((p1 and $FF) shl 8) or ((p2 and $FF00000) shr 20);
+    PUint32(dest + 4)^ := ((p2 and $3FC00) shl 14) or ((p2 and $FF) shl 16) or ((p3 and $FF00000) shr 12) or ((p3 and $3FC00) shr 10);
+    PUint32(dest + 8)^ := ((p3 and $FF) shl 24) or ((p4 and $FF00000) shr 4) or ((p4 and $3FC00) shr 2) or (p4 and $FF);
+    {$ENDIF FPC_LITTLE_ENDIAN}
+
     Dec(c);
     Inc(x, inc_source*4);
     Inc(dest, 12);
-  End;
-  
-  count := count And 3;
-  While count > 0 Do
-  Begin
-    p1 := (Pint32(source) + (x Shr 16))^;
-    p1 := (p1 And $ff) Or
-         ((p1 And ($ff Shl 10)) Shr 2) Or
-         ((p1 And ($ff Shl 20)) Shr 4);
-    Pshort16(dest)^ := p1 And $FFFF;
-    Pchar8(dest + 2)^ := p1 Shr 16;
-    
+  end;
+
+  count := count and 3;
+  while count > 0 do
+  begin
+    p1 := (PUint32(source) + (x shr 16))^;
+    p1 := (p1 and $ff) or
+         ((p1 and ($ff shl 10)) shr 2) or
+         ((p1 and ($ff shl 20)) shr 4);
+    PUint8(dest + B_24)^ := p1 and $FF;
+    PUint8(dest + G_24)^ := (p1 shr 8) and $FF;
+    PUint8(dest + R_24)^ := p1 shr 16;
+
     Inc(x, inc_source);
     Inc(dest, 3);
     Dec(count);
-  End;
-End;
-
-Procedure ConvertP_muhmu32_24bgr888_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x : DWord;
-  p1, p2, p3, p4 : DWord;
-  c : DWord;
-
-Begin
+  end;
+end;
+
+procedure ConvertP_muhmu32_24bgr888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x: DWord;
+  p1, p2, p3, p4: DWord;
+  c: DWord;
+begin
   x := 0;
-  While (PtrUInt(dest) And 3) <> 0 Do
-  Begin
-    p1 := (Pint32(source) + (x Shr 16))^;
-    p1 := ((p1 And $ff) Shl 16) Or
-          ((p1 And ($ff Shl 10)) Shr 2) Or
-          ((p1 And ($ff Shl 20)) Shr 20);
-    Pshort16(dest)^ := p1 And $FFFF;
-    Pchar8(dest + 2)^ := p1 Shr 16;
-    
+  while (PtrUInt(dest) and 3) <> 0 do
+  begin
+    p1 := (PUint32(source) + (x shr 16))^;
+    p1 := ((p1 and $ff) shl 16) or
+          ((p1 and ($ff shl 10)) shr 2) or
+          ((p1 and ($ff shl 20)) shr 20);
+    PUint8(dest + B_24)^ := p1 and $FF;
+    PUint8(dest + G_24)^ := (p1 shr 8) and $FF;
+    PUint8(dest + R_24)^ := p1 shr 16;
+
     Inc(x, inc_source);
     Inc(dest, 3);
     Dec(count);
-    If count = 0 Then
-      Exit;
-  End;
-  
-  c := count Shr 2;
-  While c > 0 Do
-  Begin
-    p1 := (Pint32(source) + (x Shr 16))^;
-    p2 := (Pint32(source) + ((x + inc_source) Shr 16))^;
-    p3 := (Pint32(source) + ((x + 2*inc_source) Shr 16))^;
-    p4 := (Pint32(source) + ((x + 3*inc_source) Shr 16))^;
-    
-    Pint32(dest + 0)^ := ((p2 And $FF00000) Shl 4) Or ((p1 And $FF) Shl 16) Or ((p1 And $3FC00) Shr 2) Or ((p1 And $FF00000) Shr 20);
-    Pint32(dest + 4)^ := ((p3 And $3FC00) Shl 14) Or ((p3 And $FF00000) Shr 4) Or ((p2 And $FF) Shl 8) Or ((p2 And $3FC00) Shr 10);
-    Pint32(dest + 8)^ := ((p4 And $FF) Shl 24) Or ((p4 And $3FC00) Shl 6) Or ((p4 And $FF00000) Shr 12) Or (p3 And $FF);
-    
+    if count = 0 then
+      exit;
+  end;
+
+  c := count shr 2;
+  while c > 0 do
+  begin
+    p1 := (PUint32(source) + (x shr 16))^;
+    p2 := (PUint32(source) + ((x + inc_source) shr 16))^;
+    p3 := (PUint32(source) + ((x + 2*inc_source) shr 16))^;
+    p4 := (PUint32(source) + ((x + 3*inc_source) shr 16))^;
+
+    {$IFDEF FPC_LITTLE_ENDIAN}
+    PUint32(dest + 0)^ := ((p2 and $FF00000) shl 4) or ((p1 and $FF) shl 16) or ((p1 and $3FC00) shr 2) or ((p1 and $FF00000) shr 20);
+    PUint32(dest + 4)^ := ((p3 and $3FC00) shl 14) or ((p3 and $FF00000) shr 4) or ((p2 and $FF) shl 8) or ((p2 and $3FC00) shr 10);
+    PUint32(dest + 8)^ := ((p4 and $FF) shl 24) or ((p4 and $3FC00) shl 6) or ((p4 and $FF00000) shr 12) or (p3 and $FF);
+    {$ELSE FPC_LITTLE_ENDIAN}
+    PUint32(dest + 0)^ := ((p1 and $FF) shl 24) or ((p1 and $3FC00) shl 6) or ((p1 and $FF00000) shr 12) or (p2 and $FF);
+    PUint32(dest + 4)^ := ((p2 and $3FC00) shl 14) or ((p2 and $FF00000) shr 4) or ((p3 and $FF) shl 8) or ((p3 and $3FC00) shr 10);
+    PUint32(dest + 8)^ := ((p3 and $FF00000) shl 4) or ((p4 and $FF) shl 16) or ((p4 and $3FC00) shr 2) or ((p4 and $FF00000) shr 20);
+    {$ENDIF FPC_LITTLE_ENDIAN}
+
     Dec(c);
     Inc(x, inc_source*4);
     Inc(dest, 12);
-  End;
-  
-  count := count And 3;
-  While count > 0 Do
-  Begin
-    p1 := (Pint32(source) + (x Shr 16))^;
-    p1 := ((p1 And $ff) Shl 16) Or
-          ((p1 And ($ff Shl 10)) Shr 2) Or
-          ((p1 And ($ff Shl 20)) Shr 20);
-    Pshort16(dest)^ := p1 And $FFFF;
-    Pchar8(dest + 2)^ := p1 Shr 16;
-    
+  end;
+
+  count := count and 3;
+  while count > 0 do
+  begin
+    p1 := (PUint32(source) + (x shr 16))^;
+    p1 := ((p1 and $ff) shl 16) or
+          ((p1 and ($ff shl 10)) shr 2) or
+          ((p1 and ($ff shl 20)) shr 20);
+    PUint8(dest + B_24)^ := p1 and $FF;
+    PUint8(dest + G_24)^ := (p1 shr 8) and $FF;
+    PUint8(dest + R_24)^ := p1 shr 16;
+
     Inc(x, inc_source);
     Inc(dest, 3);
     Dec(count);
-  End;
-End;
-
-Procedure ConvertP_muhmu32_16rgb565_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x, c : DWord;
-  p : int32;
-
-Begin
+  end;
+end;
+
+procedure ConvertP_muhmu32_16rgb565_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x, c: DWord;
+  p: Uint32;
+begin
   x := 0;
   { Try to write 2 pixel blocks }
-  c := count Shr 1; 
-  While c <> 0 Do
-  Begin
+  c := count shr 1;
+  while c <> 0 do
+  begin
     Dec(c);
-    p := (((Pint32(source) + (x Shr 16))^ Shr 12) And $f800) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 7) And $7e0) Or
-	 (((Pint32(source) + (x Shr 16))^ Shr 3) And $1f);
+    p := ((((PUint32(source) + (x shr 16))^ shr 12) and $f800) or
+          (((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
+          (((PUint32(source) + (x shr 16))^ shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
     Inc(x, inc_source);
 
-    p := p Or
-       (((((Pint32(source) + (x Shr 16))^ Shr 12) And $f800) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 7) And $7e0) Or
-	 (((Pint32(source) + (x Shr 16))^ Shr 3) And $1f)) Shl 16);
+    p := p or
+       (((((PUint32(source) + (x shr 16))^ shr 12) and $f800) or
+         (((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
+         (((PUint32(source) + (x shr 16))^ shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
     Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
 
     Inc(dest, 4);
-  End;
+  end;
 
   { Write trailing pixel }
-  If (count And 1) <> 0 Then
-    Pshort16(dest)^ := (((Pint32(source) + (x Shr 16))^ Shr 12) And $f800) Or
-                       (((Pint32(source) + (x Shr 16))^ Shr 7) And $7e0) Or
-	               (((Pint32(source) + (x Shr 16))^ Shr 3) And $1f);
-End;
-
-Procedure ConvertP_muhmu32_16bgr565_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x, c : DWord;
-  p : int32;
-
-Begin
+  if (count and 1) <> 0 then
+    PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 12) and $f800) or
+                       (((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
+                       (((PUint32(source) + (x shr 16))^ shr 3) and $1f);
+end;
+
+procedure ConvertP_muhmu32_16bgr565_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x, c: DWord;
+  p: Uint32;
+begin
   x := 0;
   { Try to write 2 pixel blocks }
-  c := count Shr 1; 
-  While c <> 0 Do
-  Begin
+  c := count shr 1;
+  while c <> 0 do
+  begin
     Dec(c);
-    p := (((Pint32(source) + (x Shr 16))^ Shr 23) And $1f) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 7) And $7e0) Or
-	 (((Pint32(source) + (x Shr 16))^ Shl 8) And $f800);
+    p := ((((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
+          (((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
+          (((PUint32(source) + (x shr 16))^ shl 8) and $f800)) shl DWORD_SMALLINT0_SHL;
     Inc(x, inc_source);
 
-    p := p Or
-       (((((Pint32(source) + (x Shr 16))^ Shr 23) And $1f) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 7) And $7e0) Or
-	 (((Pint32(source) + (x Shr 16))^ Shl 8) And $f800)) Shl 16);
+    p := p or
+       (((((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
+         (((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
+         (((PUint32(source) + (x shr 16))^ shl 8) and $f800)) shl DWORD_SMALLINT1_SHL);
     Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
 
     Inc(dest, 4);
-  End;
+  end;
 
   { Write trailing pixel }
-  If (count And 1) <> 0 Then
-    Pshort16(dest)^ := (((Pint32(source) + (x Shr 16))^ Shr 23) And $1f) Or
-                       (((Pint32(source) + (x Shr 16))^ Shr 7) And $7e0) Or
-	               (((Pint32(source) + (x Shr 16))^ Shl 8) And $f800);
-End;
-
-Procedure ConvertP_muhmu32_16rgb555_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x, c : DWord;
-  p : int32;
-
-Begin
+  if (count and 1) <> 0 then
+    PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
+                       (((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
+                       (((PUint32(source) + (x shr 16))^ shl 8) and $f800);
+end;
+
+procedure ConvertP_muhmu32_16rgb555_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x, c: DWord;
+  p: Uint32;
+begin
   x := 0;
   { Try to write 2 pixel blocks }
-  c := count Shr 1; 
-  While c <> 0 Do
-  Begin
+  c := count shr 1;
+  while c <> 0 do
+  begin
     Dec(c);
-    p := (((Pint32(source) + (x Shr 16))^ Shr 13) And $7c00) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 8) And $3e0) Or
-	 (((Pint32(source) + (x Shr 16))^ Shr 3) And $1f);
+    p := ((((PUint32(source) + (x shr 16))^ shr 13) and $7c00) or
+          (((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
+          (((PUint32(source) + (x shr 16))^ shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
     Inc(x, inc_source);
 
-    p := p Or
-       (((((Pint32(source) + (x Shr 16))^ Shr 13) And $7c00) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 8) And $3e0) Or
-	 (((Pint32(source) + (x Shr 16))^ Shr 3) And $1f)) Shl 16);
+    p := p or
+       (((((PUint32(source) + (x shr 16))^ shr 13) and $7c00) or
+         (((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
+         (((PUint32(source) + (x shr 16))^ shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
     Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
 
     Inc(dest, 4);
-  End;
+  end;
 
   { Write trailing pixel }
-  If (count And 1) <> 0 Then
-    Pshort16(dest)^ := (((Pint32(source) + (x Shr 16))^ Shr 13) And $7c00) Or
-                       (((Pint32(source) + (x Shr 16))^ Shr 8) And $3e0) Or
-	               (((Pint32(source) + (x Shr 16))^ Shr 3) And $1f);
-End;
-
-Procedure ConvertP_muhmu32_16bgr555_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x, c : DWord;
-  p : int32;
-
-Begin
+  if (count and 1) <> 0 then
+    PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 13) and $7c00) or
+                       (((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
+                       (((PUint32(source) + (x shr 16))^ shr 3) and $1f);
+end;
+
+procedure ConvertP_muhmu32_16bgr555_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x, c: DWord;
+  p: Uint32;
+begin
   x := 0;
   { Try to write 2 pixel blocks }
-  c := count Shr 1; 
-  While c <> 0 Do
-  Begin
+  c := count shr 1;
+  while c <> 0 do
+  begin
     Dec(c);
-    p := (((Pint32(source) + (x Shr 16))^ Shr 23) And $1f) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 8) And $3e0) Or
-	 (((Pint32(source) + (x Shr 16))^ Shl 7) And $7c00);
+    p := ((((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
+          (((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
+          (((PUint32(source) + (x shr 16))^ shl 7) and $7c00)) shl DWORD_SMALLINT0_SHL;
     Inc(x, inc_source);
 
-    p := p Or
-       (((((Pint32(source) + (x Shr 16))^ Shr 23) And $1f) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 8) And $3e0) Or
-	 (((Pint32(source) + (x Shr 16))^ Shl 7) And $7c00)) Shl 16);
+    p := p or
+       (((((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
+         (((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
+         (((PUint32(source) + (x shr 16))^ shl 7) and $7c00)) shl DWORD_SMALLINT1_SHL);
     Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
 
     Inc(dest, 4);
-  End;
+  end;
 
   { Write trailing pixel }
-  If (count And 1) <> 0 Then
-    Pshort16(dest)^ := (((Pint32(source) + (x Shr 16))^ Shr 23) And $1f) Or
-                       (((Pint32(source) + (x Shr 16))^ Shr 8) And $3e0) Or
-	               (((Pint32(source) + (x Shr 16))^ Shl 7) And $7c00);
-End;
-
-Procedure ConvertP_muhmu32_8rgb332_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
-
-Var
-  x, c : DWord;
-  p : int32;
-
-Begin
+  if (count and 1) <> 0 then
+    PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
+                       (((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
+                       (((PUint32(source) + (x shr 16))^ shl 7) and $7c00);
+end;
+
+procedure ConvertP_muhmu32_8rgb332_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
+var
+  x, c: DWord;
+  p: Uint32;
+begin
   x := 0;
 
   { Write single pixels until the destination address is aligned mod 4 }
-  While (PtrUInt(dest) And $3) <> 0 Do
-  Begin
-    dest^ := (((Pint32(source) + (x Shr 16))^ Shr 20) And $e0) Or
-             (((Pint32(source) + (x Shr 16))^ Shr 13) And $1c) Or
-	     (((Pint32(source) + (x Shr 16))^ Shr 6) And $3);
+  while (PtrUInt(dest) and $3) <> 0 do
+  begin
+    dest^ := (((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
+             (((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
+             (((PUint32(source) + (x shr 16))^ shr 6) and $3);
     Inc(x, inc_source);
     Inc(dest);
     Dec(count);
-    If count = 0 Then
-      Exit;
-  End;
+    if count = 0 then
+      exit;
+  end;
 
   { Write blocks of four pixels now }
-  c := count Shr 2;
-  While c <> 0 Do
-  Begin
+  c := count shr 2;
+  while c <> 0 do
+  begin
     Dec(c);
-    p := (((Pint32(source) + (x Shr 16))^ Shr 20) And $e0) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 13) And $1c) Or
-	 (((Pint32(source) + (x Shr 16))^ Shr 6) And $3);
+    p := ((((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
+          (((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
+          (((PUint32(source) + (x shr 16))^ shr 6) and $3)) shl DWORD_BYTE0_SHL;
     Inc(x, inc_source);
 
-    p := p Or
-       (((((Pint32(source) + (x Shr 16))^ Shr 20) And $e0) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 13) And $1c) Or
-	 (((Pint32(source) + (x Shr 16))^ Shr 6) And $3)) Shl 8);
+    p := p or
+       (((((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
+         (((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
+         (((PUint32(source) + (x shr 16))^ shr 6) and $3)) shl DWORD_BYTE1_SHL);
     Inc(x, inc_source);
 
-    p := p Or
-       (((((Pint32(source) + (x Shr 16))^ Shr 20) And $e0) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 13) And $1c) Or
-	 (((Pint32(source) + (x Shr 16))^ Shr 6) And $3)) Shl 16);
+    p := p or
+       (((((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
+         (((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
+         (((PUint32(source) + (x shr 16))^ shr 6) and $3)) shl DWORD_BYTE2_SHL);
     Inc(x, inc_source);
 
-    p := p Or
-       (((((Pint32(source) + (x Shr 16))^ Shr 20) And $e0) Or
-         (((Pint32(source) + (x Shr 16))^ Shr 13) And $1c) Or
-	 (((Pint32(source) + (x Shr 16))^ Shr 6) And $3)) Shl 24);
+    p := p or
+       (((((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
+         (((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
+         (((PUint32(source) + (x shr 16))^ shr 6) and $3)) shl DWORD_BYTE3_SHL);
     Inc(x, inc_source);
 
-    Pint32(dest)^ := p;
+    PUint32(dest)^ := p;
 
     Inc(dest, 4);
-  End;
+  end;
 
   { Write up to three trailing pixels }
-  c := count And $3;
-  While c <> 0 Do
-  Begin
+  c := count and $3;
+  while c <> 0 do
+  begin
     Dec(c);
-    dest^ := (((Pint32(source) + (x Shr 16))^ Shr 20) And $e0) Or
-             (((Pint32(source) + (x Shr 16))^ Shr 13) And $1c) Or
-	     (((Pint32(source) + (x Shr 16))^ Shr 6) And $3);
+    dest^ := (((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
+             (((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
+             (((PUint32(source) + (x shr 16))^ shr 6) and $3);
     Inc(x, inc_source);
     Inc(dest);
-  End;
-End;
+  end;
+end;

+ 0 - 348
packages/hermes/src/palette.inc

@@ -1,348 +0,0 @@
-{
-    Free Pascal port of the Hermes C library.
-    Copyright (C) 2001-2003  Nikolay Nikolov ([email protected])
-    Original C version by Christian Nentwich ([email protected])
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library 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
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-}
-
-Type
-  PHermesLookupTable = ^THermesLookupTable;
-  THermesLookupTable = Record
-    data : ^int32;             { Actual lookup table }
-    valid : Boolean;           { Is this table up to date? }
-    format : THermesFormat;    { Format of lookup table }
-  End;
-  PHermesPalette = ^THermesPalette;
-  THermesPalette = Record
-    data : ^int32;             { Palette data }
-    tables : PHermesList;      { Linked list of HermesLookupTables }
-  End;
-
-Const
-  PaletteList : PHermesList = Nil;
-  PALETTErefcount : Integer = 0;
-  currenthandle : THermesHandle = 0;
-
-{Function Hermes_PaletteGetTable(palette : THermesHandle; format : PHermesFormat) : Pointer;
-Procedure Hermes_PaletteMakeLookup(lookup, palette : Pint32;
-                                   format : PHermesFormat);
-
-Function Hermes_PaletteInstance : THermesHandle;
-Procedure Hermes_PaletteReturn(handle : THermesHandle);
-Procedure Hermes_PaletteSet(handle : THermesHandle; palette : Pointer);
-Function Hermes_PaletteGet(handle : THermesHandle) : Pointer;
-Procedure Hermes_PaletteInvalidateCache(handle : THermesHandle);}
-
-Function Hermes_PaletteInstance : THermesHandle;
-
-Var
-  newinstance : PHermesPalette;
-  newelement : PHermesListElement;
-
-Begin
-  If PaletteList = Nil Then
-  Begin
-    PaletteList := Hermes_ListNew;
-    { Could not create a new list }
-    If PaletteList = Nil Then
-    Begin
-      Hermes_PaletteInstance := 0;
-      Exit;
-    End;
-  End;
-  { Create a new palette structure }
-  newinstance := malloc(SizeOf(THermesPalette));
-  If newinstance = Nil Then
-  Begin
-    Hermes_PaletteInstance := 0;
-    Exit;
-  End;
-  { Create palette data }
-  newinstance^.data := malloc(256*SizeOf(int32));
-  If newinstance^.data = Nil Then
-  Begin
-    free(newinstance);
-    Hermes_PaletteInstance := 0;
-    Exit;
-  End;
-  { Create lookup table list }
-  newinstance^.tables := Hermes_ListNew;
-  If newinstance^.tables = Nil Then
-  Begin
-    free(newinstance^.data);
-    free(newinstance);
-    Hermes_PaletteInstance := 0;
-    Exit;
-  End;
-  { Everything fine so far, create a new list element }
-  newelement := Hermes_ListElementNew(currenthandle+1);
-  If newelement = Nil Then
-  Begin
-    Hermes_ListDestroy(newinstance^.tables);
-    free(newinstance^.data);
-    free(newinstance);
-    Hermes_PaletteInstance := 0;
-    Exit;
-  End;
-
-  { No errors, put current palette structure into the list element and add
-    that to the list }
-  newelement^.data := newinstance;
-
-  Hermes_ListAdd(PaletteList, newelement);
-
-  Inc(PALETTErefcount);
-  Inc(currenthandle);
-  Hermes_PaletteInstance := currenthandle;
-End;
-
-Procedure Hermes_PaletteReturn(handle : THermesHandle);
-
-Var
-  element : PHermesListElement;
-  pal : PHermesPalette;
-  table : PHermesLookupTable;
-
-Begin
-  element := Hermes_ListLookup(PaletteList, handle);
-  If element = Nil Then
-    Exit;
-
-  pal := element^.data;
-
-
-  { Free palette data and lookup tables }
-  free(pal^.data);
-
-  element := pal^.tables^.first;
-  While element <> Nil Do
-  Begin
-    table := element^.data;
-    If (table <> Nil) And (table^.data <> Nil) Then
-    Begin
-      free(table^.data);
-      table^.data := Nil;
-    End;
-    element := element^.next;
-  End;
-  Hermes_ListDestroy(pal^.tables);
-
-
-  { Delete list element that holds this palette }
-  Hermes_ListDeleteElement(PaletteList, handle);
-
-
-  { Decrease reference count. If down to zero, delete palette list }
-  Dec(PALETTErefcount);
-  If PALETTErefcount = 0 Then
-  Begin
-    Hermes_ListDestroy(PaletteList);
-    PaletteList := Nil;
-  End;
-End;
-
-Procedure Hermes_PaletteSet(handle : THermesHandle; palette : Pointer);
-
-Var
-  element : PHermesListElement;
-  pal : PHermesPalette;
-
-Begin
-{  DebugMSG('Hermes_PaletteSet('+C2Str(handle)+','+C2Str(DWord(palette))+')');}
-  element := Hermes_ListLookup(PaletteList, handle);
-  If element = Nil Then
-    Exit;
-
-  pal := element^.data;
-  element := pal^.tables^.first;
-
-  { Invalidate all lookup tables }
-
-  While element <> Nil Do
-  Begin
-    (PHermesLookupTable(element^.data))^.valid := False;
-    element := element^.next;
-  End;
-
-{  FillChar(palette^, 256*4, $7f);}
-  Move(palette^, pal^.data^, 256*4);
-End;
-
-Function Hermes_PaletteGet(handle : THermesHandle) : Pointer;
-
-Var
-  element : PHermesListElement;
-  pal : PHermesPalette;
-
-Begin
-  element := Hermes_ListLookup(PaletteList, handle);
-  If element = Nil Then
-  Begin
-    Hermes_PaletteGet := Nil;
-    Exit;
-  End;
-
-  pal := element^.data;
-  Hermes_PaletteGet := pal^.data;
-End;
-
-Procedure Hermes_PaletteMakeLookup(lookup, palette : Pint32;
-                                   format : PHermesFormat);
-
-Var
-  info : THermesGenericInfo;
-  I : Integer;
-  r, g, b : int32;
-
-Begin
-{  DebugMSG('Yo! Hermes_PaletteMakeLookup');}
-  r := 0;
-  g := 0;
-  b := 0;
-  If format^.indexed Then
-    Exit;
-
-  Hermes_Calculate_Generic_Info(24,16,8,32,
-                                Hermes_Topbit(format^.r),
-                                Hermes_Topbit(format^.g),
-                                Hermes_Topbit(format^.b),
-                                Hermes_Topbit(format^.a),
-                                @info);
-
-  { Optimised loop if there are no left shifts }
-  If (info.r_left = 0) And (info.g_left = 0) And (info.b_left = 0) Then
-    For I := 0 To 255 Do
-    Begin
-      r := (palette[i] Shr info.r_right) And format^.r;
-      g := (palette[i] Shr info.g_right) And format^.g;
-      b := (palette[i] Shr info.b_right) And format^.b;
-      lookup[i] := r Or g Or b;
-    End
-  Else
-    For I := 0 To 255 Do
-    Begin
-      r := ((palette[i] Shr info.r_right) Shl info.r_left) And format^.r;
-      g := ((palette[i] Shr info.g_right) Shl info.g_left) And format^.g;
-      b := ((palette[i] Shr info.b_right) Shl info.b_left) And format^.b;
-      lookup[i] := r Or g Or b;
-    End;
-End;
-
-Function Hermes_PaletteGetTable(palette : THermesHandle; format : PHermesFormat) : Pointer;
-
-Var
-  element : PHermesListElement;
-  pal : PHermesPalette;
-  table : PHermesLookupTable;
-
-Begin
-  element := Hermes_ListLookup(PaletteList, palette);
-  If element = Nil Then
-  Begin
-    Hermes_PaletteGetTable := Nil;
-    Exit;
-  End;
-
-  pal := element^.data;
-
-  { Go to the first table in the list }
-  element := pal^.tables^.first;
-
-  { Search for correct table using format }
-  While element <> Nil Do
-  Begin
-    table := element^.data;
-
-    If Hermes_FormatEquals(@table^.format, format) Then
-    Begin
-      If table^.valid Then
-      Begin
-        Hermes_PaletteGetTable := table^.data;
-        Exit;
-      End;
-
-      { Have to recreate the lookup table }
-      Hermes_PaletteMakeLookup(table^.data, pal^.data, format);
-      table^.valid := True;
-
-      Hermes_PaletteGetTable := table^.data;
-      Exit;
-    End;
-
-    element := element^.next;
-  End;
-
-  { Format not found, have to create a new table (need no handle) }
-  table := malloc(SizeOf(THermesLookupTable));
-  If table = Nil Then
-  Begin
-    Hermes_PaletteGetTable := Nil;
-    Exit;
-  End;
-
-  table^.data := malloc(1024);
-  If table^.data = Nil Then
-  Begin
-    Hermes_PaletteGetTable := Nil;
-    Exit;
-  End;
-
-  { Create lookup table }
-  Hermes_PaletteMakeLookup(table^.data, pal^.data, format);
-  Hermes_FormatCopy(format, @table^.format);
-
-  table^.valid := True;
-
-  { Create a new list element }
-  element := Hermes_ListElementNew(0);
-  If element = Nil Then
-  Begin
-    Hermes_PaletteGetTable := Nil;
-    Exit;
-  End;
-  element^.data := table;
-
-  { Add to the front of the list }
-  Hermes_ListAddFront(pal^.tables, element);
-
-  { Return lookup data }
-  Hermes_PaletteGetTable := table^.data;
-
-End;
-
-Procedure Hermes_PaletteInvalidateCache(handle : THermesHandle);
-
-Var
-  element : PHermesListElement;
-  pal : PHermesPalette;
-
-Begin
-  element := Hermes_ListLookup(PaletteList, handle);
-  If element = Nil Then
-    Exit;
-
-  pal := element^.data;
-
-  element := pal^.tables^.first;
-
-  { Invalidate all lookup tables }
-
-  While element <> Nil Do
-  Begin
-    (PHermesLookupTable(element^.data))^.valid := False;
-    element := element^.next;
-  End;
-End;

+ 0 - 111
packages/hermes/src/utility.inc

@@ -1,111 +0,0 @@
-{
-    Free Pascal port of the Hermes C library.
-    Copyright (C) 2001-2003  Nikolay Nikolov ([email protected])
-    Original C version by Christian Nentwich ([email protected])
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library 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
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-}
-
-{Procedure Hermes_Calculate_Generic_Info(s_r, s_g, s_b, s_a, 
-                                        d_r, d_g, d_b, d_a : int32;
-					info : PHermesGenericInfo);
-Function Hermes_Topbit(mask : int32) : Integer;}
-
-Procedure Hermes_Calculate_Generic_Info(s_r, s_g, s_b, s_a, 
-                                        d_r, d_g, d_b, d_a : Integer;
-					info : PHermesGenericInfo);
-
-Var
-  r_right, g_right, b_right, a_right : Integer;
-
-Begin
-  {Calculate right shift amount for red. If it's <0, then set it to 0
-   and calculate left shift amount}
-  r_right := s_r - d_r;
-  If r_right < 0 Then
-  Begin
-    info^.r_left := -r_right;
-    info^.r_right := 0;
-  End
-  Else
-  Begin
-    info^.r_left := 0;
-    info^.r_right := r_right;
-  End;
-  
-  {Same for green}
-  g_right := s_g - d_g;
-  If g_right < 0 Then
-  Begin
-    info^.g_left := -g_right;
-    info^.g_right := 0;
-  End
-  Else
-  Begin
-    info^.g_left := 0;
-    info^.g_right := g_right;
-  End;
-  
-  {Same for blue}
-  b_right := s_b - d_b;
-  If b_right < 0 Then
-  Begin
-    info^.b_left := -b_right;
-    info^.b_right := 0;
-  End
-  Else
-  Begin
-    info^.b_left := 0;
-    info^.b_right := b_right;
-  End;
-  
-  {Alpha}
-  a_right := s_a - d_a;
-  If a_right < 0 Then
-  Begin
-    info^.a_left := -a_right;
-    info^.a_right := 0;
-  End
-  Else
-  Begin
-    info^.a_left := 0;
-    info^.a_right := a_right;
-  End;
-End;
-
-Function Hermes_Topbit(mask : int32) : Integer;
-
-Var
-  i : Integer;
-
-Begin
-  If mask = 0 Then
-  Begin
-    Hermes_Topbit := 0;
-    Exit;
-  End;
-  i := 0;
-  While (mask And 1) = 0 Do
-  Begin
-    mask := mask Shr 1;
-    Inc(i);
-  End;
-  While (mask And 1) = 1 Do
-  Begin
-    mask := mask Shr 1;
-    Inc(i);
-  End;
-  Hermes_Topbit := i;
-End;

File diff suppressed because it is too large
+ 206 - 685
packages/ptc/Makefile


+ 15 - 8
packages/ptc/Makefile.fpc

@@ -7,24 +7,31 @@ name=ptc
 version=2.4.3
 
 [target]
-units=ptc
-loaders=$(CPU_LOADERS)
-exampledirs=demos examples
+units=ptc ptcwrapper ptceventqueue
+units_win32=p_ddraw
+units_win64=p_ddraw
+exampledirs=examples
 
 [compiler]
-unitdir=src/x11 src/dos/cga src/dos/fakemode src/dos/textfx2 src/dos/timeunit src/dos/vesa \
-        src/win32/directx src
-includedir=src
-targetdir=.
+#unitdir=src/ptcwrapper src/x11
+unitdir_go32v2=src/dos/base src/dos/cga src/dos/vga src/dos/textfx2 src/dos/timeunit src/dos/vesa
+unitdir_win32=src/win32/directx
+unitdir_win64=src/win32/directx
+sourcedir_win32=src/win32/directx
+sourcedir_win64=src/win32/directx
+unitdir_wince=src/wince/gapi
+sourcedir=src src/ptcwrapper
 
 [require]
-packages=hermes
+packages=hermes fcl-base
 packages_linux=x11
 packages_freebsd=x11
 
 [default]
 fpcdir=../..
 
+[install]
+fpcpackage=y
 
 [rules]
 .NOTPARALLEL:

+ 1 - 1
packages/ptc/docs/AUTHORS → packages/ptc/docs/AUTHORS.txt

@@ -3,4 +3,4 @@ The Free Pascal port was done by:
 
 It was based on the OpenPTC C++ library by Glenn Fiedler
 (http://www.gaffer.org/ptc) and the Hermes C library by Christian Nentwich
-(http://hermes.terminal.at)
+(http://www.clanlib.org/hermes/)

+ 0 - 22
packages/ptc/docs/CHANGES

@@ -1,22 +0,0 @@
-0.99.5
- - support for fpc 2.0.0. fpc 1.0.10 support dropped, except for DOS.
- - support for amd64 (the code is now 64-bit safe, but still little endian-only)
- - fix the (sometimes) missing titlebar when using the metacity window manager
-
-0.99.4
- - some X11 fixes (missing cdecl's, wrong alignments, etc.)
- - FreeBSD and NetBSD now compile and work (dga and XShm still not tested...)
- - improved exception handling in demos and examples
-
-0.99.3
- - support for fpc 1.9.2+ (adapted to use the new unix rtl)
- - the dos console uses rdtsc if available for more accurate timing
- - some vesa fixes
-
-0.99.2
- - alt, shift, ctrl modifier keys support for X11
- - key release support for win32 and X11
- - new example (keybrd2) demonstrating the use of key release events
-
-0.99.1
- - first release to sourceforge

+ 107 - 0
packages/ptc/docs/CHANGES.txt

@@ -0,0 +1,107 @@
+0.99.11
+ - added ptcgraph - an implementation of FPC's BGI-compatible graph unit on top
+   of PTCPas. It should work on all platforms, supported by PTCPas,  except for
+   DOS (because it doesn't have threads)
+ - VBE console improvements:
+    - support for double buffering with video page flipping
+    - console update synchronized with the vertical retrace
+    - automatic fallback to windowed mode, if initializing LFB fails. This
+      results in better compatibility with NTVDM and other environments that
+      would otherwise require adding the 'disable lfb' option to ptcpas.cfg.
+    - support VBE 3+ separate LFB and Windowed color masks for direct color
+      modes. This might fix some wrong color bugs in LFB mode on some modern
+      VBE 3+ video cards.
+ - fixed a bug in the X11 event handling that caused unnecessary high CPU use
+   while waiting for an event
+
+0.99.10
+ - fpc 2.4.0 support
+ - Win64 DirectX support
+ - X11 DGA 2.0 support
+ - VBE 2+ LFB support. Enabled by default. Offers a great performance
+   improvement, but may fail on buggy VGA BIOSes or buggy DOS virtual
+   machines. If it causes problems, it can be disabled by adding
+   'disable lfb' to ptcpas.cfg.
+ - API changes:
+    - in the hermes unit, THermesHandle was replaced with
+      THermesConverterHandle, THermesClearerHandle and THermesPaletteHandle,
+      which should be treated as opaque pointers, not integers. This only
+      matters if you use unit hermes directly, and not ptc.
+ - various bugfixes and code cleanup.
+
+0.99.9
+ - big endian support.
+ - Win64 support (GDI only. DirectX not supported yet).
+
+0.99.8
+ - added support for Windows CE. Still in alpha stage. Tested on a Motorola
+   MPx220 smartphone.
+ - added support for fullscreen X11 using the Xrandr extension (previously
+   only the XF86VidMode extension was supported). Also fullscreen X11 now works
+   even when there aren't any mode switching X11 extensions available. A single
+   fullscreen mode, which has the size of the entire desktop is offered in this
+   case.
+ - added a new simple windowed win32 GDI console, which is able to run even
+   without any version of DirectX installed.
+ - the X11 console now returns a mode list.
+ - fixed a bug which caused win32 fixed-size windows to be non-minimizable.
+ - imported the OpenPTC 1.0.1 DOS VGA fakemode assembly routines - should give
+   a nice speed boost on ancient 386/486/Pentium machines.
+
+0.99.7
+ - A new event system + mouse support. Yes, I know I should have done this
+   earlier :) Fullscreen X11 with mouse still does not work well, I'm planning
+   to fix this in the next version.
+ - API changes:
+    - TPTCKey class renamed to TPTCKeyEvent
+    - Removed int32, short16 and char8 types.
+      Replaced with: Uint64, Uint32, Uint16, Uint8,
+                     Sint64, Sint32, Sint16, Sint8.
+ - fixed fullscreen palette modes under DirectX (was buggy on modern NVIDIA and
+   ATI video cards).
+ - a new example program, demonstrating the mouse support.
+   Use it as a reference for now, until I update the documentation with the new
+   event handling stuff (hopefully this will happen in the next release).
+ - X11 window is not resizable anymore. Maybe some day I'll implement (optional)
+   stretching as in win32 windowed mode.
+ - code cleanup. Hid some implementation details from the interface part.
+
+0.99.6
+ - Now distributed under the terms of the modified LGPL (used by the FPC RTL).
+   See the file modified_lgpl.txt distributed with the library for details.
+   Thanks to Glenn Fiedler (the author of the original OpenPTC C++ code, that
+   this library is based on) and Christian Nentwich (the author of the original
+   C code of the Hermes library and the X11 version of OpenPTC) for giving
+   permission to distribute the code under this license.
+ - The Free Pascal Development Team intends to distribute this library with the
+   Free Pascal Compiler and to base the graph unit on it, which is very cool! :)
+ - fullscreen support in xshm/ximage mode.
+ - dga support is now disabled by default.
+ - added workaround for the 'shmat' bug in fpc 2.0.0's rtl on amd64 linux.
+ - fixed some compilation-related problems with the example programs.
+ - fpc 2.0.2 - go32v2 compilation fixed. fpc 1.0.10 support dropped completely.
+ - some other DOS code fixes and cleanups.
+ - config file name changed to ptcpas.cfg (~/.ptcpas.conf on *NIX)
+
+0.99.5
+ - support for fpc 2.0.0. fpc 1.0.10 support dropped, except for DOS.
+ - support for amd64 (the code is now 64-bit safe, but still little endian-only)
+ - fix the (sometimes) missing titlebar when using the metacity window manager
+
+0.99.4
+ - some X11 fixes (missing cdecl's, wrong alignments, etc.)
+ - FreeBSD and NetBSD now compile and work (dga and XShm still not tested...)
+ - improved exception handling in demos and examples
+
+0.99.3
+ - support for fpc 1.9.2+ (adapted to use the new unix rtl)
+ - the dos console uses rdtsc if available for more accurate timing
+ - some vesa fixes
+
+0.99.2
+ - alt, shift, ctrl modifier keys support for X11
+ - key release support for win32 and X11
+ - new example (keybrd2) demonstrating the use of key release events
+
+0.99.1
+ - first release to sourceforge

+ 0 - 36
packages/ptc/docs/INSTALL

@@ -1,36 +0,0 @@
-The supported platforms are Linux (on IA-32 and AMD64), Windows and DOS.
-FreeBSD and NetBSD compiles and runs fine on the SourceForge compilefarm, but
-I haven't tested it on a local machine, so any feedback (+patches) is welcome.
-(At least the basic XImage mode works, XShm and dga are not tested since they
-need to run on the same machine as the X server, so I can't test them on the
-SourceForge compilefarm.)
-
-You need Free Pascal Compiler version 2.0.0. Since there's no DOS version of
-2.0.0, you need 1.0.10 if you are going to use the DOS version of the library.
-Please note that DOS is the only platform where the 1.0.10 compiler is
-supported.
-
- - Compiling the library:
-Before starting make sure the FPCDIR environment variable is set correctly.
-For example: (windows, fpc version 2.0.0, default install dir)
-
-  set FPCDIR=c:\fpc\2.0.0
-
-To compile the library type:
-
-  fpcmake -r
-  make
-
-Then you can do:
-
-  make examples
-
-And then try to run the programs in the demos/ and examples/ dirs.
-
-If compiling the library fails, make sure you're using the GNU make and not
-some other make! (e.g. GNU make is called 'gmake' on FreeBSD and NetBSD)
-
-'make -v' should report:
-  GNU Make version x.xx.x, ... etc. :)
-
-On Windows and DOS this is the 'make' that comes with Free Pascal.

+ 29 - 0
packages/ptc/docs/INSTALL.txt

@@ -0,0 +1,29 @@
+The supported platforms are Linux, FreeBSD, Windows, Windows Mobile and DOS.
+
+Generally you need the latest stable version of the Free Pascal Compiler, which
+currently means version 2.4.0. Generally FPC 2.2.4 should also work fine.
+
+ - Compiling the library:
+Before starting make sure the FPCDIR environment variable is set correctly.
+For example: (windows, fpc version 2.4.0, default install dir)
+
+  set FPCDIR=c:\fpc\2.4.0
+
+To compile the library type:
+
+  fpcmake -r
+  make
+
+Then you can do:
+
+  make examples
+
+And then try to run the programs in the demos/ and examples/ dirs.
+
+If compiling the library fails, make sure you're using the GNU make and not
+some other make! (e.g. GNU make is usually called 'gmake' on *BSD)
+
+'make -v' should report:
+  GNU Make version x.xx.x, ... etc. :)
+
+On Windows and DOS this is the 'make' that comes with Free Pascal.

+ 10 - 10
packages/ptc/docs/INTRO → packages/ptc/docs/INTRO.txt

@@ -1,5 +1,5 @@
-For more complete documentation please refer to the C++ documentation of
-OpenPTC.
+For more complete documentation please see the API reference found in the
+'api-reference' directory (as well as online on the official PTCPas website).
 
 This will explain the basics of creating a simple graphics application using
 PTC for FPC. :)
@@ -38,29 +38,29 @@ How to use this TPTCConsole? Easy! First create it:
 
 This still doesn't do anything, just allocates memory and initializes stuff.
 Then you switch to the desired mode:
-  Console.open('Hello, world!', 320, 200, Format);
+  Console.Open('Hello, world!', 320, 200, Format);
 
 Note that if your hardware doesn't support the requested mode, PTC will try
 to switch to the best mode. If (for example) your card doesn't support
 320x200 in 32bpp, only in 16bpp, PTC will (probably) switch to that mode.
 To see the actual mode that PTC has set use these properties:
-  Console.width Console.height and Console.format
+  Console.Width Console.Height and Console.Format
 
 Ok, now that you have created a TPTCSurface and opened a TPTCConsole, what to
 do next? Draw stuff... The lock function of TPTCSurface will give you a pointer
 to the internal buffer.
-  ptr := Surface.lock;
+  ptr := Surface.Lock;
 
 Now you can draw your frame in the buffer, pointed by ptr. Note that this buffer
 is guaranteed to be in the format and resolution you requested.
 
 When you're done you have to unlock the surface and copy it to the console:
-  Surface.unlock;
-  Surface.copy(Console);
-  Console.update;
+  Surface.Unlock;
+  Surface.Copy(Console);
+  Console.Update;
 
-The Surface.copy(Console) will do the conversion (if necessary) to the actual
-mode. Console.update will actually show the new frame (if the console driver
+The Surface.Copy(Console) will do the conversion (if necessary) to the actual
+mode. Console.Update will actually show the new frame (if the console driver
 supports multiple pages and you have enough video RAM for that, etc... :) ).
 
 See the example programs for additional details. (keyboard input, high

+ 33 - 19
packages/ptc/docs/README.txt

@@ -1,8 +1,9 @@
-PTCPas 0.99.5
+PTCPas 0.99.11
 Nikolay Nikolov ([email protected])
 
-This is a FPC port of the OpenPTC C++ library. It is distributed under the
-the terms of the GNU LGPL (see lgpl.txt).
+PTCPas is a free, portable framebuffer library, written in Free Pascal. It is
+distributed under the the terms of a modified version of the GNU LGPL (see
+modified_lgpl.txt).
 
 The latest version can be found at http://ptcpas.sourceforge.net
 
@@ -12,33 +13,46 @@ Windows, more will be added in the future)
 3d acceleration isn't supported, nor planned. If you need that, you should use
 something like OpenGL instead. :-)
 
+PTCPas initially started out as a complete Object Pascal translation of the
+OpenPTC C++ library. Since then, OpenPTC development has stalled and PTCPas
+lives on as a fully independent Object Pascal project.
+
 Supported consoles:
-  DirectX 3+ (should work on all Windows versions since Windows 95, except
-              Windows CE. This currently means 95/98/ME/NT4/2000/XP/2003.
-	      On NT4 you need SP3 or later. Also some very ancient versions of
-	      Windows 95 do not have any DirectX preinstalled, so it has to be
-	      installed separately.)
-  X11 (on linux, maybe also other unix-like OSes, supports dga and XShm
-       extensions)
-  Vesa 1.2+ (DOS. LFB and video pages not yet supported)
+  DirectX 3+ (should work on all x86 Windows versions since Windows 95, except
+              Windows CE. This currently means 95/98/ME/NT4/2000/XP/2003/Vista.
+              It is compatible with the x64 editions of XP and 2003 (although
+              only as a 32-bit application, no native win64 yet). On NT4 you
+              need SP3 or later. Also some very ancient versions of Windows 95
+              do not have any DirectX preinstalled, so it has to be installed
+              separately.)
+  Win32 GDI (no fullscreen support. Slower than DirectX, but maybe more
+             compatible.)
+  X11 (on linux and other unix-like OSes, supports XRandR, XF86VidMode, XShm
+       and xf86dga extensions)
+  Vesa 1.0+ (DOS. Supports LFB and banked video memory access. Video pages not
+             yet supported)
   VGA (DOS, fakemodes, mode13h, etc...)
   CGA (DOS, added by me just for fun ... and maybe some day I'll even add
        EGA :-) )
   Text (DOS, 80x50 - 16 colours, should work even in the most buggy dos boxes
         (2000,XP) and IMHO looks better than AALib ;-) )
+  WinCE GAPI (Windows CE 3.0 and later on devices that support GAPI. Needs
+              testing on more devices.)
+  WinCE GDI (Windows CE 3.0 and later. Slow. Needs testing on more devices.)
 
-All programs using OpenPTC look (at runtime) for a config file that may contain
+All programs using PTCPas look (at runtime) for a config file that may contain
 various (platform specific) options, so you can try different consoles, etc,
-without the need to recompile. It is called ptc.cfg and is searched in the
-current directory on DOS and Windows. On unix it is .ptc.conf in the user's
-HOME directory. There's an example ptc.cfg file with all supported options,
+without the need to recompile. It is called ptcpas.cfg and is searched in the
+current directory on DOS and Windows. On unix it is .ptcpas.conf in the user's
+HOME directory. There's an example ptcpas.cfg file with all supported options,
 prefixed with #. If you want to try an option just remove the # and put it in
-the same directory as the .exe (or copy to ~/.ptc.conf on unix :) )
+the same directory as the .exe (or copy to ~/.ptcpas.conf on unix :) )
 
 --------------------------------------------------------------------------------
 The original copyrights from the C++ version:
-The X11 classes are Copyright (c) 1998/99 Christian Nentwich ([email protected])
+The X11 classes are Copyright (c) 1998/99 Christian Nentwich
+([email protected], old mail [email protected] no longer works?)
 The OpenPTC 1.0 C++ API is (c) 1998/99 Glenn Fiedler ([email protected])
 
-The OpenPTC C++ library can be found at http://www.gaffer.org/ptc
-The Hermes C library can be found at http://hermes.terminal.at
+The OpenPTC C++ library can be found at http://sourceforge.net/projects/openptc/
+The Hermes C library can be found at http://www.clanlib.org/download/legacy/

+ 7 - 6
packages/ptc/docs/TODO.txt

@@ -1,8 +1,9 @@
+ - mouse grab support
+ - add more event types (expose, focus in, focus out, etc.)
+ - mouse support for the x11 dga console
  - key release events support in dos
- - mouse support
- - multiple video pages and lfb for the vesa console
- - test the x11 console (in XShm and dga mode) under *BSD
- - big endian support in hermes
- - make hermes thread safe (in FPC 1.9.x+)
- - delphi (kylix? c++?) bindings
+ - multiple video pages support for the x11 w/dga console
+ - cross-platform opengl initialization support (like sdl or glut)
+ - make hermes thread safe
  - better timing under dos
+ - delphi (kylix? c++?) bindings

+ 25 - 0
packages/ptc/docs/modified_lgpl.txt

@@ -0,0 +1,25 @@
+This is the file modified_lgpl.txt, it applies to the ptcpas library (the Free
+Pascal port of the OpenPTC C++ library) and to the Free Pascal port of the
+Hermes library.
+
+The source code of the ptcpas library and the Free Pascal port of the Hermes
+library are distributed under the Lesser GNU General Public License
+(see the file lgpl.txt) with the following modification:
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent modules,
+and to copy and distribute the resulting executable under terms of your choice,
+provided that you also meet, for each linked independent module, the terms
+and conditions of the license of that module. An independent module is a module
+which is not derived from or based on this library. If you modify this
+library, you may extend this exception to your version of the library, but you are
+not obligated to do so. If you do not wish to do so, delete this exception
+statement from your version.
+
+If you didn't receive a copy of the file lgpl.txt, contact:
+      Free Software Foundation
+      675 Mass Ave
+      Cambridge, MA  02139
+      USA
+

+ 40 - 45
packages/ptc/examples/area.pp

@@ -3,35 +3,30 @@ Ported to FPC by Nikolay Nikolov ([email protected])
 }
 
 {
- Area example for OpenPTC 1.0 C++ Implementation
+ Area example for OpenPTC 1.0 C++ implementation
  Copyright (c) Glenn Fiedler ([email protected])
  This source code is in the public domain
 }
 
-Program AreaExample;
+program AreaExample;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc;
 
-Var
-  console : TPTCConsole;
-  format : TPTCFormat;
-  surface : TPTCSurface;
-  pixels : PDWord;
-  width, height : Integer;
-  i : Integer;
-  x, y, r, g, b : Integer;
-  area : TPTCArea;
-
-Begin
-  area := Nil;
-  format := Nil;
-  surface := Nil;
-  console := Nil;
-  Try
-    Try
+var
+  console: TPTCConsole = nil;
+  format: TPTCFormat = nil;
+  surface: TPTCSurface = nil;
+  pixels: PDWord;
+  width, height: Integer;
+  i: Integer;
+  x, y, r, g, b: Integer;
+  area: TPTCArea = nil;
+begin
+  try
+    try
       { create console }
       console := TPTCConsole.Create;
 
@@ -42,59 +37,59 @@ Begin
       console.open('Area example', format);
 
       { create surface half the size of the console }
-      surface := TPTCSurface.Create(console.width Div 2, console.height Div 2, format);
-      
+      surface := TPTCSurface.Create(console.width div 2, console.height div 2, format);
+
       { setup destination area }
-      x := console.width Div 4;
-      y := console.height Div 4;
+      x := console.width div 4;
+      y := console.height div 4;
       area := TPTCArea.Create(x, y, x + surface.width, y + surface.height);
 
       { loop until a key is pressed }
-      While Not console.KeyPressed Do
-      Begin
+      while not console.KeyPressed do
+      begin
         { lock surface }
         pixels := surface.lock;
-        Try
+        try
           { get surface dimensions }
           width := surface.width;
           height := surface.height;
 
           { draw random pixels }
-          For i := 1 To 100 Do
-          Begin
+          for i := 1 to 100 do
+          begin
             { get random position }
-	    x := Random(width);
-	    y := Random(height);
+            x := Random(width);
+            y := Random(height);
 
             { get random color }
-	    r := Random(256);
-	    g := Random(256);
-	    b := Random(256);
+            r := Random(256);
+            g := Random(256);
+            b := Random(256);
 
             { draw color [r,g,b] at position [x,y] }
-	    pixels[x + y * width] := (r Shl 16) + (g Shl 8) + b;
-          End;
-	Finally
+            pixels[x + y * width] := (r shl 16) + (g shl 8) + b;
+          end;
+        finally
           { unlock surface }
           surface.unlock;
-	End;
+        end;
 
         { copy surface to console destination area }
         surface.copy(console, surface.area, area);
 
         { update console area }
         console.update;
-      End;
-    Finally
+      end;
+    finally
       console.close;
       console.Free;
       surface.Free;
       format.Free;
       area.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 36 - 41
packages/ptc/examples/buffer.pp

@@ -3,34 +3,29 @@ Ported to FPC by Nikolay Nikolov ([email protected])
 }
 
 {
- Buffer example for OpenPTC 1.0 C++ Implementation
+ Buffer example for OpenPTC 1.0 C++ implementation
  Copyright (c) Glenn Fiedler ([email protected])
  This source code is in the public domain
 }
 
-Program BufferExample;
+program BufferExample;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc;
 
-Var
-  console : TPTCConsole;
-  format : TPTCFormat;
-  palette : TPTCPalette;
-  width, height : Integer;
-  pixels : Pint32;
-  x, y, r, g, b : Integer;
-  i : Integer;
-
-Begin
-  pixels := Nil;
-  format := Nil;
-  palette := Nil;
-  console := Nil;
-  Try
-    Try
+var
+  console: TPTCConsole = nil;
+  format: TPTCFormat = nil;
+  palette: TPTCPalette = nil;
+  width, height: Integer;
+  pixels: PUint32 = nil;
+  x, y, r, g, b: Integer;
+  i: Integer;
+begin
+  try
+    try
       { create console }
       console := TPTCConsole.Create;
 
@@ -45,46 +40,46 @@ Begin
       height := console.height;
 
       { allocate a buffer of pixels }
-      pixels := GetMem(width * height * SizeOf(int32));
+      pixels := GetMem(width * height * SizeOf(Uint32));
+      FillChar(pixels^, width * height * SizeOf(Uint32), 0);
       palette := TPTCPalette.Create;
 
       { loop until a key is pressed }
-      While Not console.KeyPressed Do
-      Begin
+      while not console.KeyPressed do
+      begin
         { draw random pixels }
-        For i := 1 To 100 Do
-        Begin
+        for i := 1 to 100 do
+        begin
           { get random position }
-	  x := Random(width);
-	  y := Random(height);
+          x := Random(width);
+          y := Random(height);
 
-          { get random color }	
-	  r := Random(256);
-	  g := Random(256);
-	  b := Random(256);
+          { get random color }
+          r := Random(256);
+          g := Random(256);
+          b := Random(256);
 
           { draw color [r,g,b] at position [x,y] }
-	  pixels[x + y * width] := (r Shl 16) Or (g Shl 8) Or b;
-        End;
+          pixels[x + y * width] := (r shl 16) or (g shl 8) or b;
+        end;
 
         { load pixels to console }
         console.load(pixels, width, height, width * 4, format, palette);
 
         { update console }
         console.update;
-      End;
-    Finally
+      end;
+    finally
       { free pixels buffer }
-      If Assigned(pixels) Then
-        FreeMem(pixels);
+      FreeMem(pixels);
       console.close;
       palette.Free;
       format.Free;
       console.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 40 - 37
packages/ptc/examples/clear.pp

@@ -3,30 +3,29 @@ Ported to FPC by Nikolay Nikolov ([email protected])
 }
 
 {
- Clear example for OpenPTC 1.0 C++ Implementation
+ Clear example for OpenPTC 1.0 C++ implementation
  Copyright (c) Glenn Fiedler ([email protected])
  This source code is in the public domain
 }
 
-Program ClearExample;
+program ClearExample;
 
 {$MODE objfpc}
 
-Uses
-  ptc;
-
-Var
-  console : TPTCConsole;
-  format : TPTCFormat;
-  surface : TPTCSurface;
-  width, height : Integer;
-  x, y : Integer;
-  size : Integer;
-  area : TPTCArea;
-  color : TPTCColor;
-
-Begin
-  Try
+uses
+  SysUtils, ptc;
+
+var
+  console: TPTCConsole = nil;
+  format: TPTCFormat = nil;
+  surface: TPTCSurface = nil;
+  width, height: Integer;
+  x, y: Integer;
+  size: Integer;
+  area: TPTCArea = nil;
+  color: TPTCColor = nil;
+begin
+  try
     { create console }
     console := TPTCConsole.Create;
 
@@ -40,8 +39,8 @@ Begin
     surface := TPTCSurface.Create(console.width, console.height, format);
 
     { loop until a key is pressed }
-    While Not console.KeyPressed Do
-    Begin
+    while not console.KeyPressed do
+    begin
       { get surface dimensions }
       width := surface.width;
       height := surface.height;
@@ -51,31 +50,35 @@ Begin
       y := Random(height);
 
       { get random area size }
-      size := Random(width Div 8);
+      size := Random(width div 8);
 
-      { setup clear area }
-      area := TPTCArea.Create(x-size, y-size, x+size, y+size);
+      try
+        { setup clear area }
+        area := TPTCArea.Create(x-size, y-size, x+size, y+size);
 
-      { create random color }
-      color := TPTCColor.Create(Random, Random, Random);
+        { create random color }
+        color := TPTCColor.Create(Random, Random, Random);
 
-      { clear surface area with color }
-      surface.clear(color, area);
+        { clear surface area with color }
+        surface.clear(color, area);
 
-      { copy to console }
-      surface.copy(console);
+        { copy to console }
+        surface.copy(console);
 
-      { update console }
-      console.update;
-      area.Free;
-      color.Free;
-    End;
+        { update console }
+        console.update;
+      finally
+        FreeAndNil(area);
+        FreeAndNil(color);
+      end;
+    end;
     console.close;
     console.Free;
     surface.Free;
-  Except
-    On error : TPTCError Do
+    format.Free;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 42 - 46
packages/ptc/examples/clip.pp

@@ -3,35 +3,31 @@ Ported to FPC by Nikolay Nikolov ([email protected])
 }
 
 {
- Clip example for OpenPTC 1.0 C++ Implementation
+ Clip example for OpenPTC 1.0 C++ implementation
  Copyright (c) Glenn Fiedler ([email protected])
  This source code is in the public domain
 }
 
-Program ClipExample;
+program ClipExample;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc;
 
-Var
-  console : TPTCConsole;
-  surface : TPTCSurface;
-  format : TPTCFormat;
-  area : TPTCArea;
-  x1, y1, x2, y2 : Integer;
-  pixels : Pint32;
-  width, height : Integer;
-  i : Integer;
-  x, y, r, g, b : Integer;
-
-Begin
-  format := Nil;
-  surface := Nil;
-  console := Nil;
-  Try
-    Try
+var
+  console: TPTCConsole = nil;
+  surface: TPTCSurface = nil;
+  format: TPTCFormat = nil;
+  area: TPTCArea;
+  x1, y1, x2, y2: Integer;
+  pixels: PUint32;
+  width, height: Integer;
+  i: Integer;
+  x, y, r, g, b: Integer;
+begin
+  try
+    try
       { create console }
       console := TPTCConsole.Create;
 
@@ -45,65 +41,65 @@ Begin
       surface := TPTCSurface.Create(console.width, console.height, format);
 
       { calculate clip coordinates }
-      x1 := console.width Div 4;
-      y1 := console.height Div 4;
+      x1 := console.width div 4;
+      y1 := console.height div 4;
       x2 := console.width - x1;
       y2 := console.height - y1;
 
       { setup clip area }
       area := TPTCArea.Create(x1, y1, x2, y2);
-      Try
+      try
         { set clip area }
         console.clip(area);
-      Finally
+      finally
         area.Free;
-      End;
+      end;
 
       { loop until a key is pressed }
-      While Not console.KeyPressed Do
-      Begin
+      while not console.KeyPressed do
+      begin
         { lock surface }
         pixels := surface.lock;
-        Try
+        try
           { get surface dimensions }
           width := surface.width;
           height := surface.height;
 
           { draw random pixels }
-          For i := 1 To 100 Do
-          Begin
+          for i := 1 to 100 do
+          begin
             { get random position }
-	    x := Random(width);
-	    y := Random(height);
+            x := Random(width);
+            y := Random(height);
 
             { get random color }
-	    r := Random(256);
-	    g := Random(256);
-	    b := Random(256);
+            r := Random(256);
+            g := Random(256);
+            b := Random(256);
 
             { draw color [r,g,b] at position [x,y] }
-	    pixels[x + y * width] := (r Shl 16) + (g Shl 8) + b;
-          End;
-	Finally
+            pixels[x + y * width] := (r shl 16) + (g shl 8) + b;
+          end;
+        finally
           { unlock surface }
           surface.unlock;
-	End;
+        end;
 
         { copy to console }
         surface.copy(console);
 
         { update console }
         console.update;
-      End;
-    Finally
+      end;
+    finally
       console.close;
       console.Free;
       surface.Free;
       format.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 24 - 27
packages/ptc/examples/con_info.pp

@@ -3,45 +3,42 @@ Ported to FPC by Nikolay Nikolov ([email protected])
 }
 
 {
- Info example for OpenPTC 1.0 C++ Implementation
+ Info example for OpenPTC 1.0 C++ implementation
  Copyright (c) Glenn Fiedler ([email protected])
  This source code is in the public domain
 }
 
-Program InfoExample;
+program InfoExample;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc;
 
-Procedure print(Const format : TPTCFormat);
-
-Begin
+procedure print(const format: TPTCFormat);
+begin
   { check format type }
-  If format.direct Then
+  if format.direct then
     { check alpha }
-    If format.a = 0 Then
+    if format.a = 0 then
       { direct color format without alpha }
       Write('Format(', format.bits:2, ',$', HexStr(format.r, 8), ',$', HexStr(format.g, 8), ',$', HexStr(format.b, 8), ')')
-    Else
+    else
       { direct color format with alpha }
       Write('Format(', format.bits:2, ',$', HexStr(format.r, 8), ',$', HexStr(format.g, 8), ',$', HexStr(format.b, 8), ',$', HexStr(format.a, 8), ')')
-  Else
+  else
     { indexed color format }
     Write('Format(', format.bits:2, ')');
-End;
-
-Var
-  console : TPTCConsole;
+end;
 
-Begin
-  console := Nil;
-  Try
-    Try
-      Writeln('[ptc version]');
-      { print ptc version string define }
-      Writeln(PTC_VERSION);
+var
+  console: TPTCConsole = nil;
+begin
+  try
+    try
+      Writeln('[ptcpas version]');
+      { print ptcpas version string define }
+      Writeln(PTCPAS_VERSION);
       Writeln;
 
       { create console }
@@ -66,13 +63,13 @@ Begin
       { print console information }
       Writeln('[console information]');
       Writeln(console.information);
-    Finally
+    finally
       console.close;
       console.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 107 - 103
packages/ptc/examples/console.pp

@@ -3,117 +3,121 @@ Ported to FPC by Nikolay Nikolov ([email protected])
 }
 
 {
- Console example for OpenPTC 1.0 C++ Implementation
+ Console example for OpenPTC 1.0 C++ implementation
  Copyright (c) Glenn Fiedler ([email protected])
  This source code is in the public domain
 }
 
-Program ConsoleExample;
+program ConsoleExample;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc;
 
-Var
-  console : TPTCConsole;
-  palette : TPTCPalette;
-  data : Array[0..255] Of DWord;
-  i : Integer;
-  pixels : PByte;
-  width, height, pitch : Integer;
-  format : TPTCFormat;
-  bits, bytes : Integer;
-  x, y : Integer;
-  color : DWord;
-  pixel : PByte;
-  _data : PByte;
-
-Begin
-  Try
-    { create console }
-    console := TPTCConsole.Create;
-
-    { open the console with one page }
-    console.open('Console example', 1);
-
-    { create palette }
-    palette := TPTCPalette.Create;
-
-    { generate palette }
-    For i := 0 To 255 Do
-      data[i] := i;
-
-    { load palette data }
-    palette.load(data);
-
-    { set console palette }
-    console.palette(palette);
-
-    { loop until a key is pressed }
-    While Not console.KeyPressed Do
-    Begin
-      { lock console }
-      pixels := console.lock;
-
-      { get console dimensions }
-      width := console.width;
-      height := console.height;
-      pitch := console.pitch;
-
-      { get console format }
-      format := console.format;
-
-      { get format information }
-      bits := format.bits;
-      bytes := format.bytes;
-
-      { draw random pixels }
-      For i := 1 To 100 Do
-      Begin
-        { get random position }
-	x := Random(width);
-	y := Random(height);
-
-        { generate random color integer }
-	color := (Random(256) Shl 0) Or
-		 (Random(256) Shl 8) Or
-		 (Random(256) Shl 16) Or
-		 (Random(256) Shl 24);
-
-        { calculate pointer to pixel [x,y] }
-	pixel := pixels + y * pitch + x * bytes;
-
-        { check bits }
-	Case bits Of
-               { 32 bits per pixel }
-	  32 : PDWord(pixel)^ := color;
-	  24 : Begin
-            { 24 bits per pixel }
-	    _data := pixel;
-	    _data[0] := (color And $000000FF) Shr 0;
-	    _data[1] := (color And $0000FF00) Shr 8;
-	    _data[2] := (color And $00FF0000) Shr 16;
-	  End;
-               { 16 bits per pixel }
-	  16 : PWord(pixel)^ := color;
-              { 8 bits per pixel }
-	  8 : PByte(pixel)^ := color;
-	End;
-      End;
-
-      { unlock console }
-      console.unlock;
-
-      { update console }
-      console.update;
-    End;
-    palette.Free;
-    console.close;
-    console.Free;
-  Except
-    On error : TPTCError Do
+var
+  console: TPTCConsole = nil;
+  palette: TPTCPalette = nil;
+  data: array [0..255] of DWord;
+  i: Integer;
+  pixels: PByte;
+  width, height, pitch: Integer;
+  format: TPTCFormat;
+  bits, bytes: Integer;
+  x, y: Integer;
+  color: DWord;
+  pixel: PByte;
+  _data: PByte;
+begin
+  try
+    try
+      { create console }
+      console := TPTCConsole.Create;
+
+      { open the console with one page }
+      console.open('Console example', 1);
+
+      { create palette }
+      palette := TPTCPalette.Create;
+
+      { generate palette }
+      for i := 0 to 255 do
+        data[i] := i;
+
+      { load palette data }
+      palette.load(data);
+
+      { set console palette }
+      console.palette(palette);
+
+      { loop until a key is pressed }
+      while not console.KeyPressed do
+      begin
+        { lock console }
+        pixels := console.lock;
+
+        try
+          { get console dimensions }
+          width := console.width;
+          height := console.height;
+          pitch := console.pitch;
+
+          { get console format }
+          format := console.format;
+
+          { get format information }
+          bits := format.bits;
+          bytes := format.bytes;
+
+          { draw random pixels }
+          for i := 1 to 100 do
+          begin
+            { get random position }
+            x := Random(width);
+            y := Random(height);
+
+            { generate random color integer }
+            color := (DWord(Random(256)) shl 0) or
+                     (DWord(Random(256)) shl 8) or
+                     (DWord(Random(256)) shl 16) or
+                     (DWord(Random(256)) shl 24);
+
+            { calculate pointer to pixel [x,y] }
+            pixel := pixels + y * pitch + x * bytes;
+
+            { check bits }
+            case bits of
+                   { 32 bits per pixel }
+              32: PDWord(pixel)^ := color;
+              24: begin
+                { 24 bits per pixel }
+                _data := pixel;
+                _data[0] := (color and $000000FF) shr 0;
+                _data[1] := (color and $0000FF00) shr 8;
+                _data[2] := (color and $00FF0000) shr 16;
+              end;
+                   { 16 bits per pixel }
+              16: PWord(pixel)^ := color;
+                  { 8 bits per pixel }
+              8: PByte(pixel)^ := color;
+            end;
+          end;
+        finally
+          { unlock console }
+          console.unlock;
+        end;
+
+        { update console }
+        console.update;
+      end;
+    finally
+      palette.Free;
+      console.close;
+      console.Free;
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 88 - 97
packages/ptc/examples/fire.pp

@@ -8,95 +8,86 @@ Ported to FPC by Nikolay Nikolov ([email protected])
  This source code is licensed under the GNU GPL
 }
 
-Program Fire;
+program Fire;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc;
 
-Function pack(r, g, b : Uint32) : Uint32;
-
-Begin
+function pack(r, g, b: Uint32): Uint32;
+begin
   { pack color integer }
-  pack := (r Shl 16) Or (g Shl 8) Or b;
-End;
-
-Procedure generate(palette : TPTCPalette);
-
-Var
-  data : PUint32;
-  i, c : Integer;
-
-Begin
+  pack := (r shl 16) or (g shl 8) or b;
+end;
+
+procedure generate(palette: TPTCPalette);
+var
+  data: PUint32;
+  i, c: Integer;
+begin
   { lock palette data }
   data := palette.lock;
 
-  Try
+  try
     { black to red }
     i := 0;
     c := 0;
-    While i < 64 Do
-    Begin
+    while i < 64 do
+    begin
       data[i] := pack(c, 0, 0);
       Inc(c, 4);
       Inc(i);
-    End;
+    end;
 
     { red to yellow }
     c := 0;
-    While i < 128 Do
-    Begin
+    while i < 128 do
+    begin
       data[i] := pack(255, c, 0);
       Inc(c, 4);
       Inc(i);
-    End;
+    end;
 
     { yellow to white }
     c := 0;
-    While i < {192}128 Do
-    Begin
+    while i < {192}128 do
+    begin
       data[i] := pack(255, 255, c);
       Inc(c, 4);
       Inc(i);
-    End;
+    end;
 
     { white }
-    While i < 256 Do
-    Begin
+    while i < 256 do
+    begin
       data[i] := pack(255, 255, 255);
       Inc(i);
-    End;
+    end;
 
-  Finally
+  finally
     { unlock palette }
     palette.unlock;
-  End;
-End;
-
-Var
-  format : TPTCFormat;
-  console : TPTCConsole;
-  surface : TPTCSurface;
-  palette : TPTCPalette;
-  state : Integer;
-  intensity : Single;
-  pixels, pixel, p : PUint8;
-  width, height : Integer;
-  x, y : Integer;
-  top, bottom, c1, c2 : Uint32;
-  generator : PUint8;
-  color : Integer;
-  area : TPTCArea;
-
-Begin
-  format := Nil;
-  console := Nil;
-  surface := Nil;
-  palette := Nil;
-  area := Nil;
-  Try
-    Try
+  end;
+end;
+
+var
+  format: TPTCFormat = nil;
+  console: TPTCConsole = nil;
+  surface: TPTCSurface = nil;
+  palette: TPTCPalette = nil;
+  state: Integer;
+  intensity: Single;
+  pixels, pixel, p: PUint8;
+  width, height: Integer;
+  x, y: Integer;
+  top, bottom, c1, c2: Uint32;
+  generator: PUint8;
+  color: Integer;
+  area: TPTCArea = nil;
+begin
+  try
+    try
       { create format }
       format := TPTCFormat.Create(8);
 
@@ -129,71 +120,71 @@ Begin
       area := TPTCArea.Create(0, 0, 320, 200);
 
       { main loop }
-      Repeat
+      repeat
         { lower flame on keypress }
-        If console.KeyPressed Then
+        if console.KeyPressed then
           state := 2;
 
         { state machine }
-        Case state Of
-          0 : Begin
+        case state of
+          0: begin
             { raise flame }
-            intensity += 0.007;
+            intensity := intensity + 0.007;
 
             { maximum flame height }
-            If intensity > 0.8 Then
+            if intensity > 0.8 then
               state := 1;
-          End;
-          1 : Begin
+          end;
+          1: begin
             { constant flame }
-          End;
-          2 : Begin
+          end;
+          2: begin
             { lower flame }
             intensity := intensity - 0.005;
 
             { exit program when flame is out }
-            If intensity < 0.01 Then
-            Begin
+            if intensity < 0.01 then
+            begin
               console.close;
-	      Exit;
-            End;
-          End;
-        End;
+              exit;
+            end;
+          end;
+        end;
 
         { lock surface pixels }
         pixels := surface.lock;
-	
-	Try
+
+        try
           { get surface dimensions }
           width := surface.width;
           height := surface.height;
 
           { flame vertical loop }
           y := 1;
-          While y < height - 4 Do
-          Begin
+          while y < height - 4 do
+          begin
             { current pixel pointer }
             pixel := pixels + y * width;
 
             { flame horizontal loop }
-            For x := 0 To width - 1 Do
-            Begin
+            for x := 0 to width - 1 do
+            begin
               { sum top pixels }
-              p := pixel + (width Shl 1);
+              p := pixel + (width shl 1);
               top := p^;
               Inc(top, (p - 1)^);
               Inc(top, (p + 1)^);
 
               { bottom pixel }
-              bottom := (pixel + (width Shl 2))^;
+              bottom := (pixel + (width shl 2))^;
 
               { combine pixels }
-              c1 := (top + bottom) Shr 2;
-              If c1 > 1 Then
+              c1 := (top + bottom) shr 2;
+              if c1 > 1 then
                 Dec(c1);
 
               { interpolate }
-              c2 := (c1 + bottom) Shr 1;
+              c2 := (c1 + bottom) shr 1;
 
               { store pixels }
               pixel^ := c1;
@@ -201,17 +192,17 @@ Begin
 
               { next pixel }
               Inc(pixel);
-            End;
+            end;
             Inc(y, 2);
-          End;
+          end;
 
           { setup flame generator pointer }
           generator := pixels + width * (height - 4);
 
           { update flame generator bar }
           x := 0;
-          While x < width Do
-          Begin
+          while x < width do
+          begin
             { random block color taking intensity into account }
             color := random(Integer(Trunc(255 * intensity)));
 
@@ -236,30 +227,30 @@ Begin
             { next block }
             Inc(generator, 4);
             Inc(x, 4);
-          End;
+          end;
 
-        Finally
+        finally
           { unlock surface }
           surface.unlock;
-	End;
+        end;
 
         { copy surface to console }
         surface.copy(console, area, area);
 
         { update console }
         console.update;
-      Until False;
-      
-    Finally
+      until False;
+
+    finally
       console.Free;
       surface.Free;
       format.Free;
       palette.Free;
       area.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 85 - 97
packages/ptc/examples/flower.pp

@@ -8,133 +8,121 @@ Ported to FPC by Nikolay Nikolov ([email protected])
  This source code is licensed under the GNU GPL
 }
 
-Program Flower;
+program Flower;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc, Math;
 
-Function pack(r, g, b : Uint32) : Uint32;
-
-Begin
+function pack(r, g, b: Uint32): Uint32;
+begin
   { pack color integer }
-  pack := (r Shl 16) Or (g Shl 8) Or b;
-End;
-
-Procedure generate_flower(flower : TPTCSurface);
-
-Var
-  data : PUint8;
-  x, y, fx, fy, fx2, fy2 : Integer;
-  TWO_PI : Single;
-
-Begin
+  pack := (r shl 16) or (g shl 8) or b;
+end;
+
+procedure generate_flower(flower: TPTCSurface);
+var
+  data: PUint8;
+  x, y, fx, fy, fx2, fy2: Integer;
+  TWO_PI: Single;
+begin
   { lock surface }
   data := flower.lock;
-  
-  Try
+
+  try
     { surface width and height constants for cleaner code }
     fx := flower.width;
     fy := flower.height;
-    fx2 := fx Div 2;
-    fy2 := fy Div 2;
+    fx2 := fx div 2;
+    fy2 := fy div 2;
 
     { useful 2*pi constant }
     TWO_PI := 2 * PI;
 
     { generate flower image }
-    For y := 0 To fy - 1 Do
-      For x := 0 To fx - 1 Do
+    for y := 0 to fy - 1 do
+      for x := 0 to fx - 1 do
         data[x + y * fx] := Trunc(1.0 * Cos(18*ArcTan2((y - fy2),(x - fx2))) * 255 / TWO_PI +
-		                  0.3 * Sin(15*ArcTan2((y - fy2),(x - fx2))) * 255 / TWO_PI +
-                                  Sqrt((y - fy2) * (y - fy2) + (x - fx2) * (x - fx2))) And $FF;
+                                  0.3 * Sin(15*ArcTan2((y - fy2),(x - fx2))) * 255 / TWO_PI +
+                                  Sqrt((y - fy2) * (y - fy2) + (x - fx2) * (x - fx2))) and $FF;
 
     { You might want to move the 1.0 and 0.3 and the 18 and the 15
       to parameters passed to the generate function...
       the 1.0 and the 0.3 define the 'height' of the flower, while the
       18 and 15 control the number of 'petals' }
-  Finally
+  finally
     flower.unlock;
-  End;
-End;
-
-Procedure generate(palette : TPTCPalette);
-
-Var
-  data : PUint32;
-  i, c : Integer;
-
-Begin
+  end;
+end;
+
+procedure generate(palette: TPTCPalette);
+var
+  data: PUint32;
+  i, c: Integer;
+begin
   { lock palette data }
   data := palette.lock;
-  
-  Try
+
+  try
     { black to yellow }
     i := 0;
     c := 0;
-    While i < 64 Do
-    Begin
+    while i < 64 do
+    begin
       data[i] := pack(c, c, 0);
       Inc(c, 4);
       Inc(i);
-    End;
+    end;
 
     { yellow to red }
     c := 0;
-    While i < 128 Do
-    Begin
+    while i < 128 do
+    begin
       data[i] := pack(255, 255 - c, 0);
       Inc(c, 4);
       Inc(i);
-    End;
+    end;
 
     { red to white }
     c := 0;
-    While i < 192 Do
-    Begin
+    while i < 192 do
+    begin
       data[i] := pack(255, c, c);
       Inc(c, 4);
       Inc(i);
-    End;
+    end;
 
     { white to black }
     c := 0;
-    While i < 256 Do
-    Begin
+    while i < 256 do
+    begin
       data[i] := pack(255 - c, 255 - c, 255 - c);
       Inc(c, 4);
       Inc(i);
-    End;
-  Finally
+    end;
+  finally
     { unlock palette }
     palette.unlock;
-  End;
-End;
-
-Var
-  console : TPTCConsole;
-  format : TPTCFormat;
-  flower_surface : TPTCSurface;
-  surface : TPTCSurface;
-  palette : TPTCPalette;
-  area : TPTCArea;
-  time, delta : Single;
-  scr, map : PUint8;
-  width, height, mapWidth : Integer;
-  xo, yo, xo2, yo2, xo3, yo3 : Single;
-  offset1, offset2, offset3 : Integer;
-  x, y : Integer;
-
-Begin
-  area := Nil;
-  format := Nil;
-  palette := Nil;
-  surface := Nil;
-  flower_surface := Nil;
-  console := Nil;
-  Try
-    Try
+  end;
+end;
+
+var
+  console: TPTCConsole = nil;
+  format: TPTCFormat = nil;
+  flower_surface: TPTCSurface = nil;
+  surface: TPTCSurface = nil;
+  palette: TPTCPalette = nil;
+  area: TPTCArea = nil;
+  time, delta: Single;
+  scr, map: PUint8;
+  width, height, mapWidth: Integer;
+  xo, yo, xo2, yo2, xo3, yo3: Single;
+  offset1, offset2, offset3: Integer;
+  x, y: Integer;
+begin
+  try
+    try
       { create format }
       format := TPTCFormat.Create(8);
 
@@ -173,13 +161,13 @@ Begin
       delta := 0.04;
 
       { main loop }
-      While Not console.KeyPressed Do
-      Begin
+      while not console.KeyPressed do
+      begin
         { lock surface pixels }
         scr := surface.lock;
-	Try
+        try
           map := flower_surface.lock;
-	  Try
+          try
             { get surface dimensions }
             width := surface.width;
             height := surface.height;
@@ -198,20 +186,20 @@ Begin
             offset3 := Trunc(xo3) + Trunc(yo3) * mapWidth;
 
             { vertical loop }
-            For y := 0 To height - 1 Do
+            for y := 0 to height - 1 do
               { horizontal loop }
-	      For x := 0 To width - 1 Do
-	        scr[x + y * width] := (map[x + y * mapWidth + offset1] +
-				       map[x + y * mapWidth + offset2] +
-				       map[x + y * mapWidth + offset3]) And $FF;
-	  Finally
+              for x := 0 to width - 1 do
+                scr[x + y * width] := (map[x + y * mapWidth + offset1] +
+                                       map[x + y * mapWidth + offset2] +
+                                       map[x + y * mapWidth + offset3]) and $FF;
+          finally
             { unlock surface }
             flower_surface.unlock;
-	  End;
-	Finally
+          end;
+        finally
           { unlock surface }
           surface.unlock;
-	End;
+        end;
 
         { copy surface to console }
         surface.copy(console, area, area);
@@ -221,9 +209,9 @@ Begin
 
         { update time }
         time := time + delta;
-      End;
-    Finally
-      If Assigned(console) Then
+      end;
+    finally
+      if Assigned(console) then
         console.close;
       area.Free;
       format.Free;
@@ -231,10 +219,10 @@ Begin
       surface.Free;
       flower_surface.Free;
       console.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 37 - 41
packages/ptc/examples/hicolor.pp

@@ -3,33 +3,29 @@ Ported to FPC by Nikolay Nikolov ([email protected])
 }
 
 {
- HiColor example for OpenPTC 1.0 C++ Implementation
+ HiColor example for OpenPTC 1.0 C++ implementation
  Copyright (c) Glenn Fiedler ([email protected])
  This source code is in the public domain
 }
 
-Program HiColorExample;
+program HiColorExample;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc;
 
-Var
-  console : TPTCConsole;
-  surface : TPTCSurface;
-  format : TPTCFormat;
-  pixels : Pshort16;
-  width, height : Integer;
-  i : Integer;
-  x, y, r, g, b : Integer;
-
-Begin
-  format := Nil;
-  surface := Nil;
-  console := Nil;
-  Try
-    Try
+var
+  console: TPTCConsole = nil;
+  surface: TPTCSurface = nil;
+  format: TPTCFormat = nil;
+  pixels: PUint16;
+  width, height: Integer;
+  i: Integer;
+  x, y, r, g, b: Integer;
+begin
+  try
+    try
       { create console }
       console := TPTCConsole.Create;
 
@@ -43,52 +39,52 @@ Begin
       surface := TPTCSurface.Create(console.width, console.height, format);
 
       { loop until a key is pressed }
-      While Not console.KeyPressed Do
-      Begin
+      while not console.KeyPressed do
+      begin
         { lock surface }
         pixels := surface.lock;
-        Try
+        try
           { get surface dimensions }
           width := surface.width;
           height := surface.height;
 
           { draw random pixels }
-          For i := 1 To 100 Do
-          Begin
+          for i := 1 to 100 do
+          begin
             { get random position }
-	    x := Random(width);
-	    y := Random(height);
+            x := Random(width);
+            y := Random(height);
 
             { get random color }
-	    r := Random(256);
-	    g := Random(256);
-	    b := Random(256);
+            r := Random(256);
+            g := Random(256);
+            b := Random(256);
 
             { draw color [r,g,b] at position [x,y] }
-	    pixels[x + y * width] := ((r And $00F8) Shl 8) Or
-				     ((g And $00FC) Shl 3) Or
-				     ((b And $00F8) Shr 3);
-          End;
-	Finally
+            pixels[x + y * width] := ((r and $00F8) shl 8) or
+                                     ((g and $00FC) shl 3) or
+                                     ((b and $00F8) shr 3);
+          end;
+        finally
           { unlock surface }
           surface.unlock;
-	End;
+        end;
 
         { copy to console }
         surface.copy(console);
 
         { update console }
         console.update;
-      End;
-    Finally
+      end;
+    finally
       console.close;
       console.Free;
       surface.Free;
       format.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 99 - 89
packages/ptc/examples/image.pp

@@ -3,104 +3,114 @@ Ported to FPC by Nikolay Nikolov ([email protected])
 }
 
 {
- Image example for OpenPTC 1.0 C++ Implementation
+ Image example for OpenPTC 1.0 C++ implementation
  Copyright (c) Glenn Fiedler ([email protected])
  This source code is in the public domain
 }
 
-Program ImageExample;
+program ImageExample;
 
 {$MODE objfpc}
 
-Uses
-  ptc;
-
-Procedure load(surface : TPTCSurface; filename : String);
-
-Var
-  F : File;
-  width, height : Integer;
-  pixels : PByte;
-  y : Integer;
-  tmp : TPTCFormat;
-  tmp2 : TPTCPalette;
-
-Begin
+uses
+  SysUtils, ptc;
+
+procedure load(surface: TPTCSurface; filename: String);
+var
+  F: File;
+  width, height: Integer;
+  pixels: PByte = nil;
+  y: Integer;
+  img_format: TPTCFormat = nil;
+  img_palette: TPTCPalette = nil;
+begin
   { open image file }
-  ASSign(F, filename);
+  AssignFile(F, filename);
   Reset(F, 1);
 
-  { skip header }
-  Seek(F, 18);
-
-  { get surface dimensions }
-  width := surface.width;
-  height := surface.height;
-
-  { allocate image pixels }
-  pixels := GetMem(width * height * 3);
-
-  { read image pixels one line at a time }
-  For y := height - 1 DownTo 0 Do
-    BlockRead(F, pixels[width * y * 3], width * 3);
-
-  { load pixels to surface }
-  tmp := TPTCFormat.Create(24, $00FF0000, $0000FF00, $000000FF);
-  tmp2 := TPTCPalette.Create;
-  surface.load(pixels, width, height, width * 3, tmp, tmp2);
-  tmp2.Free;
-  tmp.Free;
-
-  { free image pixels }
-  FreeMem(pixels);
-End;
-
-Var
-  console : TPTCConsole;
-  format : TPTCFormat;
-  surface : TPTCSurface;
-
-Begin
-  Try
-    { create console }
-    console := TPTCConsole.Create;
-
-    { create format }
-    format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
-
-    Try
-      { try to open the console matching the image resolution }
-      console.open('Image example', 320, 200, format);
-    Except
-      On TPTCError Do
-        { fallback to the default resolution }
-        console.open('Image example', format);
-    End;
-
-    { create surface }
-    surface := TPTCSurface.Create(320, 200, format);
-    format.Free;
-
-    { load image to surface }
-    load(surface, 'image.tga');
-
-    { copy surface to console }
-    surface.copy(console);
-
-    { update console }
-    console.update;
-
-    { read key }
-    console.ReadKey;
-
-    { close console }
-    console.close;
-
-    console.Free;
-    surface.Free;
-  Except
-    On error : TPTCError Do
+  try
+    { skip header }
+    Seek(F, 18);
+
+    { get surface dimensions }
+    width := surface.width;
+    height := surface.height;
+
+    { allocate image pixels }
+    pixels := GetMem(width * height * 3);
+
+    { read image pixels one line at a time }
+    for y := height - 1 DownTo 0 do
+      BlockRead(F, pixels[width * y * 3], width * 3);
+
+    { load pixels to surface }
+    {$IFDEF FPC_LITTLE_ENDIAN}
+    img_format := TPTCFormat.Create(24, $00FF0000, $0000FF00, $000000FF);
+    {$ELSE FPC_LITTLE_ENDIAN}
+    img_format := TPTCFormat.Create(24, $000000FF, $0000FF00, $00FF0000);
+    {$ENDIF FPC_LITTLE_ENDIAN}
+    img_palette := TPTCPalette.Create;
+    surface.load(pixels, width, height, width * 3, img_format, img_palette);
+
+  finally
+    CloseFile(F);
+
+    { free image pixels }
+    FreeMem(pixels);
+
+    img_palette.Free;
+    img_format.Free;
+  end;
+end;
+
+var
+  console: TPTCConsole = nil;
+  format: TPTCFormat = nil;
+  surface: TPTCSurface = nil;
+begin
+  try
+    try
+      { create console }
+      console := TPTCConsole.Create;
+
+      { create format }
+      format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+
+      try
+        { try to open the console matching the image resolution }
+        console.open('Image example', 320, 200, format);
+      except
+        on TPTCError do
+          { fallback to the default resolution }
+          console.open('Image example', format);
+      end;
+
+      { create surface }
+      surface := TPTCSurface.Create(320, 200, format);
+
+      { load image to surface }
+      load(surface, 'image.tga');
+
+      { copy surface to console }
+      surface.copy(console);
+
+      { update console }
+      console.update;
+
+      { read key }
+      console.ReadKey;
+
+    finally
+      { close console }
+      console.close;
+
+      console.Free;
+      surface.Free;
+      format.Free;
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 47 - 53
packages/ptc/examples/keyboard.pp

@@ -3,40 +3,34 @@ Ported to FPC by Nikolay Nikolov ([email protected])
 }
 
 {
- Keyboard example for OpenPTC 1.0 C++ Implementation
+ Keyboard example for OpenPTC 1.0 C++ implementation
  Copyright (c) Glenn Fiedler ([email protected])
  This source code is in the public domain
 }
 
-Program KeyboardExample;
+program KeyboardExample;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc;
 
-Var
-  console : TPTCConsole;
-  surface : TPTCSurface;
-  format : TPTCFormat;
-  color : TPTCColor;
-  key : TPTCKey;
-  area : TPTCArea;
-  x, y : Integer;
-  size : Integer;
-  delta : Integer;
-
-Begin
-  key := Nil;
-  color := Nil;
-  format := Nil;
-  surface := Nil;
-  console := Nil;
-  Try
-    Try
+var
+  console: TPTCConsole = nil;
+  surface: TPTCSurface = nil;
+  format: TPTCFormat = nil;
+  color: TPTCColor = nil;
+  key: TPTCKeyEvent = nil;
+  area: TPTCArea;
+  x, y: Integer;
+  size: Integer;
+  delta: Integer;
+begin
+  try
+    try
       { create key }
-      key := TPTCKey.Create;
-      
+      key := TPTCKeyEvent.Create;
+
       { create console }
       console := TPTCConsole.Create;
 
@@ -50,67 +44,67 @@ Begin
       surface := TPTCSurface.Create(console.width, console.height, format);
 
       { setup cursor data }
-      x := surface.width Div 2;
-      y := surface.height Div 2;
-      size := surface.width Div 10;
+      x := surface.width div 2;
+      y := surface.height div 2;
+      size := surface.width div 10;
       color := TPTCColor.Create(1, 1, 1);
 
       { main loop }
-      Repeat
+      repeat
         { check for key press }
-        If console.KeyPressed Then
-        Begin
+        if console.KeyPressed then
+        begin
           { read console key press }
           console.ReadKey(key);
-	
+
           { shift modifier }
-	  If key.shift Then
+          if key.shift then
             { move fast }
-	    delta := 10
-	  Else
+            delta := 10
+          else
             { move slow }
-	    delta := 1;
+            delta := 1;
 
           { handle cursor keys }
-          Case key.code Of
-            PTCKEY_LEFT : Dec(x, delta);
-            PTCKEY_RIGHT : Inc(x, delta);
-            PTCKEY_UP : Dec(y, delta);
-            PTCKEY_DOWN : Inc(y, delta);
+          case key.code of
+            PTCKEY_LEFT: Dec(x, delta);
+            PTCKEY_RIGHT: Inc(x, delta);
+            PTCKEY_UP: Dec(y, delta);
+            PTCKEY_DOWN: Inc(y, delta);
             { exit when escape is pressed }
-            PTCKEY_ESCAPE : Break;
-          End;
-        End;
+            PTCKEY_ESCAPE: Break;
+          end;
+        end;
 
         { clear surface }
         surface.clear;
 
         { setup cursor area }
         area := TPTCArea.Create(x - size, y - size, x + size, y + size);
-        Try
+        try
           { draw cursor as a quad }
           surface.clear(color, area);
-        Finally
+        finally
           area.Free;
-        End;
+        end;
 
         { copy to console }
         surface.copy(console);
 
         { update console }
         console.update;
-      Until False;
-    Finally
+      until False;
+    finally
       color.Free;
       console.close;
       console.Free;
       surface.Free;
       key.Free;
       format.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 63 - 59
packages/ptc/examples/keybrd2.pp → packages/ptc/examples/keyboard2.pp

@@ -1,36 +1,40 @@
-Program KeyboardExample2;
+{
+ Keyboard example for the PTCPas library
+ This source code is in the public domain
+}
+
+program KeyboardExample2;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc;
 
-Var
-  console : TPTCConsole;
-  surface : TPTCSurface;
-  format : TPTCFormat;
-  color : TPTCColor;
-  timer : TPTCTimer;
-  key : TPTCKey;
-  area : TPTCArea;
-  x, y, delta : Real;
-  left, right, up, down : Boolean;
-  size : Integer;
-  Done : Boolean;
-
-Begin
+var
+  console: TPTCConsole = nil;
+  surface: TPTCSurface = nil;
+  format: TPTCFormat = nil;
+  color: TPTCColor = nil;
+  timer: TPTCTimer = nil;
+  key: TPTCKeyEvent = nil;
+  area: TPTCArea;
+  x, y, delta: Real;
+  left, right, up, down: Boolean;
+  size: Integer;
+  Done: Boolean;
+begin
   left := False;
   right := False;
   up := False;
   down := False;
-  Try
-    Try
+  try
+    try
       { create key }
-      key := TPTCKey.Create;
-      
+      key := TPTCKeyEvent.Create;
+
       { create console }
       console := TPTCConsole.Create;
-      
+
       { enable key release events }
       console.KeyReleaseEnabled := True;
 
@@ -39,71 +43,71 @@ Begin
 
       { open the console }
       console.open('Keyboard example 2', format);
-      
+
       { create timer }
       timer := TPTCTimer.Create;
-      
+
       { create surface matching console dimensions }
       surface := TPTCSurface.Create(console.width, console.height, format);
 
       { setup cursor data }
-      x := surface.width Div 2;
-      y := surface.height Div 2;
-      size := surface.width Div 10;
+      x := surface.width div 2;
+      y := surface.height div 2;
+      size := surface.width div 10;
       color := TPTCColor.Create(1, 1, 1);
-      
+
       { start timer }
       timer.start;
 
       { main loop }
       Done := False;
-      Repeat
+      repeat
         { check for key press/release }
-        While console.KeyPressed Do
-        Begin
+        while console.KeyPressed do
+        begin
           console.ReadKey(key);
-          Case key.code Of
-	    PTCKEY_LEFT : left := key.press;
-	    PTCKEY_RIGHT : right := key.press;
-	    PTCKEY_UP : up := key.press;
-	    PTCKEY_DOWN : down := key.press;
-	    PTCKEY_ESCAPE : Begin
-	      Done := True;
-	      Break;
-	    End;
-	  End;
-        End;
+          case key.code of
+            PTCKEY_LEFT: left := key.press;
+            PTCKEY_RIGHT: right := key.press;
+            PTCKEY_UP: up := key.press;
+            PTCKEY_DOWN: down := key.press;
+            PTCKEY_ESCAPE: begin
+              Done := True;
+              Break;
+            end;
+          end;
+        end;
 
         { move square }
         delta := timer.delta*100;
-        If left Then
-          x -= delta;
-        If right Then
-          x += delta;
-        If up Then
-          y -= delta;
-        If down Then
-          y += delta;
+        if left then
+          x := x - delta;
+        if right then
+          x := x + delta;
+        if up then
+          y := y - delta;
+        if down then
+          y := y + delta;
 
         { clear surface }
         surface.clear;
 
         { setup cursor area }
         area := TPTCArea.Create(Trunc(x) - size, Trunc(y) - size, Trunc(x) + size, Trunc(y) + size);
-        Try
+        try
           { draw cursor as a quad }
           surface.clear(color, area);
-        Finally
+        finally
           area.Free;
-        End;
+        end;
 
         { copy to console }
         surface.copy(console);
 
         { update console }
         console.update;
-      Until Done;
-    Finally
+      until Done;
+    finally
       color.Free;
       console.close;
       console.Free;
@@ -111,10 +115,10 @@ Begin
       key.Free;
       timer.Free;
       format.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 199 - 214
packages/ptc/examples/land.pp

@@ -13,121 +13,116 @@ Ported to FPC by Nikolay Nikolov ([email protected])
  Cursor keys to move, <Pause> to brake and <Esc> to quit
 }
 
-Program Land;
+program Land;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc;
 
-Const
+const
   SCREENWIDTH = 320;
   SCREENHEIGHT = 200;
 
-  FOV : Integer = 256; { half of the xy field of view (This is based on the 0-2048 convention) }
+  FOV: Integer = 256; { half of the xy field of view (This is based on the 0-2048 convention) }
 
-Var
-  HMap : Array[0..256*256 - 1] Of Uint8; { Height field }
-  CMap : Array[0..256*256 - 1] Of Uint8; { Color map }
+var
+  HMap: array [0..256*256 - 1] of Uint8; { Height field }
+  CMap: array [0..256*256 - 1] of Uint8; { Color map }
 
   lasty, { Last pixel drawn on a given column }
-  lastc : Array[0..SCREENWIDTH - 1] Of Integer; { Color of last pixel on a column }
-  CosT, SinT : Array[0..2047] Of Integer; { Cosine and Sine tables }
+  lastc: array [0..SCREENWIDTH - 1] of Integer; { Color of last pixel on a column }
+  CosT, SinT: array [0..2047] of Integer; { Cosine and Sine tables }
 
 { Reduces a value to 0..255 (used in height field computation) }
-Function Clamp(x : Integer) : Integer;
-
-Begin
-  If x < 0 Then
-    Clamp := 0
-  Else
-    If x > 255 Then
-      Clamp := 255
-    Else
-      Clamp := x;
-End;
+function Clamp(x: Integer): Integer;
+begin
+  if x < 0 then
+    Result := 0
+  else
+    if x > 255 then
+      Result := 255
+    else
+      Result := x;
+end;
 
 { Heightfield and colormap computation }
-Procedure ComputeMap;
-
-Var
-  p, i, j, k, k2, p2, a, b, c, d : Integer;
-
-Begin
+procedure ComputeMap;
+var
+  p, i, j, k, k2, p2, a, b, c, d: Integer;
+begin
   { Start from a plasma clouds fractal }
   HMap[0] := 128;
   p := 256;
-  While p > 1 Do
-  Begin
-    p2 := p Shr 1;
+  while p > 1 do
+  begin
+    p2 := p shr 1;
     k := p * 8 + 20;
-    k2 := k Shr 1;
+    k2 := k shr 1;
     i := 0;
-    While i < 256 Do
-    Begin
+    while i < 256 do
+    begin
       j := 0;
-      While j < 256 Do
-      Begin
-	a := HMap[(i Shl 8) + j];
-	b := HMap[(((i + p) And 255) Shl 8) + j];
-	c := HMap[(i Shl 8) + ((j + p) And 255)];
-	d := HMap[(((i + p) And 255) Shl 8) + ((j + p) And 255)];
-
-	HMap[(i Shl 8) + ((j + p2) And 255)] :=
-	  Clamp(((a + c) Shr 1) + (Random(k) - k2));
-	HMap[(((i + p2) And 255) Shl 8) + ((j + p2) And 255)] :=
-	  Clamp(((a + b + c + d) Shr 2) + (Random(k) - k2));
-	HMap[(((i + p2) And 255) Shl 8) + j] :=
-	  Clamp(((a + b) Shr 1) + (Random(k) - k2));
-	Inc(j, p);
-      End;
+      while j < 256 do
+      begin
+        a := HMap[(i shl 8) + j];
+        b := HMap[(((i + p) and 255) shl 8) + j];
+        c := HMap[(i shl 8) + ((j + p) and 255)];
+        d := HMap[(((i + p) and 255) shl 8) + ((j + p) and 255)];
+
+        HMap[(i shl 8) + ((j + p2) and 255)] :=
+          Clamp(((a + c) shr 1) + (Random(k) - k2));
+        HMap[(((i + p2) and 255) shl 8) + ((j + p2) and 255)] :=
+          Clamp(((a + b + c + d) shr 2) + (Random(k) - k2));
+        HMap[(((i + p2) and 255) shl 8) + j] :=
+          Clamp(((a + b) shr 1) + (Random(k) - k2));
+        Inc(j, p);
+      end;
       Inc(i, p);
-    End;
+    end;
     p := p2;
-  End;
+  end;
 
   { Smoothing }
-  For k := 0 To 2 Do
-  Begin
+  for k := 0 to 2 do
+  begin
     i := 0;
-    While i < 256*256 Do
-    Begin
-      For j := 0 To 255 Do
-	HMap[i + j] := (HMap[((i + 256) And $FF00) + j] +
-			HMap[i + ((j + 1) And $FF)] +
-			HMap[((i - 256) And $FF00) + j] +
-			HMap[i + ((j - 1) And $FF)]) Shr 2;
+    while i < 256*256 do
+    begin
+      for j := 0 to 255 do
+        HMap[i + j] := (HMap[((i + 256) and $FF00) + j] +
+                        HMap[i + ((j + 1) and $FF)] +
+                        HMap[((i - 256) and $FF00) + j] +
+                        HMap[i + ((j - 1) and $FF)]) shr 2;
       Inc(i, 256);
-    End;
-  End;
+    end;
+  end;
 
   { Color computation (derivative of the height field) }
   i := 0;
-  While i < 256*256 Do
-  Begin
-    For j := 0 To 255 Do
-    Begin
-      k := 128 + (HMap[((i + 256) And $FF00) + ((j + 1) And 255)] - HMap[i + j])*4;
-      If k < 0 Then
-	k := 0;
-      If k > 255 Then
-	k := 255;
+  while i < 256*256 do
+  begin
+    for j := 0 to 255 do
+    begin
+      k := 128 + (HMap[((i + 256) and $FF00) + ((j + 1) and 255)] - HMap[i + j])*4;
+      if k < 0 then
+        k := 0;
+      if k > 255 then
+        k := 255;
       CMap[i + j] := k;
-    End;
+    end;
     Inc(i, 256);
-  End;
-End;
+  end;
+end;
 
 { Calculate the lookup tables }
-Procedure InitTables;
-
-Var
-  a : Integer;
-  result : Single;
-
-Begin
-  For a := 0 To 2047 Do
-  Begin
+procedure InitTables;
+var
+  a: Integer;
+  result: Single;
+begin
+  for a := 0 to 2047 do
+  begin
     { Precalculate cosine }
     result := cos(a * PI / 1024) * 256;
     CosT[a] := Trunc(result);
@@ -135,8 +130,8 @@ Begin
     { and sine }
     result := sin(a * PI / 1024) * 256;
     SinT[a] := Trunc(result);
-  End;
-End;
+  end;
+end;
 
 {
  Draw a "section" of the landscape; x0,y0 and x1,y1 and the xy coordinates
@@ -144,29 +139,27 @@ End;
  for the distance. x0,y0,x1,y1 are 16.16 fixed point numbers and the
  scaling factor is a 16.8 fixed point value.
 }
-Procedure Line(x0, y0, x1, y1, hy, s : Integer; surface_buffer : PUint32; fadeout : Integer);
-
-Var
-  sx, sy, i, a, b, u0, u1, v0, v1, h0, h1, h2, h3, h, c, y : Integer;
-  coord_x, coord_y, sc, cc, currentColor : Integer;
-  pixel : PUint32;
-
-Begin
+procedure Line(x0, y0, x1, y1, hy, s: Integer; surface_buffer: PUint32; fadeout: Integer);
+var
+  sx, sy, i, a, b, u0, u1, v0, v1, h0, h1, h2, h3, h, c, y: Integer;
+  coord_x, coord_y, sc, cc, currentColor: Integer;
+  pixel: PUint32;
+begin
   { Compute xy speed }
-  sx := (x1 - x0) Div SCREENWIDTH;
-  sy := (y1 - y0) Div SCREENWIDTH;
+  sx := (x1 - x0) div SCREENWIDTH;
+  sy := (y1 - y0) div SCREENWIDTH;
 
-  For i := 0 To SCREENWIDTH - 1 Do
-  Begin
+  for i := 0 to SCREENWIDTH - 1 do
+  begin
     { Compute the xy coordinates; a and b will be the position inside the }
     { single map cell (0..255). }
-    a := (x0 Shr 8) And $FF;
-    b := (y0 Shr 8) And $FF;
+    a := (x0 shr 8) and $FF;
+    b := (y0 shr 8) and $FF;
 
-    u0 := (x0 Shr 16) And $FF;
-    u1 := (u0 + 1) And $FF;
-    v0 := (y0 Shr 8) And $FF00;
-    v1 := (v0 + 256) And $FF00;
+    u0 := (x0 shr 16) and $FF;
+    u1 := (u0 + 1) and $FF;
+    v0 := (y0 shr 8) and $FF00;
+    v1 := (v0 + 256) and $FF00;
 
     { Fetch the height at the four corners of the square the point is in }
     h0 := HMap[u0 + v0];
@@ -175,9 +168,9 @@ Begin
     h3 := HMap[u1 + v1];
 
     { Compute the height using bilinear interpolation }
-    h0 := (h0 Shl 8) + a * (h1 - h0);
-    h2 := (h2 Shl 8) + a * (h3 - h2);
-    h := ((h0 Shl 8) + b * (h2 - h0)) Shr 16;
+    h0 := (h0 shl 8) + a * (h1 - h0);
+    h2 := (h2 shl 8) + a * (h3 - h2);
+    h := ((h0 shl 8) + b * (h2 - h0)) shr 16;
 
     { Fetch the color at the centre of the square the point is in }
     h0 := CMap[u0 + v0];
@@ -186,72 +179,70 @@ Begin
     h3 := CMap[u1 + v1];
 
     { Compute the color using bilinear interpolation (in 16.16) }
-    h0 := (h0 Shl 8) + a * (h1 - h0);
-    h2 := (h2 Shl 8) + a * (h3 - h2);
-    c := ((h0 Shl 8) + b * (h2 - h0));
+    h0 := (h0 shl 8) + a * (h1 - h0);
+    h2 := (h2 shl 8) + a * (h3 - h2);
+    c := ((h0 shl 8) + b * (h2 - h0));
 
     { Compute screen height using the scaling factor }
-    y := (((h - hy) * s) Shr 11) + (SCREENHEIGHT Shr 1);
+    y := (((h - hy) * s) shr 11) + (SCREENHEIGHT shr 1);
 
     { Draw the column }
     a := lasty[i];
-    If y < a Then
-    Begin
+    if y < a then
+    begin
       coord_x := i;
       coord_y := a;
-      If lastc[i] = -1 Then
-	lastc[i] := c;
+      if lastc[i] = -1 then
+        lastc[i] := c;
 
-      sc := (c - lastc[i]) Div (a - y);
+      sc := (c - lastc[i]) div (a - y);
       cc := lastc[i];
 
-      If a > (SCREENHEIGHT - 1) Then
-      Begin
-	Dec(coord_y, a - (SCREENHEIGHT - 1));
-	a := SCREENHEIGHT - 1;
-      End;
-      If y < 0 Then
-	y := 0;
-
-      While y < a Do
-      Begin
-	currentColor := cc Shr 18;
-	pixel := surface_buffer + (coord_y * SCREENWIDTH) + coord_x;
-	pixel^ := ((currentColor Shl 2) * (150 - fadeout) Div 150) Shl 8;
-	Inc(cc, sc);
-	Dec(coord_y);
-	Dec(a);
-      End;
+      if a > (SCREENHEIGHT - 1) then
+      begin
+        Dec(coord_y, a - (SCREENHEIGHT - 1));
+        a := SCREENHEIGHT - 1;
+      end;
+      if y < 0 then
+        y := 0;
+
+      while y < a do
+      begin
+        currentColor := cc shr 18;
+        pixel := surface_buffer + (coord_y * SCREENWIDTH) + coord_x;
+        pixel^ := ((currentColor shl 2) * (150 - fadeout) div 150) shl 8;
+        Inc(cc, sc);
+        Dec(coord_y);
+        Dec(a);
+      end;
       lasty[i] := y;
-    End;
+    end;
     lastc[i] := c;
 
     { Advance to next xy position }
     Inc(x0, sx); Inc(y0, sy);
-  End;
-End;
+  end;
+end;
 
 { Draw the view from the point x0,y0 (16.16) looking at angle a }
-Procedure View(x0, y0, angle, height : Integer; surface_buffer : PUint32);
-
-Var
-  d, u0, a, v0, u1, v1, h0, h1, h2, h3 : Integer;
-
-Begin
+procedure View(x0, y0, angle, height: Integer; surface_buffer: PUint32);
+var
+  d, u0, a, v0, u1, v1, h0, h1, h2, h3: Integer;
+begin
   { Initialize last-y and last-color arrays }
-  For d := 0 To SCREENWIDTH - 1 Do
-  Begin
+  for d := 0 to SCREENWIDTH - 1 do
+  begin
     lasty[d] := SCREENHEIGHT;
     lastc[d] := -1;
-  End;
+  end;
 
   { Compute the xy coordinates; a and b will be the position inside the }
   { single map cell (0..255). }
-  u0 := (x0 Shr 16) And $FF;
-  a := (x0 Shr 8) And $FF;
-  v0 := (y0 Shr 8) And $FF00;
-  u1 := (u0 + 1) And $FF;
-  v1 := (v0 + 256) And $FF00;
+  u0 := (x0 shr 16) and $FF;
+  a := (x0 shr 8) and $FF;
+  v0 := (y0 shr 8) and $FF00;
+  u1 := (u0 + 1) and $FF;
+  v1 := (v0 + 256) and $FF00;
 
   { Fetch the height at the four corners of the square the point is in }
   h0 := HMap[u0 + v0];
@@ -260,47 +251,41 @@ Begin
   h3 := HMap[u1 + v1];
 
   { Compute the height using bilinear interpolation }
-  h0 := (h0 Shl 8) + a * (h1 - h0);
-  h2 := (h2 Shl 8) + a * (h3 - h2);
+  h0 := (h0 shl 8) + a * (h1 - h0);
+  h2 := (h2 shl 8) + a * (h3 - h2);
 
   { Draw the landscape from near to far without overdraw }
   d := 0;
-  While d < 150 Do
-  Begin
-    Line(x0 + (d Shl 8)*CosT[(angle - FOV) And $7FF],
-	 y0 + (d Shl 8)*SinT[(angle - FOV) And $7FF],
-	 x0 + (d Shl 8)*CosT[(angle + FOV) And $7FF],
-	 y0 + (d Shl 8)*SinT[(angle + FOV) And $7FF],
-	 height, (100 Shl 8) Div (d + 1),
-	 surface_buffer,
-	 d);
-    Inc(d, 1 + (d Shr 6));
-  End;
-End;
-
-Var
-  format : TPTCFormat;
-  console : TPTCConsole;
-  surface : TPTCSurface;
-  timer : TPTCTimer;
-  key : TPTCKeyEvent;
-  pixels : PUint32;
-  Done : Boolean;
-
-  x0, y0 : Integer;
-  height : Integer;
-  angle, deltaAngle, deltaSpeed, CurrentSpeed, scale, delta : Double;
-  index : Integer;
-
-Begin
+  while d < 150 do
+  begin
+    Line(x0 + (d shl 8)*CosT[(angle - FOV) and $7FF],
+         y0 + (d shl 8)*SinT[(angle - FOV) and $7FF],
+         x0 + (d shl 8)*CosT[(angle + FOV) and $7FF],
+         y0 + (d shl 8)*SinT[(angle + FOV) and $7FF],
+         height, (100 shl 8) div (d + 1),
+         surface_buffer,
+         d);
+    Inc(d, 1 + (d shr 6));
+  end;
+end;
+
+var
+  format: TPTCFormat = nil;
+  console: TPTCConsole = nil;
+  surface: TPTCSurface = nil;
+  timer: TPTCTimer = nil;
+  key: TPTCKeyEvent = nil;
+  pixels: PUint32;
+  Done: Boolean;
+
+  x0, y0: Integer;
+  height: Integer;
+  angle, deltaAngle, deltaSpeed, CurrentSpeed, scale, delta: Double;
+  index: Integer;
+begin
   Done := False;
-  format := Nil;
-  console := Nil;
-  surface := Nil;
-  timer := Nil;
-  key := Nil;
-  Try
-    Try
+  try
+    try
       key := TPTCKeyEvent.Create;
       format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
       console := TPTCConsole.Create;
@@ -330,7 +315,7 @@ Begin
       timer.start;
 
       { main loop }
-      Repeat
+      repeat
         { get time delta between frames }
         delta := timer.delta;
 
@@ -339,13 +324,13 @@ Begin
 
         { lock surface pixels }
         pixels := surface.lock;
-        Try
+        try
           { draw current landscape view }
           View(x0, y0, Trunc(angle), height, pixels);
-	Finally
+        finally
           { unlock surface }
           surface.unlock;
-	End;
+        end;
 
         { copy surface to console }
         surface.copy(console);
@@ -354,49 +339,49 @@ Begin
         console.update;
 
         { check key press }
-        While console.KeyPressed Do
-        Begin
+        while console.KeyPressed do
+        begin
           { read key press }
-	  console.ReadKey(key);
+          console.ReadKey(key);
 
           { handle key press }
-	  Case key.code Of
+          case key.code of
                         { increase speed }
-	    PTCKEY_UP : CurrentSpeed += deltaSpeed * delta * scale;
+            PTCKEY_UP: CurrentSpeed := CurrentSpeed + deltaSpeed * delta * scale;
                         { decrease speed }
-	    PTCKEY_DOWN : CurrentSpeed -= deltaSpeed * delta * scale;
+            PTCKEY_DOWN: CurrentSpeed := CurrentSpeed - deltaSpeed * delta * scale;
                         { turn to the left }
-	    PTCKEY_LEFT : deltaAngle -= 1;
+            PTCKEY_LEFT: deltaAngle := deltaAngle - 1;
                         { turn to the right }
-	    PTCKEY_RIGHT : deltaAngle += 1;
-	    PTCKEY_SPACE : Begin
+            PTCKEY_RIGHT: deltaAngle := deltaAngle + 1;
+            PTCKEY_SPACE: begin
               { stop moving }
-	      CurrentSpeed := 0;
-	      deltaAngle := 0;
-	    End;
+              CurrentSpeed := 0;
+              deltaAngle := 0;
+            end;
                            { exit }
-	    PTCKEY_ESCAPE : Done := True;
-	  End;
-        End;
+            PTCKEY_ESCAPE: Done := True;
+          end;
+        end;
 
         { Update position/angle }
-        angle += deltaAngle * delta * scale;
+        angle := angle + deltaAngle * delta * scale;
 
-        index := Trunc(angle) And $7FF;
-        Inc(x0, Trunc(CurrentSpeed * CosT[index]) Div 256);
-        Inc(y0, Trunc(CurrentSpeed * SinT[index]) Div 256);
-      Until Done;
-    Finally
+        index := Trunc(angle) and $7FF;
+        Inc(x0, Trunc(CurrentSpeed * CosT[index]) div 256);
+        Inc(y0, Trunc(CurrentSpeed * SinT[index]) div 256);
+      until Done;
+    finally
       console.close;
       console.Free;
       surface.Free;
       timer.Free;
       format.Free;
       key.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 81 - 86
packages/ptc/examples/lights.pp

@@ -8,56 +8,51 @@ Ported to FPC by Nikolay Nikolov ([email protected])
  This source code is licensed under the GNU GPL
 }
 
-Program Lights;
+program Lights;
 
 {$MODE objfpc}
+{$INLINE on}
 
-Uses
+uses
   ptc;
 
-Var
+var
   { distance lookup table }
-  distance_table : Array[0..299, 0..511] Of DWord; { note: 16.16 fixed }
+  distance_table: array [0..299, 0..511] of DWord; { note: 16.16 fixed }
 
 { intensity calculation }
-Function CalcIntensity(dx, dy : Integer; i : DWord) : DWord;{ Inline;}
-
-Begin
+function CalcIntensity(dx, dy: Integer; i: DWord): DWord; Inline;
+begin
   { lookup intensity at [dx,dy] }
-  CalcIntensity := i * distance_table[dy, dx];
-End;
-
-Var
-  console : TPTCConsole;
-  surface : TPTCSurface;
-  format : TPTCFormat;
-  palette : TPTCPalette;
-  dx, dy : Integer;
-  divisor : Single;
-  data : PUint32;
-  pixels, line : PUint8;
-  width : Integer;
-  i : Integer;
-  x, y, x1, y1, x2, y2, x3, y3, x4, y4 : Integer;
-  cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4 : Single;
-  dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4 : Single;
-  _dx1, _dx2, _dx3, _dx4 : Integer;
-  _dy1, _dy2, _dy3, _dy4 : Integer;
-  ix1, ix2, ix3, ix4 : Integer;
-  i1, i2, i3, i4 : DWord;
-  length : Integer;
-  move_t, move_dt, move_ddt : Single;
-  flash_t, flash_dt, flash_ddt : Single;
-  intensity : DWord;
-  max_intensity, max_intensity_inc : Single;
-
-Begin
-  console := Nil;
-  format := Nil;
-  surface := Nil;
-  palette := Nil;
-  Try
-    Try
+  Result := i * distance_table[dy, dx];
+end;
+
+var
+  console: TPTCConsole = nil;
+  surface: TPTCSurface = nil;
+  format: TPTCFormat = nil;
+  palette: TPTCPalette = nil;
+  dx, dy: Integer;
+  divisor: Single;
+  data: PUint32;
+  pixels, line: PUint8;
+  width: Integer;
+  i: Integer;
+  x, y, x1, y1, x2, y2, x3, y3, x4, y4: Integer;
+  cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4: Single;
+  dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4: Single;
+  _dx1, _dx2, _dx3, _dx4: Integer;
+  _dy1, _dy2, _dy3, _dy4: Integer;
+  ix1, ix2, ix3, ix4: Integer;
+  i1, i2, i3, i4: DWord;
+  length: Integer;
+  move_t, move_dt, move_ddt: Single;
+  flash_t, flash_dt, flash_ddt: Single;
+  intensity: DWord;
+  max_intensity, max_intensity_inc: Single;
+begin
+  try
+    try
       { create console }
       console := TPTCConsole.Create;
 
@@ -70,26 +65,26 @@ Begin
       surface := TPTCSurface.Create(320, 200, format);
 
       { setup intensity table }
-      For dy := 0 To 199 Do
-        For dx := 0 To 511 Do
-        Begin
+      for dy := 0 to 199 do
+        for dx := 0 to 511 do
+        begin
           divisor := sqrt((dx * dx) + (dy * dy));
-          If divisor < 0.3 Then
+          if divisor < 0.3 then
             divisor := 0.3;
           distance_table[dy, dx] := Trunc(65535 / divisor);
-        End;
+        end;
 
       { create palette }
       palette := TPTCPalette.Create;
 
       { generate greyscale palette }
       data := palette.lock;
-      Try
-        For i := 0 To 255 Do
-          data[i] := (i Shl 16) Or (i Shl 8) Or i;
-      Finally
+      try
+        for i := 0 to 255 do
+          data[i] := (i shl 16) or (i shl 8) or i;
+      finally
         palette.unlock;
-      End;
+      end;
 
       { set console palette }
       console.palette(palette);
@@ -132,8 +127,8 @@ Begin
       max_intensity_inc := 0.2;
 
       { main loop }
-      While Not console.KeyPressed Do
-      Begin
+      while not console.KeyPressed do
+      begin
         { source positions }
         x1 := Trunc(cx1 + dx1);
         y1 := Trunc(cy1 + dy1);
@@ -146,13 +141,13 @@ Begin
 
         { lock surface }
         pixels := surface.lock;
-        Try
+        try
           { get surface dimensions }
           width := surface.width;
 
           { line loop }
-          For y := 0 To 199 Do
-          Begin
+          for y := 0 to 199 do
+          begin
             { calcalate pointer to start of line }
             line := pixels + y * width;
 
@@ -166,8 +161,8 @@ Begin
             x := 0;
 
             { line loop }
-            While x < width Do
-            Begin
+            while x < width do
+            begin
               { get x deltas }
               _dx1 := abs(x1 - x);
               _dx2 := abs(x2 - x);
@@ -179,37 +174,37 @@ Begin
               ix2 := 1;
               ix3 := 1;
               ix4 := 1;
-              If x1 > x Then
+              if x1 > x then
                 ix1 := -1;
-              If x2 > x Then
+              if x2 > x then
                 ix2 := -1;
-              If x3 > x Then
+              if x3 > x then
                 ix3 := -1;
-              If x4 > x Then
+              if x4 > x then
                 ix4 := -1;
 
               { set span length to min delta }
               length := width - x;
-              If (x1 > x) And (_dx1 < length) Then
+              if (x1 > x) and (_dx1 < length) then
                 length := _dx1;
-              If (x2 > x) And (_dx2 < length) Then
+              if (x2 > x) and (_dx2 < length) then
                 length := _dx2;
-              If (x3 > x) And (_dx3 < length) Then
+              if (x3 > x) and (_dx3 < length) then
                 length := _dx3;
-              If (x4 > x) And (_dx4 < length) Then
+              if (x4 > x) and (_dx4 < length) then
                 length := _dx4;
 
               { pixel loop }
-              While length > 0 Do
-              Begin
+              while length > 0 do
+              begin
                 Dec(length);
                 { calc intensities }
                 intensity := CalcIntensity(_dx1, _dy1, i1);
                 Inc(intensity, CalcIntensity(_dx2, _dy2, i2));
                 Inc(intensity, CalcIntensity(_dx3, _dy3, i3));
                 Inc(intensity, CalcIntensity(_dx4, _dy4, i4));
-                intensity := intensity Shr 16;
-                If intensity > 255 Then
+                intensity := intensity shr 16;
+                if intensity > 255 then
                   intensity := 255;
 
                 { update deltas }
@@ -221,13 +216,13 @@ Begin
                 { store the pixel }
                 line[x] := intensity;
                 Inc(x);
-              End;
-            End;
-          End;
-	Finally
+              end;
+            end;
+          end;
+        finally
           { unlock surface }
           surface.unlock;
-	End;
+        end;
 
         { move the lights around }
         dx1 := 50  * sin((move_t + 0.0) * 0.10);
@@ -252,9 +247,9 @@ Begin
         flash_dt := flash_dt + flash_ddt;
 
         { reset on big flash... }
-        If (move_t > 600) And (i1 > 10000) And (i2 > 10000) And
-           (i3 > 10000) And (i4 > 10000) Then
-        Begin
+        if (move_t > 600) and (i1 > 10000) and (i2 > 10000) and
+           (i3 > 10000) and (i4 > 10000) then
+        begin
           move_t := 0.3;
           move_dt := 0.1;
           move_ddt := 0.0006;
@@ -263,7 +258,7 @@ Begin
           flash_ddt := 0.0004;
           max_intensity := 0.0;
           max_intensity_inc := 0.2;
-        End;
+        end;
 
         { update intensity }
         max_intensity := max_intensity + max_intensity_inc;
@@ -274,17 +269,17 @@ Begin
 
         { update console }
         console.update;
-      End;
-    Finally
+      end;
+    finally
       console.close;
       surface.Free;
       console.Free;
       palette.Free;
       format.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 37 - 41
packages/ptc/examples/modes.pp

@@ -3,45 +3,43 @@ Ported to FPC by Nikolay Nikolov ([email protected])
 }
 
 {
- Modes example for OpenPTC 1.0 C++ Implementation
+ Modes example for OpenPTC 1.0 C++ implementation
  Copyright (c) Glenn Fiedler ([email protected])
  This source code is in the public domain
 }
 
-Program ModesExample;
+program ModesExample;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc;
 
-Procedure print(Const format : TPTCFormat);
-
-Begin
+procedure print(const format: TPTCFormat);
+begin
   { check format type }
-  If format.direct Then
+  if format.direct then
     { check alpha }
-    If format.a = 0 Then
+    if format.a = 0 then
       { direct color format without alpha }
       Write('Format(', format.bits:2, ',$', HexStr(format.r, 8), ',$', HexStr(format.g, 8), ',$', HexStr(format.b, 8), ')')
-    Else
+    else
       { direct color format with alpha }
       Write('Format(', format.bits:2, ',$', HexStr(format.r, 8), ',$', HexStr(format.g, 8), ',$', HexStr(format.b, 8), ',$', HexStr(format.a, 8), ')')
-  Else
+  else
     { indexed color format }
     Write('Format(', format.bits:2, ')');
-End;
-
-Procedure print(Const mode : TPTCMode);
+end;
 
-Begin
+procedure print(const mode: TPTCMode);
+begin
   { print mode width and height }
   Write(' ', mode.width:4, ' x ', mode.height);
-  If mode.height < 1000 Then
+  if mode.height < 1000 then
     Write(' ');
-  If mode.height < 100 Then
+  if mode.height < 100 then
     Write(' ');
-  If mode.height < 10 Then
+  if mode.height < 10 then
     Write(' ');
   Write(' x ');
 
@@ -50,17 +48,15 @@ Begin
 
   { newline }
   Writeln;
-End;
-
-Var
-  console : TPTCConsole;
-  modes : PPTCMode;
-  index : Integer;
-
-Begin
-  console := Nil;
-  Try
-    Try
+end;
+
+var
+  console: TPTCConsole = nil;
+  modes: PPTCMode;
+  index: Integer;
+begin
+  try
+    try
       { create console }
       console := TPTCConsole.Create;
 
@@ -68,11 +64,11 @@ Begin
       modes := console.modes;
 
       { check for empty list }
-      If Not modes[0].valid Then
+      if not modes[0].valid then
         { the console mode list was empty }
         Writeln('[console mode list is not available]')
-      Else
-      Begin
+      else
+      begin
         { print mode list header }
         Writeln('[console modes]');
 
@@ -80,21 +76,21 @@ Begin
         index := 0;
 
         { iterate through all modes }
-        While modes[index].valid Do
-        Begin
+        while modes[index].valid do
+        begin
           { print mode }
           print(modes[index]);
 
           { next mode }
           Inc(index);
-        End;
-      End;
-    Finally
+        end;
+      end;
+    finally
       console.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

File diff suppressed because it is too large
+ 554 - 620
packages/ptc/examples/mojo.pp


+ 128 - 0
packages/ptc/examples/mouse.pp

@@ -0,0 +1,128 @@
+{
+ Mouse example for the PTCPas library
+ This source code is in the public domain
+}
+
+program MouseExample;
+
+{$MODE objfpc}
+
+uses
+  ptc;
+
+var
+  console: TPTCConsole = nil;
+  surface: TPTCSurface = nil;
+  format: TPTCFormat = nil;
+  event: TPTCEvent = nil;
+  pixels: PUint32;
+  color: Uint32;
+  width, height: Integer;
+  I: Integer;
+  X, Y: Integer;
+  button: Boolean;
+  Done: Boolean = False;
+begin
+  try
+    try
+      { create console }
+      console := TPTCConsole.Create;
+
+      { create format }
+      format := TPTCFormat.Create(32, $FF0000, $FF00, $FF);
+
+      { open the console }
+      console.open('Mouse example', format);
+
+      { we're going to draw our own cursor, so disable the default cursor }
+      console.option('hide cursor');
+
+      { create surface matching console dimensions }
+      surface := TPTCSurface.Create(console.width, console.height, format);
+
+      { initialization }
+      X := 0;
+      Y := 0;
+
+      repeat
+        { wait for events }
+        console.NextEvent(event, True, PTCAnyEvent);
+
+        { handle mouse events }
+        if event is TPTCMouseEvent then
+        begin
+          { if there's more than one mouse event, process them all... }
+          repeat
+            X := (event as TPTCMouseEvent).X;
+            Y := (event as TPTCMouseEvent).Y;
+            button := PTCMouseButton1 in (event as TPTCMouseEvent).ButtonState;
+          until not console.NextEvent(event, False, [PTCMouseEvent]);
+        end;
+
+        { handle keyboard events }
+        if (event is TPTCKeyEvent) and (event as TPTCKeyEvent).Press then
+        begin
+          case (event as TPTCKeyEvent).Code of
+            PTCKEY_G: console.Option('grab mouse');
+            PTCKEY_U: console.Option('ungrab mouse');
+            PTCKEY_ESCAPE: Done := True;
+          end;
+        end;
+
+        { clear surface }
+        surface.clear;
+
+        { lock surface }
+        pixels := surface.lock;
+
+        try
+          { get surface dimensions }
+          width := surface.width;
+          height := surface.height;
+
+          if button then
+            color := $00FF00 { green cursor, if button 1 is pressed }
+          else
+            color := $FFFFFF; { white cursor if button 1 is not pressed }
+
+          { draw a small cross for a cursor }
+          for I := 2 to 10 do
+          begin
+            if (X - I) >= 0 then
+              pixels[X - I + Y * width] := color;
+
+            if (X + I) < width then
+              pixels[X + I + Y * width] := color;
+
+            if (Y - I) >= 0 then
+              pixels[X + (Y - I) * width] := color;
+
+            if (Y + I) < height then
+              pixels[X + (Y + I) * width] := color;
+          end;
+
+        finally
+          { unlock surface }
+          surface.unlock;
+        end;
+
+        { copy to console }
+        surface.copy(console);
+
+        { update console }
+        console.update;
+
+      until Done;
+    finally
+      console.close;
+      console.Free;
+      surface.Free;
+      format.Free;
+      event.Free;
+    end;
+  except
+    on error: TPTCError do
+      { report error }
+      error.report;
+  end;
+end.

+ 90 - 86
packages/ptc/examples/palette.pp

@@ -3,100 +3,104 @@ Ported to FPC by Nikolay Nikolov ([email protected])
 }
 
 {
- Palette example for OpenPTC 1.0 C++ Implementation
+ Palette example for OpenPTC 1.0 C++ implementation
  Copyright (c) Glenn Fiedler ([email protected])
  This source code is in the public domain
 }
 
-Program PaletteExample;
+program PaletteExample;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc;
 
-Var
-  console : TPTCConsole;
-  surface : TPTCSurface;
-  format : TPTCFormat;
-  palette : TPTCPalette;
-  data : Array[0..255] Of int32;
-  pixels : Pchar8;
-  width, height : Integer;
-  i : Integer;
-  x, y, index : Integer;
-
-Begin
-  Try
-    { create console }
-    console := TPTCConsole.Create;
-
-    { create format }
-    format := TPTCFormat.Create(8);
-
-    { open console }
-    console.open('Palette example', format);
-
-    { create surface }
-    surface := TPTCSurface.Create(console.width, console.height, format);
-    format.Free;
-
-    { create palette }
-    palette := TPTCPalette.Create;
-
-    { generate palette }
-    For i := 0 To 255 Do
-      data[i] := i;
-
-    { load palette data }
-    palette.load(data);
-
-    { set console palette }
-    console.palette(palette);
-
-    { set surface palette }
-    surface.palette(palette);
-    palette.Free;
-
-    { loop until a key is pressed }
-    While Not console.KeyPressed Do
-    Begin
-      { lock surface }
-      pixels := surface.lock;
-
-      { get surface dimensions }
-      width := surface.width;
-      height := surface.height;
-
-      { draw random pixels }
-      For i := 1 To 100 Do
-      Begin
-        { get random position }
-	x := Random(width);
-	y := Random(height);
-
-        { get random color index }
-	index := Random(256);
-
-        { draw color [index] at position [x,y] }
-	pixels[x + y * width] := index;
-      End;
-
-      { unlock surface }
-      surface.unlock;
-
-      { copy to console }
-      surface.copy(console);
-
-      { update console }
-      console.update;
-    End;
-    console.close;
-    console.Free;
-    surface.Free;
-  Except
-    On error : TPTCError Do
+var
+  console: TPTCConsole = nil;
+  surface: TPTCSurface = nil;
+  format: TPTCFormat = nil;
+  palette: TPTCPalette = nil;
+  data: array [0..255] of Uint32;
+  pixels: PUint8;
+  width, height: Integer;
+  i: Integer;
+  x, y, index: Integer;
+begin
+  try
+    try
+      { create console }
+      console := TPTCConsole.Create;
+
+      { create format }
+      format := TPTCFormat.Create(8);
+
+      { open console }
+      console.open('Palette example', format);
+
+      { create surface }
+      surface := TPTCSurface.Create(console.width, console.height, format);
+
+      { create palette }
+      palette := TPTCPalette.Create;
+
+      { generate palette }
+      for i := 0 to 255 do
+        data[i] := i;
+
+      { load palette data }
+      palette.load(data);
+
+      { set console palette }
+      console.palette(palette);
+
+      { set surface palette }
+      surface.palette(palette);
+
+      { loop until a key is pressed }
+      while not console.KeyPressed do
+      begin
+        { lock surface }
+        pixels := surface.lock;
+
+        try
+          { get surface dimensions }
+          width := surface.width;
+          height := surface.height;
+
+          { draw random pixels }
+          for i := 1 to 100 do
+          begin
+            { get random position }
+            x := Random(width);
+            y := Random(height);
+
+            { get random color index }
+            index := Random(256);
+
+            { draw color [index] at position [x,y] }
+            pixels[x + y * width] := index;
+          end;
+        finally
+          { unlock surface }
+          surface.unlock;
+        end;
+
+        { copy to console }
+        surface.copy(console);
+
+        { update console }
+        console.update;
+      end;
+    finally
+      console.close;
+      console.Free;
+      surface.Free;
+      palette.Free;
+      format.Free;
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 27 - 33
packages/ptc/examples/pixel.pp

@@ -8,45 +8,39 @@ Ported to FPC by Nikolay Nikolov ([email protected])
  This source code is licensed under the GNU GPL
 }
 
-Program PixelExample;
+program PixelExample;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc;
 
-Procedure putpixel(surface : TPTCSurface; x, y : Integer; r, g, b : char8);
-
-Var
-  pixels : Pint32;
-  color : int32;
-
-Begin
+procedure putpixel(surface: TPTCSurface; x, y: Integer; r, g, b: Uint8);
+var
+  pixels: PUint32;
+  color: Uint32;
+begin
   { lock surface }
   pixels := surface.lock;
-  Try
+  try
     { pack the color integer from r,g,b components }
-    color := (r Shl 16) Or (g Shl 8) Or b;
+    color := (r shl 16) or (g shl 8) or b;
 
     { plot the pixel on the surface }
     pixels[x + y * surface.width] := color;
-  Finally
+  finally
     { unlock surface }
     surface.unlock;
-  End;
-End;
-
-Var
-  console : TPTCConsole;
-  surface : TPTCSurface;
-  format : TPTCFormat;
-
-Begin
-  format := Nil;
-  surface := Nil;
-  console := Nil;
-  Try
-    Try
+  end;
+end;
+
+var
+  console: TPTCConsole = nil;
+  surface: TPTCSurface = nil;
+  format: TPTCFormat = nil;
+begin
+  try
+    try
       { create console }
       console := TPTCConsole.Create;
 
@@ -60,7 +54,7 @@ Begin
       surface := TPTCSurface.Create(console.width, console.height, format);
 
       { plot a white pixel in the middle of the surface }
-      putpixel(surface, surface.width Div 2, surface.height Div 2, 255, 255, 255);
+      putpixel(surface, surface.width div 2, surface.height div 2, 255, 255, 255);
 
       { copy to console }
       surface.copy(console);
@@ -70,15 +64,15 @@ Begin
 
       { read key }
       console.ReadKey;
-    Finally
+    finally
       console.close;
       console.Free;
       surface.Free;
       format.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 35 - 39
packages/ptc/examples/random.pp

@@ -3,33 +3,29 @@ Ported to FPC by Nikolay Nikolov ([email protected])
 }
 
 {
- Random example for OpenPTC 1.0 C++ Implementation
+ Random example for OpenPTC 1.0 C++ implementation
  Copyright (c) Glenn Fiedler ([email protected])
  This source code is in the public domain
 }
 
-Program RandomExample;
+program RandomExample;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc;
 
-Var
-  console : TPTCConsole;
-  surface : TPTCSurface;
-  format : TPTCFormat;
-  pixels : Pint32;
-  width, height : Integer;
-  i : Integer;
-  x, y, r, g, b : Integer;
-
-Begin
-  format := Nil;
-  surface := Nil;
-  console := Nil;
-  Try
-    Try
+var
+  console: TPTCConsole = nil;
+  surface: TPTCSurface = nil;
+  format: TPTCFormat = nil;
+  pixels: PUint32;
+  width, height: Integer;
+  i: Integer;
+  x, y, r, g, b: Integer;
+begin
+  try
+    try
       { create console }
       console := TPTCConsole.Create;
 
@@ -43,50 +39,50 @@ Begin
       surface := TPTCSurface.Create(console.width, console.height, format);
 
       { loop until a key is pressed }
-      While Not console.KeyPressed Do
-      Begin
+      while not console.KeyPressed do
+      begin
         { lock surface }
         pixels := surface.lock;
-        Try
+        try
           { get surface dimensions }
           width := surface.width;
           height := surface.height;
 
           { draw random pixels }
-          For i := 1 To 100 Do
-          Begin
+          for i := 1 to 100 do
+          begin
             { get random position }
-	    x := Random(width);
-	    y := Random(height);
+            x := Random(width);
+            y := Random(height);
 
             { get random color }
-	    r := Random(256);
-	    g := Random(256);
-	    b := Random(256);
+            r := Random(256);
+            g := Random(256);
+            b := Random(256);
 
             { draw color [r,g,b] at position [x,y] }
-	    pixels[x + y * width] := (r Shl 16) + (g Shl 8) + b;
-          End;
-        Finally
+            pixels[x + y * width] := (r shl 16) + (g shl 8) + b;
+          end;
+        finally
           { unlock surface }
           surface.unlock;
-	End;
+        end;
 
         { copy to console }
         surface.copy(console);
 
         { update console }
         console.update;
-      End;
-    Finally
+      end;
+    finally
       console.close;
       console.Free;
       surface.Free;
       format.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 120 - 126
packages/ptc/examples/save.pp

@@ -3,92 +3,93 @@ Ported to FPC by Nikolay Nikolov ([email protected])
 }
 
 {
- Save example for OpenPTC 1.0 C++ Implementation
+ Save example for OpenPTC 1.0 C++ implementation
  Copyright (c) Glenn Fiedler ([email protected])
  This source code is in the public domain
 }
 
-Program SaveExample;
+program SaveExample;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc, Math;
 
-Procedure save(surface : TPTCSurface; filename : String);
-
-Const
+procedure save(surface: TPTCSurface; filename: string);
+var
+  F: File;
+  width, height: Integer;
+  size: Integer;
+  y: Integer;
+  pixels: PUint8 = nil;
+  format: TPTCFormat = nil;
+  palette: TPTCPalette = nil;
   { generate the header for a true color targa image }
-  header : Array[0..17] Of char8 =
+  header: array [0..17] of Uint8 =
     (0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
-
-Var
-  F : File;
-  width, height : Integer;
-  size : Integer;
-  y : Integer;
-  pixels : Pchar8;
-  format : TPTCFormat;
-  palette : TPTCPalette;
-
-Begin
+begin
   { open image file for writing }
-  ASSign(F, filename);
+  AssignFile(F, filename);
   Rewrite(F, 1);
 
-  { get surface dimensions }
-  width := surface.width;
-  height := surface.height;
-
-  { set targa image width }
-  header[12] := width And $FF;
-  header[13] := width Shr 8;
-
-  { set targa image height }
-  header[14] := height And $FF;
-  header[15] := height Shr 8;
+  try
+    { get surface dimensions }
+    width := surface.width;
+    height := surface.height;
 
-  { set bits per pixel }
-  header[16] := 24;
+    { set targa image width }
+    header[12] := width and $FF;
+    header[13] := width shr 8;
 
-  { write tga header }
-  BlockWrite(F, header, 18);
+    { set targa image height }
+    header[14] := height and $FF;
+    header[15] := height shr 8;
 
-  { calculate size of image pixels }
-  size := width * height * 3;
+    { set bits per pixel }
+    header[16] := 24;
 
-  { allocate image pixels }
-  pixels := GetMem(size);
+    { write tga header }
+    BlockWrite(F, header, 18);
 
-  format := TPTCFormat.Create(24, $00FF0000, $0000FF00, $000000FF);
-  palette := TPTCPalette.Create;
+    { calculate size of image pixels }
+    size := width * height * 3;
 
-  { save surface to image pixels }
-  surface.save(pixels, width, height, width * 3, format, palette);
+    { allocate image pixels }
+    pixels := GetMem(size);
 
-  palette.Free;
-  format.Free;
+    {$IFDEF FPC_LITTLE_ENDIAN}
+    format := TPTCFormat.Create(24, $00FF0000, $0000FF00, $000000FF);
+    {$ELSE FPC_LITTLE_ENDIAN}
+    format := TPTCFormat.Create(24, $000000FF, $0000FF00, $00FF0000);
+    {$ENDIF FPC_LITTLE_ENDIAN}
+    palette := TPTCPalette.Create;
 
-  { write image pixels one line at a time }
-  For y := height - 1 DownTo 0 Do
-    BlockWrite(F, pixels[width * y * 3], width * 3);
+    { save surface to image pixels }
+    surface.save(pixels, width, height, width * 3, format, palette);
 
-  { free image pixels }
-  FreeMem(pixels);
+    { write image pixels one line at a time }
+    for y := height - 1 DownTo 0 do
+      BlockWrite(F, pixels[width * y * 3], width * 3);
 
-  Close(F);
-End;
+  finally
+    { free image pixels }
+    FreeMem(pixels);
 
-Function calculate(real, imaginary : Single; maximum : Integer) : Integer;
+    palette.Free;
+    format.Free;
 
-Var
-  c_r, c_i : Single;
-  z_r, z_i : Single;
-  z_r_squared, z_i_squared : Single;
-  z_squared_magnitude : Single;
-  count : Integer;
+    CloseFile(F);
+  end;
+end;
 
-Begin
+function calculate(real, imaginary: Single; maximum: Integer): Integer;
+var
+  c_r, c_i: Single;
+  z_r, z_i: Single;
+  z_r_squared, z_i_squared: Single;
+  z_squared_magnitude: Single;
+  count: Integer;
+begin
   { complex number 'c' }
   c_r := real;
   c_i := imaginary;
@@ -102,8 +103,8 @@ Begin
   z_i_squared := 0;
 
   { mandelbrot function iteration loop }
-  For count := 0 To maximum - 1 Do
-  Begin
+  for count := 0 to maximum - 1 do
+  begin
     { square 'z' and add 'c' }
     z_i := 2 * z_r * z_i + c_i;
     z_r := z_r_squared - z_i_squared + c_r;
@@ -116,46 +117,43 @@ Begin
     z_squared_magnitude := z_r_squared + z_i_squared;
 
     { stop iterating if the magnitude of 'z' is greater than two }
-    If z_squared_magnitude > 4 Then
-    Begin
+    if z_squared_magnitude > 4 then
+    begin
       calculate := Count;
-      Exit;
-    End;
-  End;
+      exit;
+    end;
+  end;
 
   { maximum }
   calculate := 0;
-End;
+end;
 
-Procedure mandelbrot(console : TPTCConsole; surface : TPTCSurface;
-		     x1, y1, x2, y2 : Single);
-
-Const
+procedure mandelbrot(console: TPTCConsole; surface: TPTCSurface;
+                     x1, y1, x2, y2: Single);
+const
   { constant values }
   entries = 1024;
   maximum = 1024;
-
-Var
+var
   { fractal color table }
-  table : Array[0..entries - 1] Of int32;
-  i : Integer;
-  f_index : Single;
-  time : Single;
-  intensity : Single;
-  pixels, pixel : Pint32;
-  width, height : Integer;
-  dx, dy : Single;
-  real, imaginary : Single;
-  x, y : Integer;
-  count : Integer;
-  index : Integer;
-  color : int32;
-  area : TPTCArea;
-
-Begin
+  table: array [0..entries - 1] of Uint32;
+  i: Integer;
+  f_index: Single;
+  time: Single;
+  intensity: Single;
+  pixels, pixel: PUint32;
+  width, height: Integer;
+  dx, dy: Single;
+  real, imaginary: Single;
+  x, y: Integer;
+  count: Integer;
+  index: Integer;
+  color: Uint32;
+  area: TPTCArea;
+begin
   { generate fractal color table }
-  For i := 0 To entries - 1 Do
-  Begin
+  for i := 0 to entries - 1 do
+  begin
     { calculate normalized index }
     f_index := i / entries;
 
@@ -170,11 +168,11 @@ Begin
 
     { store intensity as a shade of blue }
     table[i] := Trunc(255 * intensity);
-  End;
+  end;
 
   { lock surface pixels }
   pixels := surface.lock;
-  Try
+  try
     { get surface dimensions }
     width := surface.width;
     height := surface.height;
@@ -190,19 +188,19 @@ Begin
     imaginary := y1;
 
     { iterate down surface y }
-    For y := 0 To height - 1 Do
-    Begin
+    for y := 0 to height - 1 do
+    begin
       { real axis }
       real := x1;
 
-      { iterate across surface x }    
-      For x := 0 To width - 1 Do
-      Begin
+      { iterate across surface x }
+      for x := 0 to width - 1 do
+      begin
         { calculate the mandelbrot interation count }
         count := calculate(real, imaginary, maximum);
 
         { calculate color table index }
-        index := count Mod entries;
+        index := count mod entries;
 
         { lookup color from iteration }
         color := table[index];
@@ -215,41 +213,37 @@ Begin
 
         { update real }
         real := real + dx;
-      End;
+      end;
 
       { update imaginary }
       imaginary := imaginary + dy;
 
       { setup line area }
       area := TPTCArea.Create(0, y, width, y + 1);
-      Try
+      try
         { copy surface area to console }
         surface.copy(console, area, area);
-      Finally
+      finally
         area.Free;
-      End;
+      end;
 
       { update console area }
       console.update;
-    End;
-  Finally
+    end;
+  finally
     { unlock surface }
     surface.unlock;
-  End;
-End;
-
-Var
-  console : TPTCConsole;
-  surface : TPTCSurface;
-  format : TPTCFormat;
-  x1, y1, x2, y2 : Single;
-
-Begin
-  format := Nil;
-  surface := Nil;
-  console := Nil;
-  Try
-    Try
+  end;
+end;
+
+var
+  console: TPTCConsole = nil;
+  surface: TPTCSurface = nil;
+  format: TPTCFormat = nil;
+  x1, y1, x2, y2: Single;
+begin
+  try
+    try
       { create console }
       console := TPTCConsole.Create;
 
@@ -276,15 +270,15 @@ Begin
 
       { read key }
       console.ReadKey;
-    Finally
+    finally
       console.close;
       console.Free;
       surface.Free;
       format.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 70 - 71
packages/ptc/examples/stretch.pp

@@ -3,86 +3,85 @@ Ported to FPC by Nikolay Nikolov ([email protected])
 }
 
 {
- Stretch example for OpenPTC 1.0 C++ Implementation
+ Stretch example for OpenPTC 1.0 C++ implementation
  Copyright (c) Glenn Fiedler ([email protected])
  This source code is in the public domain
 }
 
-Program StretchExample;
+program StretchExample;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc;
 
-Procedure load(surface : TPTCSurface; filename : String);
-
-Var
-  F : File;
-  width, height : Integer;
-  pixels : PByte;
-  y : Integer;
-  tmp : TPTCFormat;
-  tmp2 : TPTCPalette;
-
-Begin
+procedure load(surface: TPTCSurface; filename: String);
+var
+  F: File;
+  width, height: Integer;
+  pixels: PByte = nil;
+  y: Integer;
+  tmp: TPTCFormat;
+  tmp2: TPTCPalette;
+begin
   { open image file }
-  ASSign(F, filename);
+  AssignFile(F, filename);
   Reset(F, 1);
 
-  { skip header }
-  Seek(F, 18);
+  try
+    { skip header }
+    Seek(F, 18);
 
-  { get surface dimensions }
-  width := surface.width;
-  height := surface.height;
+    { get surface dimensions }
+    width := surface.width;
+    height := surface.height;
+
+    { allocate image pixels }
+    pixels := GetMem(width * height * 3);
 
-  { allocate image pixels }
-  pixels := GetMem(width * height * 3);
-  Try
     { read image pixels one line at a time }
-    For y := height - 1 DownTo 0 Do
+    for y := height - 1 downto 0 do
       BlockRead(F, pixels[width * y * 3], width * 3);
 
     { load pixels to surface }
+    {$IFDEF FPC_LITTLE_ENDIAN}
     tmp := TPTCFormat.Create(24, $00FF0000, $0000FF00, $000000FF);
-    Try
+    {$ELSE FPC_LITTLE_ENDIAN}
+    tmp := TPTCFormat.Create(24, $000000FF, $0000FF00, $00FF0000);
+    {$ENDIF FPC_LITTLE_ENDIAN}
+    try
       tmp2 := TPTCPalette.Create;
-      Try
+      try
         surface.load(pixels, width, height, width * 3, tmp, tmp2);
-      Finally
+      finally
         tmp2.Free;
-      End;
-    Finally
+      end;
+    finally
       tmp.Free;
-    End;
-  Finally
+    end;
+  finally
     { free image pixels }
     FreeMem(pixels);
-  End;
-End;
-
-Var
-  console : TPTCConsole;
-  surface : TPTCSurface;
-  image : TPTCSurface;
-  format : TPTCFormat;
-  timer : TPTCTimer;
-  area : TPTCArea;
-  color : TPTCColor;
-  time : Double;
-  zoom : Single;
-  x, y, x1, y1, x2, y2, dx, dy : Integer;
-
-Begin
-  format := Nil;
-  color := Nil;
-  timer := Nil;
-  image := Nil;
-  surface := Nil;
-  console := Nil;
-  Try
-    Try
+
+    { close file }
+    CloseFile(F);
+  end;
+end;
+
+var
+  console: TPTCConsole = nil;
+  surface: TPTCSurface = nil;
+  image: TPTCSurface = nil;
+  format: TPTCFormat = nil;
+  timer: TPTCTimer = nil;
+  area: TPTCArea = nil;
+  color: TPTCColor = nil;
+  time: Double;
+  zoom: Single;
+  x, y, x1, y1, x2, y2, dx, dy: Integer;
+begin
+  try
+    try
       { create console }
       console := TPTCConsole.Create;
 
@@ -102,10 +101,10 @@ Begin
       load(image, 'stretch.tga');
 
       { setup stretching parameters }
-      x := surface.width Div 2;
-      y := surface.height Div 2;
-      dx := surface.width Div 2;
-      dy := surface.height Div 3;
+      x := surface.width div 2;
+      y := surface.height div 2;
+      dx := surface.width div 2;
+      dy := surface.height div 3;
 
       { create timer }
       timer := TPTCTimer.Create;
@@ -115,8 +114,8 @@ Begin
       color := TPTCColor.Create(1, 1, 1);
 
       { loop until a key is pressed }
-      While Not console.KeyPressed Do
-      Begin
+      while not console.KeyPressed do
+      begin
         { get current time from timer }
         time := timer.time;
 
@@ -134,7 +133,7 @@ Begin
 
         { setup image copy area }
         area := TPTCArea.Create(x1, y1, x2, y2);
-	Try
+        try
           { copy and stretch image to surface }
           image.copy(surface, image.area, area);
 
@@ -143,11 +142,11 @@ Begin
 
           { update console }
           console.update;
-	Finally
+        finally
           area.Free;
-	End;
-      End;
-    Finally
+        end;
+      end;
+    finally
       console.close;
       console.Free;
       surface.Free;
@@ -155,10 +154,10 @@ Begin
       image.Free;
       color.Free;
       timer.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 229 - 246
packages/ptc/examples/texwarp.pp

@@ -8,193 +8,183 @@ Ported to FPC by Nikolay Nikolov ([email protected])
   This source code is licensed under the GNU GPL
 }
 
-Program TexWarp;
+program TexWarp;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc;
 
-Const
+const
 { colour balance values.  change these if you don't like the colouring }
 { of the texture. }
-  red_balance : Uint32 = 2;
-  green_balance : Uint32 = 3;
-  blue_balance : Uint32 = 1;
-
-Procedure blur(s : TPTCSurface);
-
-Var
-  d : PUint8;
-  pitch : Integer;
-  spack, r : Integer;
-
-Begin
+  red_balance: Uint32 = 2;
+  green_balance: Uint32 = 3;
+  blue_balance: Uint32 = 1;
+
+procedure blur(s: TPTCSurface);
+var
+  d: PUint8;
+  pitch: Integer;
+  spack, r: Integer;
+begin
   { lock surface }
   d := s.lock;
-  
-  Try
+
+  try
     pitch := s.pitch;
     spack := (s.height - 1) * pitch;
 
     { first pixel }
-    For r := 0 To 3 Do
-      d[r] := (d[pitch + r] + d[r + 4] + d[spack + r] + d[pitch - 4 + r]) Div 4;
+    for r := 0 to 3 do
+      d[r] := (d[pitch + r] + d[r + 4] + d[spack + r] + d[pitch - 4 + r]) div 4;
 
     { rest of first line }
-    For r := 4 To pitch - 1 Do
-      d[r] := (d[r + pitch] + d[r + 4] + d[r - 4] + d[spack + r]) Div 4;
+    for r := 4 to pitch - 1 do
+      d[r] := (d[r + pitch] + d[r + 4] + d[r - 4] + d[spack + r]) div 4;
 
     { rest of surface except last line }
-    For r := pitch To ((s.height - 1) * pitch) - 1 Do
-      d[r] := (d[r - pitch] + d[r + pitch] + d[r + 4] + d[r - 4]) Div 4;
+    for r := pitch to ((s.height - 1) * pitch) - 1 do
+      d[r] := (d[r - pitch] + d[r + pitch] + d[r + 4] + d[r - 4]) div 4;
 
     { last line except last pixel }
-    For r := (s.height - 1) * pitch To (s.height * s.pitch) - 5 Do
-      d[r] := (d[r - pitch] + d[r + 4] + d[r - 4] + d[r - spack]) Div 4;
+    for r := (s.height - 1) * pitch to (s.height * s.pitch) - 5 do
+      d[r] := (d[r - pitch] + d[r + 4] + d[r - 4] + d[r - spack]) div 4;
 
     { last pixel }
-    For r := (s.height * s.pitch) - 4 To s.height * s.pitch Do
-      d[r] := (d[r - pitch] + d[r - 4] + d[r - spack] + d[r + 4 - pitch]) Div 4;
+    for r := (s.height * s.pitch) - 4 to s.height * s.pitch - 1 do
+      d[r] := (d[r - pitch] + d[r - 4] + d[r - spack] + d[r + 4 - pitch]) div 4;
 
-  Finally
+  finally
     s.unlock;
-  End;
-End;
-
-Procedure generate(surface : TPTCSurface);
-
-Var
-  dest : PUint32;
-  i : Integer;
-  x, y : Integer;
-  d : PUint32;
-  cv : Uint32;
-  r, g, b : Uint8;
-
-Begin
+  end;
+end;
+
+procedure generate(surface: TPTCSurface);
+var
+  dest: PUint32;
+  i: Integer;
+  x, y: Integer;
+  d: PUint32;
+  cv: Uint32;
+  r, g, b: Uint8;
+begin
   { draw random dots all over the surface }
   dest := surface.lock;
-  Try
-    For i := 0 To surface.width * surface.height - 1 Do
-    Begin
+  try
+    for i := 0 to surface.width * surface.height - 1 do
+    begin
       x := Random(surface.width);
       y := Random(surface.height);
       d := dest + (y * surface.width) + x;
-      cv := (Random(100) Shl 16) Or (Random(100) Shl 8) Or Random(100);
+      cv := (Random(100) shl 16) or (Random(100) shl 8) or Random(100);
       d^ := cv;
-    End;
-  Finally
+    end;
+  finally
     surface.unlock;
-  End;
-  
+  end;
+
   { blur the surface }
-  For i := 1 To 5 Do
+  for i := 1 to 5 do
     blur(surface);
-  
+
   { multiply the color values }
   dest := surface.lock;
-  Try
-    For i := 0 To surface.width * surface.height - 1 Do
-    Begin
+  try
+    for i := 0 to surface.width * surface.height - 1 do
+    begin
       cv := dest^;
-      r := (cv Shr 16) And 255;
-      g := (cv Shr 8) And 255;
-      b := cv And 255;
-      r *= red_balance;
-      g *= green_balance;
-      b *= blue_balance;
-      If r > 255 Then
+      r := (cv shr 16) and 255;
+      g := (cv shr 8) and 255;
+      b := cv and 255;
+      r := r * red_balance;
+      g := g * green_balance;
+      b := b * blue_balance;
+      if r > 255 then
         r := 255;
-      If g > 255 Then
+      if g > 255 then
         g := 255;
-      If b > 255 Then
+      if b > 255 then
         b := 255;
-      dest^ := (r Shl 16) Or (g Shl 8) Or b;
+      dest^ := (r shl 16) or (g shl 8) or b;
       Inc(dest);
-    End;
-  Finally
+    end;
+  finally
     surface.unlock;
-  End;
-End;
-
-Procedure grid_map(grid : PUint32; xbase, ybase, xmove, ymove, amp : Single);
-
-Var
-  x, y : Integer;
-  a, b, id : Single;
-
-Begin
+  end;
+end;
+
+procedure grid_map(grid: PUint32; xbase, ybase, xmove, ymove, amp: Single);
+var
+  x, y: Integer;
+  a, b, id: Single;
+begin
   a := 0;
-  For y := 0 To 25 Do
-  Begin
+  for y := 0 to 25 do
+  begin
     b := 0;
-    For x := 0 To 40 Do
-    Begin
+    for x := 0 to 40 do
+    begin
       { it should be noted that there is no scientific basis for }
       { the following three lines :) }
       grid[0] := Uint32(Trunc((xbase * 14 + x*4 + xmove*sin(b)+sin(cos(a)*sin(amp))*15) * 65536));
       grid[1] := Uint32(Trunc((ybase * 31 + y*3 + ymove*cos(b)*sin(sin(a)*cos(amp))*30) * 65536));
       id := (cos(xbase) + sin(ybase) + cos(a*xmove*0.17) + sin(b*ymove*0.11)) * amp * 23;
-      If id < -127 Then
+      if id < -127 then
         grid[2] := 0
-      Else
-        If id > 127 Then
-	  grid[2] := 255 Shl 16
-	Else
-	  grid[2] := (128 Shl 16) + Trunc(id * 65536.0);
-      grid += 3;
-      b += pi / 30;
-    End;
-    a += pi / 34;
-  End;
-End;
-
-Procedure make_light_table(lighttable : PUint8);
-
-Var
-  i, j : Integer;
-  tv : Integer;
-
-Begin
-  For i := 0 To 255 Do
-    For j := 0 To 255 Do
-    Begin
+      else
+        if id > 127 then
+          grid[2] := 255 shl 16
+        else
+          grid[2] := (128 shl 16) + Trunc(id * 65536.0);
+      Inc(grid, 3);
+      b := b + pi / 30;
+    end;
+    a := a + pi / 34;
+  end;
+end;
+
+procedure make_light_table(lighttable: PUint8);
+var
+  i, j: Integer;
+  tv: Integer;
+begin
+  for i := 0 to 255 do
+    for j := 0 to 255 do
+    begin
       { light table goes from 0 to i*2. }
-      tv := (i * j) Div 128;
-      If tv > 255 Then
+      tv := (i * j) div 128;
+      if tv > 255 then
         tv := 255;
       lighttable[(j * 256) + i] := tv;
-    End;
-End;
+    end;
+end;
 
 { if you want to see how to do this properly, look at the tunnel3d demo. }
 { (not included in this distribution :) }
-Procedure texture_warp(dest, grid, texture : PUint32; lighttable : PUint8);
-
-Var
-  utl, utr, ubl, ubr : Integer;
-  vtl, vtr, vbl, vbr : Integer;
-  itl, itr, ibl, ibr : Integer;
-  dudx, dvdx, didx, dudy, dvdy, didy, ddudy, ddvdy, ddidy : Integer;
-  dudx2, dvdx2, didx2 : Integer;
-  bx, by, px, py : Integer;
-  uc, vc, ic, ucx, vcx, icx : Integer;
-  
-  edi : Uint32;
-  texel : Uint32;
-  
-  cbp, dp : PUint32;
-  dpix : Uint32;
-  
-  ltp : PUint8;
-
-Begin
+procedure texture_warp(dest, grid, texture: PUint32; lighttable: PUint8);
+var
+  utl, utr, ubl, ubr: Integer;
+  vtl, vtr, vbl, vbr: Integer;
+  itl, itr, ibl, ibr: Integer;
+  dudx, dvdx, didx, dudy, dvdy, didy, ddudy, ddvdy, ddidy: Integer;
+  dudx2, dvdx2, didx2: Integer;
+  bx, by, px, py: Integer;
+  uc, vc, ic, ucx, vcx, icx: Integer;
+
+  edi: Uint32;
+  texel: Uint32;
+
+  cbp, dp: PUint32;
+  dpix: Uint32;
+
+  ltp: PUint8;
+begin
   cbp := grid;
-  For by := 0 To 24 Do
-  Begin
-    For bx := 0 To 39 Do
-    Begin
+  for by := 0 to 24 do
+  begin
+    for bx := 0 to 39 do
+    begin
       utl := Integer(cbp^);
       vtl := Integer((cbp + 1)^);
       itl := Integer((cbp + 2)^);
@@ -207,87 +197,81 @@ Begin
       ubr := Integer((cbp + (42 * 3))^);
       vbr := Integer((cbp + (42 * 3) + 1)^);
       ibr := Integer((cbp + (42 * 3) + 2)^);
-      dudx := (utr - utl) Div 8;
-      dvdx := (vtr - vtl) Div 8;
-      didx := (itr - itl) Div 8;
-      dudx2 := (ubr - ubl) Div 8;
-      dvdx2 := (vbr - vbl) Div 8;
-      didx2 := (ibr - ibl) Div 8;
-      dudy := (ubl - utl) Div 8;
-      dvdy := (vbl - vtl) Div 8;
-      didy := (ibl - itl) Div 8;
-      ddudy := (dudx2 - dudx) Div 8;
-      ddvdy := (dvdx2 - dvdx) Div 8;
-      ddidy := (didx2 - didx) Div 8;
+      dudx := (utr - utl) div 8;
+      dvdx := (vtr - vtl) div 8;
+      didx := (itr - itl) div 8;
+      dudx2 := (ubr - ubl) div 8;
+      dvdx2 := (vbr - vbl) div 8;
+      didx2 := (ibr - ibl) div 8;
+      dudy := (ubl - utl) div 8;
+      dvdy := (vbl - vtl) div 8;
+      didy := (ibl - itl) div 8;
+      ddudy := (dudx2 - dudx) div 8;
+      ddvdy := (dvdx2 - dvdx) div 8;
+      ddidy := (didx2 - didx) div 8;
       uc := utl;
       vc := vtl;
       ic := itl;
-      For py := 0 To 7 Do
-      Begin
+      for py := 0 to 7 do
+      begin
         ucx := uc;
-	vcx := vc;
-	icx := ic;
-	dp := dest + (((by * 8 + py)*320) + (bx * 8));
-	For px := 0 To 7 Do
-	Begin
+        vcx := vc;
+        icx := ic;
+        dp := dest + (((by * 8 + py)*320) + (bx * 8));
+        for px := 0 to 7 do
+        begin
 
           { get light table pointer for current intensity }
-	  ltp := lighttable + ((icx And $FF0000) Shr 8);
+          ltp := lighttable + ((icx and $FF0000) shr 8);
 
           { get texel }
-	  edi := ((ucx And $FF0000) Shr 16) + ((vcx And $FF0000) Shr 8);
-	  texel := texture[edi];
-	  
+          edi := ((ucx and $FF0000) shr 16) + ((vcx and $FF0000) shr 8);
+          texel := texture[edi];
+
           { calculate actual colour }
-	  dpix := ltp[(texel Shr 16) And 255];
-	  dpix := dpix Shl 8;
-	  dpix := dpix Or ltp[(texel Shr 8) And 255];
-	  dpix := dpix Shl 8;
-	  dpix := dpix Or ltp[texel And 255];
-	  
-	  dp^ := dpix;
-	  Inc(dp);
-	  
-	  ucx += dudx;
-	  vcx += dvdx;
-	  icx += didx;
-	End;
-	uc += dudy;
-	vc += dvdy;
-	ic += didy;
-	dudx += ddudy;
-	dvdx += ddvdy;
-	didx += ddidy;
-      End;
-      cbp += 3;
-    End;
-    cbp += 3;
-  End;
-End;
-
-Var
-  format : TPTCFormat;
-  texture : TPTCSurface;
-  surface : TPTCSurface;
-  console : TPTCConsole;
-  lighttable : PUint8;
+          dpix := ltp[(texel shr 16) and 255];
+          dpix := dpix shl 8;
+          dpix := dpix or ltp[(texel shr 8) and 255];
+          dpix := dpix shl 8;
+          dpix := dpix or ltp[texel and 255];
+
+          dp^ := dpix;
+          Inc(dp);
+
+          Inc(ucx, dudx);
+          Inc(vcx, dvdx);
+          Inc(icx, didx);
+        end;
+        Inc(uc, dudy);
+        Inc(vc, dvdy);
+        Inc(ic, didy);
+        Inc(dudx, ddudy);
+        Inc(dvdx, ddvdy);
+        Inc(didx, ddidy);
+      end;
+      Inc(cbp, 3);
+    end;
+    Inc(cbp, 3);
+  end;
+end;
+
+var
+  format: TPTCFormat = nil;
+  texture: TPTCSurface = nil;
+  surface: TPTCSurface = nil;
+  console: TPTCConsole = nil;
+  lighttable: PUint8 = nil;
   { texture grid }
-  grid : Array[0..41*26*3-1] Of Uint32;
-  xbase, ybase, xmove, ymove, amp, dct, dxb, dyb, dxm, dym, sa : Single;
-  
-  p1, p2 : PUint32;
-
-Begin
-  format := Nil;
-  texture := Nil;
-  surface := Nil;
-  console := Nil;
-  lighttable := Nil;
-  Try
-    Try
+  grid: array [0..41*26*3-1] of Uint32;
+  xbase, ybase, xmove, ymove, amp, dct, dxb, dyb, dxm, dym, sa: Single;
+
+  p1, p2: PUint32;
+begin
+  try
+    try
       { create format }
       format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
-    
+
       { create texture surface }
       texture := TPTCSurface.Create(256, 256, format);
 
@@ -318,79 +302,78 @@ Begin
       dyb := -0.019;
       dxm := 0.015;
       dym := -0.0083;
-    
+
       { main loop }
-      While Not console.KeyPressed Do
-      Begin
-    
+      while not console.KeyPressed do
+      begin
+
         { create texture mapping grid }
         grid_map(grid, xbase, ybase, xmove, ymove*3, amp);
 
         p1 := surface.lock;
-	Try
-	  p2 := texture.lock;
-	  Try
+        try
+          p2 := texture.lock;
+          try
             { map texture to drawing surface }
             texture_warp(p1, grid, p2, lighttable);
-	  Finally
+          finally
             texture.unlock;
-	  End;
-	Finally
+          end;
+        finally
           surface.unlock;
-	End;
+        end;
 
         { copy surface to console }
         surface.copy(console);
 
         { update console }
         console.update;
-      
+
         { move control values (limit them so it doesn't go too far) }
-        xbase += dxb;
-        If xbase > pi Then
+        xbase := xbase + dxb;
+        if xbase > pi then
           dxb := -dxb;
-        If xbase < (-pi) Then
+        if xbase < (-pi) then
           dxb := -dxb;
-      
-        ybase += dyb;
-        If ybase > pi Then
+
+        ybase := ybase + dyb;
+        if ybase > pi then
           dyb := -dyb;
-        If ybase < (-pi) Then
+        if ybase < (-pi) then
           dyb := -dyb;
-      
-        xmove += dxm;
-        If xmove > pi Then
+
+        xmove := xmove + dxm;
+        if xmove > pi then
           dxm := -dxm;
-        If xmove < (-pi) Then
+        if xmove < (-pi) then
           dxm := -dxm;
-      
-        ymove += dym;
-        If ymove > pi Then
+
+        ymove := ymove + dym;
+        if ymove > pi then
           dym := -dym;
-        If ymove < (-pi) Then
+        if ymove < (-pi) then
           dym := -dym;
-      
-        amp += dct;
+
+        amp := amp + dct;
         sa := sin(amp);
-        If (sa > -0.0001) And (sa < 0.0001) Then
-        Begin
-          If amp > 8.457547 Then
-	    dct := -dct;
-	  If amp < -5.365735 Then
-	    dct := -dct;
-        End;
-      End;
-    Finally
+        if (sa > -0.0001) and (sa < 0.0001) then
+        begin
+          if amp > 8.457547 then
+            dct := -dct;
+          if amp < -5.365735 then
+            dct := -dct;
+        end;
+      end;
+    finally
       console.close;
       console.Free;
       surface.Free;
       texture.Free;
       format.Free;
-      If assigned(lighttable) Then
-        FreeMem(lighttable);
-    End;
-  Except
-    On e : TPTCError Do
+      FreeMem(lighttable);
+    end;
+  except
+    on e: TPTCError do
       e.report;
-  End;
-End.
+  end;
+end.

+ 36 - 41
packages/ptc/examples/timer.pp

@@ -3,36 +3,31 @@ Ported to FPC by Nikolay Nikolov ([email protected])
 }
 
 {
- Timer example for OpenPTC 1.0 C++ Implementation
+ Timer example for OpenPTC 1.0 C++ implementation
  Copyright (c) Glenn Fiedler ([email protected])
  This source code is in the public domain
 }
 
-Program TimerExample;
+program TimerExample;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc;
 
-Var
-  console : TPTCConsole;
-  format : TPTCFormat;
-  surface : TPTCSurface;
-  timer : TPTCTimer;
-  time, t : Double;
-  pixels : PDWord;
-  width, height : Integer;
-  repeats, center, magnitude, intensity, sx : Single;
-  x, y : Integer;
-
-Begin
-  timer := Nil;
-  format := Nil;
-  surface := Nil;
-  console := Nil;
-  Try
-    Try
+var
+  console: TPTCConsole = nil;
+  format: TPTCFormat = nil;
+  surface: TPTCSurface = nil;
+  timer: TPTCTimer = nil;
+  time, t: Double;
+  pixels: PDWord;
+  width, height: Integer;
+  repeats, center, magnitude, intensity, sx: Single;
+  x, y: Integer;
+begin
+  try
+    try
       { create console }
       console := TPTCConsole.Create;
 
@@ -52,8 +47,8 @@ Begin
       timer.start;
 
       { loop until a key is pressed }
-      While Not console.KeyPressed Do
-      Begin
+      while not console.KeyPressed do
+      begin
         { get current time from timer }
         time := timer.time;
 
@@ -62,7 +57,7 @@ Begin
 
         { lock surface }
         pixels := surface.lock;
-        Try
+        try
           { get surface dimensions }
           width := surface.width;
           height := surface.height;
@@ -73,44 +68,44 @@ Begin
           magnitude := height / 3;
 
           { render a sine curve }
-          For x := 0 To width - 1 Do
-          Begin
+          for x := 0 to width - 1 do
+          begin
             { rescale 'x' in the range [0,2*pi] }
-	    sx := x / width * 2 * pi;
+            sx := x / width * 2 * pi;
 
             { calculate time at current position }
-	    t := time + sx * repeats;
+            t := time + sx * repeats;
 
             { lookup sine intensity at time 't' }
-	    intensity := sin(t);
+            intensity := sin(t);
 
             { convert intensity to a y position on the surface }
-	    y := Trunc(center + intensity * magnitude);
+            y := Trunc(center + intensity * magnitude);
 
             { plot pixel on sine curve }
-	    pixels[x + y * width] := $000000FF;
-          End;
-        Finally
+            pixels[x + y * width] := $000000FF;
+          end;
+        finally
           { unlock surface }
           surface.unlock;
-	End;
+        end;
 
         { copy to console }
         surface.copy(console);
 
         { update console }
         console.update;
-      End;
-    Finally
+      end;
+    finally
       timer.Free;
       surface.Free;
       console.close;
       console.Free;
       format.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 80 - 96
packages/ptc/examples/tunnel.pp

@@ -9,68 +9,59 @@ Ported to FPC by Nikolay Nikolov ([email protected])
  This source code is licensed under the GNU GPL
 }
 
-Program Tunnel;
+program Tunnel;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc, Math;
 
-Type
+type
   { tunnel class }
-  TTunnel = Class(TObject)
-    Public
-    Constructor Create;
-    Destructor Destroy; Override;
-    Procedure setup;
-    Procedure draw(buffer : PUint32; t : Single);
-    Private
+  TTunnel = class
+    public
+    constructor Create;
+    destructor Destroy; override;
+    procedure setup;
+    procedure draw(buffer: PUint32; t: Single);
+    private
     { tunnel data }
-    tunnel : PUint32;
-    texture : PUint8;
-  End;
+    tunnel: PUint32;
+    texture: PUint8;
+  end;
 
-Constructor TTunnel.Create;
-
-Begin
-  tunnel := Nil;
-  texture := Nil;
-  
+constructor TTunnel.Create;
+begin
   { allocate tables }
   tunnel := GetMem(320*200*SizeOf(Uint32));
   texture := GetMem(256*256*2*SizeOf(Uint8));
 
   { setup }
   setup;
-End;
-
-Destructor TTunnel.Destroy;
+end;
 
-Begin
+destructor TTunnel.Destroy;
+begin
   { free tables }
-  If assigned(tunnel) Then
-    FreeMem(tunnel);
-  If assigned(texture) Then
-    FreeMem(texture);
-  
-  Inherited Destroy;
-End;
-
-Procedure TTunnel.setup;
-
-Var
-  index : Integer;
-  x, y : Integer;
-  angle, angle1, angle2, radius, u, v : Double;
-
-Begin
+  FreeMem(tunnel);
+  FreeMem(texture);
+
+  inherited Destroy;
+end;
+
+procedure TTunnel.setup;
+var
+  index: Integer;
+  x, y: Integer;
+  angle, angle1, angle2, radius, u, v: Double;
+begin
   { tunnel index }
   index := 0;
-  
+
   { generate tunnel table }
-  For y := 100 DownTo -99 Do
-    For x := -160 To 159 Do
-    Begin
+  for y := 100 DownTo -99 do
+    for x := -160 to 159 do
+    begin
       { calculate angle from center }
       angle := arctan2(y, x) * 256 / pi / 2;
 
@@ -78,70 +69,63 @@ Begin
       radius := sqrt(x * x + y * y);
 
       { clamp radius to minimum }
-      If radius < 1 Then
-	radius := 1;
+      if radius < 1 then
+        radius := 1;
 
       { texture coordinates }
       u := angle;
       v := 6000 / radius;
 
       { calculate texture index for (u,v) }
-      tunnel[index] := (Trunc(v) And $FF) * 256 + (Trunc(u) And $FF);
+      tunnel[index] := (Trunc(v) and $FF) * 256 + (Trunc(u) and $FF);
       Inc(index);
-    End;
+    end;
 
   { generate blue plasma texture }
   index := 0;
   angle2 := pi * 2/256 * 230;
-  For y := 0 To 256 * 2 - 1 Do
-  Begin
+  for y := 0 to 256 * 2 - 1 do
+  begin
     angle1 := pi * 2/256 * 100;
-    For x := 0 To 256-1 Do
-    Begin
+    for x := 0 to 256-1 do
+    begin
       texture[index] := Trunc(sin(angle1)*80 + sin(angle2)*40 + 128);
       angle1 := angle1 + pi*2/256*3;
       Inc(index);
-    End;
+    end;
     angle2 := angle2 + pi * 2/256 *2;
-  End;
-End;
-
-Procedure TTunnel.draw(buffer : PUint32; t : Single);
-
-Var
-  x, y : Integer;
-  scroll : Uint32;
-  i : Integer;
-
-Begin
+  end;
+end;
+
+procedure TTunnel.draw(buffer: PUint32; t: Single);
+var
+  x, y: Integer;
+  scroll: Uint32;
+  i: Integer;
+begin
   { tunnel control functions }
   x := Trunc(sin(t) * 99.9);
   y := Trunc(t * 200);
 
   { calculate tunnel scroll offset }
-  scroll := ((y And $FF) Shl 8) + (x And $FF);
+  scroll := ((y and $FF) shl 8) + (x and $FF);
 
   { loop through each pixel }
-  For i := 0 To 64000-1 Do
+  for i := 0 to 64000-1 do
     { lookup tunnel texture }
     buffer[i] := texture[tunnel[i] + scroll];
-End;
-
-Var
-  format : TPTCFormat;
-  console : TPTCConsole;
-  surface : TPTCSurface;
-  TheTunnel : TTunnel;
-  time, delta : Single;
-  buffer : PUint32;
-
-Begin
-  format := Nil;
-  surface := Nil;
-  console := Nil;
-  TheTunnel := Nil;
-  Try
-    Try
+end;
+
+var
+  format: TPTCFormat = nil;
+  console: TPTCConsole = nil;
+  surface: TPTCSurface = nil;
+  TheTunnel: TTunnel = nil;
+  time, delta: Single;
+  buffer: PUint32;
+begin
+  try
+    try
       { create format }
       format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
 
@@ -153,7 +137,7 @@ Begin
 
       { create surface }
       surface := TPTCSurface.Create(320, 200, format);
-    
+
       { create tunnel }
       TheTunnel := TTunnel.Create;
 
@@ -162,17 +146,17 @@ Begin
       delta := 0.03;
 
       { loop until a key is pressed }
-      While Not console.KeyPressed Do
-      Begin
+      while not console.KeyPressed do
+      begin
         { lock surface }
         buffer := surface.lock;
-	Try
+        try
           { draw tunnel }
           TheTunnel.draw(buffer, time);
-	Finally
+        finally
           { unlock surface }
           surface.unlock;
-	End;
+        end;
 
         { copy to console }
         surface.copy(console);
@@ -181,18 +165,18 @@ Begin
         console.update;
 
         { update time }
-        time += delta;
-      End;
-    Finally
+        time := time + delta;
+      end;
+    finally
       TheTunnel.Free;
       surface.Free;
       console.close;
       console.Free;
       format.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       { report error }
       error.report;
-  End;
-End.
+  end;
+end.

+ 310 - 355
packages/ptc/examples/tunnel3d.pp

@@ -9,20 +9,20 @@ Ported to FPC by Nikolay Nikolov ([email protected])
  Copyright (c) 1998 Christian Nentwich ([email protected])
  This source code is licensed under the GNU LGPL
 
- And do not just blatantly cut&paste this into your demo :)
+ and do not just blatantly cut&paste this into your demo :)
 }
 
-Program Tunnel3D;
+program Tunnel3D;
 
 {$MODE objfpc}
 
-Uses
+uses
   ptc, Math;
 
-Type
+type
   PVector = ^TVector;
-  TVector = Array[0..2] Of Single;      { X,Y,Z }
-  TMatrix = Array[0..3, 0..3] Of Single;{ FIRST  = COLUMN
+  TVector = array [0..2] of Single;      { X,Y,Z }
+  TMatrix = array [0..3, 0..3] of Single;{ FIRST  = COLUMN
                                           SECOND = ROW
 
                                           [0, 0]  [1, 0]  [2, 0]
@@ -31,116 +31,108 @@ Type
   (I know the matrices are the wrong way round, so what, the code is quite
   old :) }
 
-  TRayTunnel = Class(TObject)
-  Private
-    tunneltex : PUint8;                      { Texture }
-    pal : PUint8;                            { Original palette }
-    lookup : PUint32;                         { Lookup table for lighting }
+  TRayTunnel = class
+  private
+    tunneltex: PUint8;                      { Texture }
+    tunneltex_orig: PUint8;                 { Original start of texture memory block }
+    pal: PUint8;                            { Original palette }
+    lookup: PUint32;                         { Lookup table for lighting }
 
-    sintab, costab : PSingle;                { Take a guess }
+    sintab, costab: PSingle;                { Take a guess }
 
-    u_array, v_array, l_array : PInteger;    { Raytraced coordinates and light }
-    norms : PVector;
+    u_array, v_array, l_array: PInteger;    { Raytraced coordinates and light }
+    norms: PVector;
 
-    radius, radius_sqr : Single;
-    rot : TMatrix;
+    radius, radius_sqr: Single;
+    rot: TMatrix;
 
-    pos, light : TVector;                    { Position in the tunnel, pos of }
-    xa, ya, za : Integer;                    { lightsource, angles }
+    pos, light: TVector;                    { Position in the tunnel, pos of }
+    xa, ya, za: Integer;                    { lightsource, angles }
 
-    lightstatus : Boolean;                   { Following the viewer ? }
+    lightstatus: Boolean;                   { Following the viewer ? }
 
-  Public
-    Constructor Create(rad : Single);        { Constructor takes the radius }
-    Destructor Destroy; Override;
+  public
+    constructor Create(rad: Single);        { constructor takes the radius }
+    destructor Destroy; override;
 
-    Procedure load_texture;
+    procedure load_texture;
 
-    Procedure tilt(x, y, z : Integer);              { Rotate relative }
-    Procedure tilt(x, y, z : Integer; abs : Uint8); { Absolute }
+    procedure tilt(x, y, z: Integer);              { Rotate relative }
+    procedure tilt(x, y, z: Integer; abs: Uint8); { Absolute }
 
-    Procedure move(dx, dy, dz : Single);            { Relative move }
-    Procedure move(x, y, z : Single; abs : Uint8);  { Absolute }
+    procedure move(dx, dy, dz: Single);            { Relative move }
+    procedure move(x, y, z: Single; abs: Uint8);  { Absolute }
 
-    Procedure movelight(dx, dy, dz : Single);
-    Procedure movelight(x, y, z : Single; abs : Uint8);
+    procedure movelight(dx, dy, dz: Single);
+    procedure movelight(x, y, z: Single; abs: Uint8);
 
-    Procedure locklight(lock : Boolean);    { Make the light follow the viewer }
+    procedure locklight(lock: Boolean);    { Make the light follow the viewer }
 
-    Procedure interpolate;                  { Raytracing }
+    procedure interpolate;                  { Raytracing }
 
-    Procedure draw(dest : PUint32);          { Draw the finished tunnel }
-  End;
+    procedure draw(dest: PUint32);          { Draw the finished tunnel }
+  end;
 
 { VECTOR ROUTINES }
-Procedure vector_normalize(Var v : TVector);
-
-Var
-  length : Single;
-
-Begin
+procedure vector_normalize(var v: TVector);
+var
+  length: Single;
+begin
   length := v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
   length := sqrt(length);
-  If length <> 0 Then
-  Begin
+  if length <> 0 then
+  begin
     v[0] := v[0] / length;
     v[1] := v[1] / length;
     v[2] := v[2] / length;
-  End
-  Else
-  Begin
+  end
+  else
+  begin
     v[0] := 0;
     v[1] := 0;
     v[2] := 0;
-  End;
-End;
-
-Procedure vector_times_matrix(Const v : TVector; Const m : TMatrix;
-                              Var res : TVector);
-
-Var
-  i, j : Integer;
-
-Begin
-  For j := 0 To 2 Do
-  Begin
+  end;
+end;
+
+procedure vector_times_matrix(const v: TVector; const m: TMatrix;
+                              var res: TVector);
+var
+  i, j: Integer;
+begin
+  for j := 0 to 2 do
+  begin
     res[j] := 0;
-    For i := 0 To 2 Do
+    for i := 0 to 2 do
       res[j] := res[j] + (m[j, i] * v[i]);
-  End;
-End;
-
-Procedure matrix_idle(Var m : TMatrix);
+  end;
+end;
 
-Begin
+procedure matrix_idle(var m: TMatrix);
+begin
   FillChar(m, SizeOf(TMatrix), 0);
   m[0, 0] := 1;
   m[1, 1] := 1;
   m[2, 2] := 1;
   m[3, 3] := 1;
-End;
-
-Procedure matrix_times_matrix(Const m1, m2 : TMatrix; Var res : TMatrix);
-
-Var
-  i, j, k : Integer;
-
-Begin
-  For j := 0 To 3 Do
-    For i := 0 To 3 Do
-    Begin
+end;
+
+procedure matrix_times_matrix(const m1, m2: TMatrix; var res: TMatrix);
+var
+  i, j, k: Integer;
+begin
+  for j := 0 to 3 do
+    for i := 0 to 3 do
+    begin
       res[i, j] := 0;
-      For k := 0 To 3 Do
+      for k := 0 to 3 do
         res[i, j] := res[i, j] + (m1[k, j] * m2[i, k]);
-    End;
-End;
-
-Procedure matrix_rotate_x(Var m : TMatrix; angle : Integer; sintab, costab : PSingle);
+    end;
+end;
 
-Var
-  tmp, tmp2 : TMatrix;
-
-Begin
+procedure matrix_rotate_x(var m: TMatrix; angle: Integer; sintab, costab: PSingle);
+var
+  tmp, tmp2: TMatrix;
+begin
   matrix_idle(tmp);
   tmp[1, 1] := costab[angle];
   tmp[2, 1] := sintab[angle];
@@ -148,14 +140,12 @@ Begin
   tmp[2, 2] := costab[angle];
   matrix_times_matrix(tmp, m, tmp2);
   Move(tmp2, m, SizeOf(TMatrix));
-End;
-
-Procedure matrix_rotate_y(Var m : TMatrix; angle : Integer; sintab, costab : PSingle);
+end;
 
-Var
-  tmp, tmp2 : TMatrix;
-
-Begin
+procedure matrix_rotate_y(var m: TMatrix; angle: Integer; sintab, costab: PSingle);
+var
+  tmp, tmp2: TMatrix;
+begin
   matrix_idle(tmp);
   tmp[0, 0] := costab[angle];
   tmp[2, 0] := -sintab[angle];
@@ -163,14 +153,12 @@ Begin
   tmp[2, 2] := costab[angle];
   matrix_times_matrix(tmp, m, tmp2);
   Move(tmp2, m, SizeOf(TMatrix));
-End;
-
-Procedure matrix_rotate_z(Var m : TMatrix; angle : Integer; sintab, costab : PSingle);
-
-Var
-  tmp, tmp2 : TMatrix;
+end;
 
-Begin
+procedure matrix_rotate_z(var m: TMatrix; angle: Integer; sintab, costab: PSingle);
+var
+  tmp, tmp2: TMatrix;
+begin
   matrix_idle(tmp);
   tmp[0, 0] := costab[angle];
   tmp[1, 0] := sintab[angle];
@@ -178,25 +166,14 @@ Begin
   tmp[1, 1] := costab[angle];
   matrix_times_matrix(tmp, m, tmp2);
   Move(tmp2, m, SizeOf(TMatrix));
-End;
-
-Constructor TRayTunnel.Create(rad : Single);
-
-Var
-  x, y : Single;
-  i, j : Integer;
-  tmp : TVector;
-
-Begin
-  tunneltex := Nil;
-  sintab := Nil;
-  costab := Nil;
-  u_array := Nil;
-  v_array := Nil;
-  norms := Nil;
-  lookup := Nil;
-  pal := Nil;
-
+end;
+
+constructor TRayTunnel.Create(rad: Single);
+var
+  x, y: Single;
+  i, j: Integer;
+  tmp: TVector;
+begin
   radius := rad;
   radius_sqr := rad * rad;
 
@@ -210,28 +187,28 @@ Begin
   lookup := GetMem(65 * 256 * SizeOf(Uint32));
   pal := GetMem(768 * SizeOf(Uint8));
 
-  For i := 0 To 1023 Do
-  Begin
+  for i := 0 to 1023 do
+  begin
     sintab[i] := sin(i * pi / 512);
     costab[i] := cos(i * pi / 512);
-  End;
+  end;
 
   { Generate normal vectors }
   y := -100;
-  For j := 0 To 25 Do
-  Begin
+  for j := 0 to 25 do
+  begin
     x := -160;
-    For i := 0 To 40 Do
-    Begin
+    for i := 0 to 40 do
+    begin
       tmp[0] := x;
       tmp[1] := y;
       tmp[2] := 128;
       vector_normalize(tmp);
       norms[j * 64 + i] := tmp;
       x := x + 8;
-    End;
+    end;
     y := y + 8;
-  End;
+  end;
 
   { Reset tunnel and light position and all angles }
   pos[0] := 0; pos[1] := 0; pos[2] := 0;
@@ -243,127 +220,119 @@ Begin
 
   { Normalize light vector to length 1.0 }
   vector_normalize(light);
-End;
-
-Destructor TRayTunnel.Destroy;
-
-Begin
-  If Assigned(tunneltex) Then
-    FreeMem(tunneltex);
-  If Assigned(pal) Then
-    FreeMem(pal);
-  If Assigned(lookup) Then
-    FreeMem(lookup);
-  If Assigned(norms) Then
-    FreeMem(norms);
-  If Assigned(l_array) Then
-    FreeMem(l_array);
-  If Assigned(v_array) Then
-    FreeMem(v_array);
-  If Assigned(u_array) Then
-    FreeMem(u_array);
-  If Assigned(costab) Then
-    FreeMem(costab);
-  If Assigned(sintab) Then
-    FreeMem(sintab);
-End;
-
-Procedure TRayTunnel.load_texture;
-
-Var
-  texfile : File;
-  tmp : PUint8;
-  i, j : Uint32;
-  r, g, b : Uint32;
-  newoffs : Integer;
-
-Begin
-  { Allocate tunnel texture 65536+33 bytes too big }
-
-  If tunneltex <> Nil Then
-  Begin
-    FreeMem(tunneltex);
-    tunneltex := Nil;
-  End;
-  tunneltex := GetMem(2*65536 + 33);
-  tmp := GetMem(65536);
-
-  { Align the texture on a 64k boundary }
-  While (PtrUInt(tunneltex) And $FFFF) <> 0 Do
-    Inc(tunneltex);
-
-  ASSign(texfile, 'tunnel3d.raw');
-  Reset(texfile, 1);
-  BlockRead(texfile, pal^, 768);
-  BlockRead(texfile, tmp^, 65536);
-  Close(texfile);
-
-  { Generate lookup table for lighting (65 because of possible inaccuracies) }
-
-  For j := 0 To 64 Do
-    For i := 0 To 255 Do
-    Begin
-      r := pal[i * 3] Shl 2;
-      g := pal[i * 3 + 1] Shl 2;
-      b := pal[i * 3 + 2] Shl 2;
-      r := (r * j) Shr 6;
-      g := (g * j) Shr 6;
-      b := (b * j) Shr 6;
-      If r > 255 Then
-        r := 255;
-      If g > 255 Then
-        g := 255;
-      If b > 255 Then
-        b := 255;
-      lookup[j * 256 + i] := (r Shl 16) Or (g Shl 8) Or b;
-    End;
-
-  { Arrange texture for cache optimised mapping }
-
-  For j := 0 To 255 Do
-    For i := 0 To 255 Do
-    Begin
-      newoffs := ((i Shl 8) And $F800) + (i And $0007) + ((j Shl 3) And $7F8);
-      (tunneltex + newoffs)^ := (tmp + j * 256 + i)^;
-    End;
-
-  FreeMem(tmp);
-End;
-
-Procedure TRayTunnel.interpolate;
-
-Var
-  ray, intsc, norm, lvec : TVector;
-  x, y, a, b, c, discr, t, res : Single;
-  i, j : Integer;
-
-Begin
-  If lightstatus Then { Lightsource locked to viewpoint }
+end;
+
+destructor TRayTunnel.Destroy;
+begin
+  FreeMem(tunneltex_orig);
+  FreeMem(pal);
+  FreeMem(lookup);
+  FreeMem(norms);
+  FreeMem(l_array);
+  FreeMem(v_array);
+  FreeMem(u_array);
+  FreeMem(costab);
+  FreeMem(sintab);
+end;
+
+procedure TRayTunnel.load_texture;
+var
+  texfile: File;
+  tmp: PUint8 = nil;
+  i, j: Uint32;
+  r, g, b: Uint32;
+  newoffs: Integer;
+begin
+  try
+    { Allocate tunnel texture 65536+33 bytes too big }
+
+    if tunneltex_orig <> nil then
+    begin
+      FreeMem(tunneltex_orig);
+      tunneltex_orig := nil;
+    end;
+    tunneltex_orig := GetMem(2*65536 + 33);
+    tmp := GetMem(65536);
+
+    { Align the texture on a 64k boundary }
+    tunneltex := tunneltex_orig;
+    while (PtrUInt(tunneltex) and $FFFF) <> 0 do
+      Inc(tunneltex);
+
+    AssignFile(texfile, 'tunnel3d.raw');
+    Reset(texfile, 1);
+    try
+      BlockRead(texfile, pal^, 768);
+      BlockRead(texfile, tmp^, 65536);
+    finally
+      CloseFile(texfile);
+    end;
+
+    { Generate lookup table for lighting (65 because of possible inaccuracies) }
+
+    for j := 0 to 64 do
+      for i := 0 to 255 do
+      begin
+        r := pal[i * 3] shl 2;
+        g := pal[i * 3 + 1] shl 2;
+        b := pal[i * 3 + 2] shl 2;
+        r := (r * j) shr 6;
+        g := (g * j) shr 6;
+        b := (b * j) shr 6;
+        if r > 255 then
+          r := 255;
+        if g > 255 then
+          g := 255;
+        if b > 255 then
+          b := 255;
+        lookup[j * 256 + i] := (r shl 16) or (g shl 8) or b;
+      end;
+
+    { Arrange texture for cache optimised mapping }
+
+    for j := 0 to 255 do
+      for i := 0 to 255 do
+      begin
+        newoffs := ((i shl 8) and $F800) + (i and $0007) + ((j shl 3) and $7F8);
+        (tunneltex + newoffs)^ := (tmp + j * 256 + i)^;
+      end;
+  finally
+    FreeMem(tmp);
+  end;
+end;
+
+procedure TRayTunnel.interpolate;
+var
+  ray, intsc, norm, lvec: TVector;
+  x, y, a, b, c, discr, t, res: Single;
+  i, j: Integer;
+begin
+  if lightstatus then { Lightsource locked to viewpoint }
     light := pos;
 
   matrix_idle(rot);
-  matrix_rotate_x(rot, xa And $3FF, sintab, costab);
-  matrix_rotate_y(rot, ya And $3FF, sintab, costab);
-  matrix_rotate_z(rot, za And $3FF, sintab, costab);
+  matrix_rotate_x(rot, xa and $3FF, sintab, costab);
+  matrix_rotate_y(rot, ya and $3FF, sintab, costab);
+  matrix_rotate_z(rot, za and $3FF, sintab, costab);
 
   { Constant factor }
   c := 2 * (pos[0] * pos[0] + pos[1] * pos[1] - radius_sqr);
 
   { Start raytracing }
   y := -100;
-  For j := 0 To 25 Do
-  Begin
+  for j := 0 to 25 do
+  begin
     x := -160;
-    For i := 0 To 40 Do
-    Begin
-      vector_times_matrix(norms[(j Shl 6) + i], rot, ray);
+    for i := 0 to 40 do
+    begin
+      vector_times_matrix(norms[(j shl 6) + i], rot, ray);
 
       a := 2 * (ray[0] * ray[0] + ray[1] * ray[1]);
       b := 2 * (pos[0] * ray[0] + pos[1] * ray[1]);
 
       discr := b * b - a * c;
-      If discr > 0 Then
-      Begin
+      if discr > 0 then
+      begin
         discr := sqrt(discr);
         t := (- b + discr) / a;
 
@@ -373,9 +342,9 @@ Begin
         intsc[2] := pos[2] + t * ray[2];
 
         { Calculate texture index at intersection point (cylindrical mapping) }
-        { Try and adjust the 0.2 to stretch/shrink the texture }
-        u_array[(j Shl 6) + i] := Trunc(intsc[2] * 0.2) Shl 16;
-        v_array[(j Shl 6) + i] := Trunc(abs(arctan2(intsc[1], intsc[0]) * 256 / pi)) Shl 16;
+        { try and adjust the 0.2 to stretch/shrink the texture }
+        u_array[(j shl 6) + i] := Trunc(intsc[2] * 0.2) shl 16;
+        v_array[(j shl 6) + i] := Trunc(abs(arctan2(intsc[1], intsc[0]) * 256 / pi)) shl 16;
 
         { Calculate the dotproduct between the normal vector and the vector }
         { from the intersection point to the lightsource }
@@ -391,172 +360,158 @@ Begin
         res := lvec[0] * norm[0] + lvec[1] * norm[1] + lvec[2] * norm[2];
 
         { Scale the light a bit }
-        res *= res;
-        If res < 0 Then
+        res := Sqr(res);
+        if res < 0 then
           res := 0;
-        If res > 1 Then
+        if res > 1 then
           res := 1;
-        res *= 63;
+        res := res * 63;
 
         { Put it into the light array }
-        l_array[(j Shl 6) + i] := Trunc(res) Shl 16;
-      End
-      Else
-      Begin
-        u_array[(j Shl 6) + i] := 0;
-        v_array[(j Shl 6) + i] := 0;
-        l_array[(j Shl 6) + i] := 0;
-      End;
+        l_array[(j shl 6) + i] := Trunc(res) shl 16;
+      end
+      else
+      begin
+        u_array[(j shl 6) + i] := 0;
+        v_array[(j shl 6) + i] := 0;
+        l_array[(j shl 6) + i] := 0;
+      end;
       x := x + 8;
-    End;
+    end;
     y := y + 8;
-  End;
-End;
-
-Procedure TRayTunnel.draw(dest : PUint32);
-
-Var
-  x, y, lu, lv, ru, rv, liu, liv, riu, riv : Integer;
-  iu, iv, i, j, ll, rl, lil, ril, l, il : Integer;
-  iadr, adr, til_u, til_v, til_iu, til_iv : DWord;
-  bla : Uint8;
-
-Begin
-  For j := 0 To 24 Do
-    For i := 0 To 39 Do
-    Begin
-      iadr := (j Shl 6) + i;
+  end;
+end;
+
+procedure TRayTunnel.draw(dest: PUint32);
+var
+  x, y, lu, lv, ru, rv, liu, liv, riu, riv: Integer;
+  iu, iv, i, j, ll, rl, lil, ril, l, il: Integer;
+  iadr, adr, til_u, til_v, til_iu, til_iv: DWord;
+  bla: Uint8;
+begin
+  for j := 0 to 24 do
+    for i := 0 to 39 do
+    begin
+      iadr := (j shl 6) + i;
 
       { Set up gradients }
       lu := u_array[iadr]; ru := u_array[iadr + 1];
-      liu := (u_array[iadr + 64] - lu) Shr 3;
-      riu := (u_array[iadr + 65] - ru) Shr 3;
+      liu := (u_array[iadr + 64] - lu) shr 3;
+      riu := (u_array[iadr + 65] - ru) shr 3;
 
       lv := v_array[iadr]; rv := v_array[iadr + 1];
-      liv := (v_array[iadr + 64] - lv) Shr 3;
-      riv := (v_array[iadr + 65] - rv) Shr 3;
+      liv := (v_array[iadr + 64] - lv) shr 3;
+      riv := (v_array[iadr + 65] - rv) shr 3;
 
       ll := l_array[iadr]; rl := l_array[iadr + 1];
-      lil := (l_array[iadr + 64] - ll) Shr 3;
-      ril := (l_array[iadr + 65] - rl) Shr 3;
+      lil := (l_array[iadr + 64] - ll) shr 3;
+      ril := (l_array[iadr + 65] - rl) shr 3;
 
-      For y := 0 To 7 Do
-      Begin
-        iu := (ru - lu) Shr 3;
-        iv := (rv - lv) Shr 3;
+      for y := 0 to 7 do
+      begin
+        iu := (ru - lu) shr 3;
+        iv := (rv - lv) shr 3;
         l := ll;
-        il := (rl - ll) Shr 3;
+        il := (rl - ll) shr 3;
 
         { Mess up everything for the sake of cache optimised mapping :) }
-        til_u := DWord(((lu Shl 8) And $F8000000) Or ((lu Shr 1) And $00007FFF) Or (lu And $00070000));
-        til_v := DWord(((lv Shl 3) And $07F80000) Or ((lv Shr 1) And $00007FFF));
-        til_iu := DWord((((iu Shl 8) And $F8000000) Or ((iu Shr 1) And $00007FFF) Or
-                          (iu And $00070000)) Or $07F88000);
-        til_iv := DWord((((iv Shl 3) And $07F80000) Or ((iv Shr 1) And $00007FFF)) Or $F8078000);
+        til_u := DWord(((lu shl 8) and $F8000000) or ((lu shr 1) and $00007FFF) or (lu and $00070000));
+        til_v := DWord(((lv shl 3) and $07F80000) or ((lv shr 1) and $00007FFF));
+        til_iu := DWord((((iu shl 8) and $F8000000) or ((iu shr 1) and $00007FFF) or
+                          (iu and $00070000)) or $07F88000);
+        til_iv := DWord((((iv shl 3) and $07F80000) or ((iv shr 1) and $00007FFF)) or $F8078000);
 
         adr := til_u + til_v;
 
-        For x := 0 To 7 Do
-        Begin
+        for x := 0 to 7 do
+        begin
           { Interpolate texture u,v and light }
-	  Inc(til_u, til_iu);
-	  Inc(til_v, til_iv);
+          Inc(til_u, til_iu);
+          Inc(til_v, til_iv);
           Inc(l, il);
 
-          adr := adr Shr 16;
+          adr := adr shr 16;
 
-          til_u := til_u And DWord($F8077FFF);
-          til_v := til_v And $07F87FFF;
+          til_u := til_u and DWord($F8077FFF);
+          til_v := til_v and $07F87FFF;
 
           bla := (tunneltex + adr)^;
 
           adr := til_u + til_v;
 
           { Look up the light and write to buffer }
-          (dest + ((j Shl 3) + y) * 320 + (I Shl 3) + x)^ := lookup[((l And $3F0000) Shr 8) + bla];
-        End;
+          (dest + ((j shl 3) + y) * 320 + (I shl 3) + x)^ := lookup[((l and $3F0000) shr 8) + bla];
+        end;
 
         Inc(lu, liu); Inc(ru, riu);
         Inc(lv, liv); Inc(rv, riv);
         Inc(ll, lil); Inc(rl, ril);
-      End;
-    End;
-End;
+      end;
+    end;
+end;
 
 { tilt rotates the viewer in the tunnel in a relative / absolute way }
-Procedure TRayTunnel.tilt(x, y, z : Integer);
-
-Begin
-  xa := (xa + x) And $3FF;
-  ya := (ya + y) And $3FF;
-  za := (za + z) And $3FF;
-End;
-
-Procedure TRayTunnel.tilt(x, y, z : Integer; abs : Uint8);
-
-Begin
-  xa := x And $3FF;
-  ya := y And $3FF;
-  za := z And $3FF;
-End;
+procedure TRayTunnel.tilt(x, y, z: Integer);
+begin
+  xa := (xa + x) and $3FF;
+  ya := (ya + y) and $3FF;
+  za := (za + z) and $3FF;
+end;
+
+procedure TRayTunnel.tilt(x, y, z: Integer; abs: Uint8);
+begin
+  xa := x and $3FF;
+  ya := y and $3FF;
+  za := z and $3FF;
+end;
 
 { Relative / absolute move }
-Procedure TRayTunnel.move(dx, dy, dz : Single);
-
-Begin
+procedure TRayTunnel.move(dx, dy, dz: Single);
+begin
   pos[0] := pos[0] + dx;
   pos[1] := pos[1] + dy;
   pos[2] := pos[2] + dz;
-End;
-
-Procedure TRayTunnel.move(x, y, z : Single; abs : Uint8);
+end;
 
-Begin
+procedure TRayTunnel.move(x, y, z: Single; abs: Uint8);
+begin
   pos[0] := x;
   pos[1] := y;
   pos[2] := z;
-End;
+end;
 
 { Relative / absolute move for the lightsource }
-Procedure TRayTunnel.movelight(dx, dy, dz : Single);
-
-Begin
+procedure TRayTunnel.movelight(dx, dy, dz: Single);
+begin
   light[0] := light[0] + dx;
   light[1] := light[1] + dy;
   light[2] := light[2] + dz;
-End;
-
-Procedure TRayTunnel.movelight(x, y, z : Single; abs : Uint8);
+end;
 
-Begin
+procedure TRayTunnel.movelight(x, y, z: Single; abs: Uint8);
+begin
   light[0] := x;
   light[1] := y;
   light[2] := z;
-End;
+end;
 
 { Lock lightsource to the viewer }
-Procedure TRayTunnel.locklight(lock : Boolean);
-
-Begin
+procedure TRayTunnel.locklight(lock: Boolean);
+begin
   lightstatus := lock;
-End;
-
-Var
-  console : TPTCConsole;
-  surface : TPTCSurface;
-  format : TPTCFormat;
-  tunnel : TRayTunnel;
-  posz, phase_x, phase_y : Single;
-  angle_x, angle_y : Integer;
-  buffer : PUint32;
-
-Begin
-  format := Nil;
-  surface := Nil;
-  console := Nil;
-  tunnel := Nil;
-  Try
-    Try
+end;
+
+var
+  console: TPTCConsole = nil;
+  surface: TPTCSurface = nil;
+  format: TPTCFormat = nil;
+  tunnel: TRayTunnel = nil;
+  posz, phase_x, phase_y: Single;
+  angle_x, angle_y: Integer;
+  buffer: PUint32;
+begin
+  try
+    try
       format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
 
       console := TPTCConsole.create;
@@ -575,19 +530,19 @@ Begin
       posz := 80; phase_x := 0; phase_y := 0;
       angle_x := 6; angle_y := 2;
 
-      While Not console.KeyPressed Do
-      Begin
+      while not console.KeyPressed do
+      begin
         buffer := surface.lock;
-	Try
+        try
           tunnel.interpolate;
 
           { Draw to offscreen buffer }
           tunnel.draw(buffer);
-	Finally
+        finally
           surface.unlock;
-	End;
+        end;
 
-        { And copy to screen }
+        { and copy to screen }
         surface.copy(console);
 
         console.update;
@@ -597,16 +552,16 @@ Begin
 
         phase_x := phase_x + 0.2;
         phase_y := phase_y + 0.1;
-      End;
-    Finally
+      end;
+    finally
       console.close;
       console.Free;
       surface.Free;
       tunnel.Free;
       format.Free;
-    End;
-  Except
-    On error : TPTCError Do
+    end;
+  except
+    on error: TPTCError do
       error.report;
-  End;
-End.
+  end;
+end.

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